Korotkodul

CF D 3

Aug 1st, 2022 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 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. abacabaca
  93. 3
  94. aba
  95. bac
  96. aca
  97.  
  98.  
  99. */
  100.  
  101.     sort(al.begin(), al.end(), cmp);
  102.     if (al.empty()){
  103.         cout<<-1<<"\n";
  104.         return;
  105.     }
  106.     int from=0,to=0;
  107.     vector <pii> ans;//опследовательность жадных ходов
  108.     id=0;//ЖАДНОСТЬ
  109.     bool can=1;
  110.     pii mv; // move
  111.     if (sh){
  112.         cout<<"B\n";
  113.         cout<<"al.size() = "<<al.size()<<"\n";
  114.         cout<<"al\n";
  115.         for (auto p: al){
  116.             cout<<p.fr<<' '<<p.ln<<' '<<p.ids<<"\n";
  117.         }
  118.     }
  119.  
  120.     while (from < t.size() && to < t.size()){
  121.         vector <pii> now; //{длина за зоной изведанного, id из al}
  122.         //id = from;
  123.         if (sh){
  124.             cout<<"from  to = "<<from<<' '<<to<<"\n";
  125.         }
  126.         while (id < al.size() && al[id].fr <= to){
  127.             now.push_back({al[id].fr + al[id].ln - 1 - (to - 1), id});
  128.  
  129.             if (sh){
  130.                     cout<<"id = "<<id<<"\n";
  131.             }
  132.             id++;
  133.         }
  134.  
  135.  
  136.         sort(now.begin(), now.end());
  137.         reverse(now.begin(), now.end());
  138.  
  139.         if (sh){
  140.             //cout<<"C\n";
  141.  
  142.             cout<<"now\n";
  143.             cvp(now);
  144.             if (sh){
  145.                 cout<<"ans\n";
  146.                 cvp(ans);
  147.             }
  148.         }
  149.         //берем первый
  150.         if (now.empty() || now[0].first <= 0){//значит не переплюнули границу неизведанного
  151.             can=0;
  152.             break;
  153.         }
  154.         in gd = al[now[0].second];
  155.         to = gd.fr + gd.ln;
  156.         mv = {gd.ids, gd.fr};
  157.         ans.push_back(mv);
  158.         from++;
  159.     }
  160.     if (sh){
  161.         cout<<"id = "<<id<<"\n";
  162.         cout<<"NIGGER ASS FUCK\n";
  163.     }
  164.     if (!can){
  165.         cout<<-1<<"\n";
  166.         return;
  167.     }
  168.     cout<<ans.size()<<"\n";
  169.     for (auto p: ans){
  170.         cout<<(p.first+1)<<' '<<(p.second+1)<<"\n";
  171.     }
  172. }
  173.  
  174. /*
  175. На 2м тесте все вылетает -- проверь, а на 1м WA
  176. */
  177. /*
  178. abacabaca
  179. 3
  180. aba
  181. bac
  182. aca
  183.  
  184. */
  185. int main()
  186. {
  187.     ios::sync_with_stdio(0);
  188.     cin.tie(0);
  189.     cout.tie(0);
  190.     int q=1;
  191.     if (!sh) cin>>q;
  192.     for (int go=0;go<q;++go){
  193.         slv();
  194.     }
  195. }
  196.  
Add Comment
Please, Sign In to add comment