Advertisement
vlatkovski

Tjuring za 6/20 (TLE)

Apr 6th, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool comp1(const string &a, const string &b) {
  5.     return a.length() < b.length();
  6. }
  7.  
  8. int main() {
  9. //    std::ios::sync_with_stdio(false);
  10. //    freopen("in.txt", "r", stdin);
  11. //    freopen("out.txt", "w", stdout);
  12.     int n;
  13.     cin >> n;
  14.     vector<string> v(n);
  15.     for (int i = 0; i < n; ++i) {
  16.         cin >> v[i];
  17.     }
  18.     sort(v.begin(), v.end(), comp1);
  19.  
  20.     bool done = 0;
  21.     int len;
  22.     for (len = v[0].length(); len > 0; --len) {
  23.         bool itendHasBeenEndOnce = 0;
  24.         for (auto itstart = v[0].begin(), itend = v[0].begin()+len;
  25.                   !itendHasBeenEndOnce;
  26.                   ++itstart, ++itend) {
  27. //            cout << "*its=" << *itstart << " *ite=" << *itend << endl;
  28.             if (itend == v[0].end()) itendHasBeenEndOnce = 1;
  29.             bool found = 1;
  30.             for (int i = 1; i < n; ++i) {
  31.                 auto result = search(v[i].begin(), v[i].end(), itstart, itend);
  32.                 if (result == v[i].end()) {
  33.                     found = 0;
  34.                     break;
  35.                 }
  36.             }
  37.             if (found) {
  38.                 done = 1;
  39. //                cout << "found in all: ";
  40. //                for (auto itz = itstart; itz != itend; ++itz) cout << *itz;
  41. //                cout << '\n';
  42.                 break;
  43.             }
  44.         }
  45.         if (done) break;
  46.     }
  47.  
  48.     cout << len;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement