Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1.  
  2. Begin: 2018-10-26 22:05 BST
  3. Contest on Z algorithm
  4. End: 2018-11-02 22:05 BST
  5. 168:00:00
  6. Ended
  7. Overview
  8. Problem
  9. Status
  10. Rank (168:00:00)
  11. 0 Comments
  12. Previous12345…Next
  13. Username
  14. Prob
  15.     Result
  16.     Time
  17. (ms)    Mem
  18. (MB)    Lang
  19.     Submit Time
  20. Sanjoy_Kumar
  21. B
  22. Accepted
  23. 2980       
  24. C++
  25. 5 months ago
  26.            
  27. All Copyright Reserved ©2018 Xu Han
  28. Server Time: 2019-03-27 09:27:02 BST
  29.  
  30. #16750879 | Sanjoy_Kumar's solution for [UVA-10679] [Problem B]
  31. Status
  32. Accepted
  33. Time
  34. 2980ms
  35. Length
  36. 1256
  37. Lang
  38. C++11 5.3.0
  39. Submitted
  40. 2018-10-31 02:07:19
  41. RemoteRunId
  42. 22220819
  43. Select Code
  44. #include <bits/stdc++.h>
  45. #define fastio ios_base::sync_with_stdio(false);
  46.  
  47. using namespace std;
  48.  
  49. const int maxn = 2e6 + 10;
  50.  
  51. int main()
  52. {
  53.     fastio;
  54. //    freopen("input.txt", "r", stdin);
  55.  
  56.     int test, q;
  57.     cin >> test;
  58.  
  59.     while( test-- ){
  60.  
  61.         string line, in;
  62.         cin >> line >> q;
  63.  
  64.         while( q-- ){
  65.  
  66.             cin >> in;
  67.             int len = in.length();
  68.             in = in + "#" + line;
  69.             int sz = in.length();
  70.  
  71.             int lft, rgt, indx, maxLen = -1;
  72.             int z[sz + 10] = {0};
  73.             bool flag = true;
  74.             lft = rgt = -1;
  75.  
  76.             for( int i = 1; i < sz; i++ ){
  77.                 if( i <= rgt )
  78.                     z[i] = min( rgt - i + 1, z[i - lft]);
  79.                 while( (i + z[i] < sz) && (in[i + z[i]] == in[z[i]]) )
  80.                     z[i]++;
  81.                 if( (i + z[i] - 1) > rgt ){
  82.                     lft = i;
  83.                     rgt = i + z[i] - 1;
  84.                     if( z[i] == len ){
  85.                         flag = false;
  86.                         cout << "y" << endl;
  87.                         break;
  88.                     }
  89.                 }
  90.             }
  91.             if( flag ) cout << "n" << endl;
  92.             in = "";
  93.         }
  94.  
  95.         line = "";
  96.     }
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement