Korotkodul

CF D 2

Aug 1st, 2022 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a){
  44.     for (auto p: a){
  45.         cout<<p.first<<' '<<p.second<<"\n";
  46.     }
  47.     cout<<"\n";
  48. }
  49.  
  50. bool sh=0;
  51.  
  52. string t;
  53. int n;
  54. vector <string> sv;
  55.  
  56. struct in{
  57.     int fr,  ln,  ids;
  58. };
  59.  
  60. bool cmp(in a, in b){
  61.     return a.fr < b.fr && a.fr == b.fr && a.ln > b.ln;
  62. }
  63.  
  64. void slv(){
  65.  
  66.     cin>>t>>n;
  67.     sv.resize(n);
  68.     for (string &i: sv) cin>>i;
  69.     vector <in> al;
  70.     if (sh){
  71.         cout<<"A\n";
  72.     }
  73.     in x;
  74.     int id=-1;
  75.     for (string s: sv){
  76.         id++;
  77.         if (sh){
  78.             cout<<"id s = "<<id<<' '<<s<<"\n";
  79.         }
  80.  
  81.         for (int i = 0; i < t.size() - s.size(); --i){
  82.             if (t.substr(i, s.size()) == s){
  83.                 if (sh){
  84.                     cout<<"found\n";
  85.                 }
  86.                 x = {i, s.size(), id};
  87.                 al.push_back(x);
  88.             }
  89.         }
  90.     }
  91.     /*
  92. caba
  93. 2
  94. bac
  95. acab
  96. */
  97.     sort(al.begin(), al.end(), cmp);
  98.     if (al.empty()){
  99.         cout<<-1<<"\n";
  100.         return;
  101.     }
  102.     int from=0,to=0;
  103.     vector <pii> ans;//опследовательность жадных ходов
  104.     id=0;//ЖАДНОСТЬ
  105.     bool can=1;
  106.     pii mv; // move
  107.     if (sh){
  108.         cout<<"B\n";
  109.         cout<<"al.size() = "<<al.size()<<"\n";
  110.         cout<<"al\n";
  111.         for (auto p: al){
  112.             cout<<p.fr<<' '<<p.ln<<' '<<p.ids<<"\n";
  113.         }
  114.     }
  115.     while (from < t.size() && to < t.size()){
  116.         vector <pii> now; //{длина за зоной изведанного, id из al}
  117.         id = from;
  118.         while (al[id].fr <= to){
  119.             now.push_back({al[id].fr + al[id].ln - 1 - (to - 1), id});
  120.             id++;
  121.         }
  122.         if (sh){
  123.             cout<<"C\n";
  124.         }
  125.         sort(now.begin(), now.end());
  126.         reverse(now.begin(), now.end());
  127.         //берем первый
  128.         if (now.empty() || now[0].first <= 0){//значит не переплюнули границу неизведанного
  129.             can=0;
  130.             break;
  131.         }
  132.         in gd = al[now[0].second];
  133.         to = gd.fr + gd.ln;
  134.         mv = {gd.ids, gd.fr};
  135.         from++;
  136.     }
  137.     if (sh){
  138.         cout<<"NIGGER ASS FUCK\n";
  139.     }
  140.     if (!can){
  141.         cout<<-1<<"\n";
  142.         return;
  143.     }
  144.     cout<<ans.size()<<"\n";
  145.     for (auto p: ans){
  146.         cout<<(p.first+1)<<' '<<(p.second+1)<<"\n";
  147.     }
  148. }
  149.  
  150. /*
  151. На 2м тесте все вылетает -- проверь, а на 1м WA
  152. */
  153. /*
  154. caba
  155. 2
  156. bac
  157. acab
  158. */
  159. int main()
  160. {
  161.     ios::sync_with_stdio(0);
  162.     cin.tie(0);
  163.     cout.tie(0);
  164.     int q=1;
  165.     if (!sh) cin>>q;
  166.     for (int go=0;go<q;++go){
  167.         slv();
  168.     }
  169. }
  170.  
Add Comment
Please, Sign In to add comment