Submission #1076699

#TimeUsernameProblemLanguageResultExecution timeMemory
1076699vjudge1Necklace (Subtask 4) (BOI19_necklace4)C++17
15 / 15
199 ms568 KiB
#include <bits/stdc++.h> #define all(s) s.begin(), s.end() #define lb(s, a) lower_bound(all(s), (a)) - s.begin() using namespace std; typedef long long ll; const int ar = 2e5+2; const ll mod = 1e9+7; const int oo = 1e9; vector<int> KMP(string s) { int n = (int)s.length(); vector<int> pi(n); for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "wefwe" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } string s, t; cin >> s >> t; int n = s.size(), m = t.size(); int res = 0, l = 0, r = 0; for(int type = 0; type < 2; ++type) { reverse(all(s)); for(int i = 0; i < n; ++i) { string s1 = s.substr(0, i + 1), s2 = s.substr(i + 1, n - i - 1); reverse(all(s1)); string tn = t; reverse(all(tn)); vector <int> kmp1 = KMP(s1 + "/" + tn), kmp2 = KMP(s2 + "/" + t); for(int j = 0; j < m; ++j) { if(res < kmp1[i + m - j] + kmp2[j + n - i]) { res = kmp1[i + m - j] + kmp2[j + n - i]; if(type == 0) l = n - i - 1 - kmp2[j + n - i]; else l = i + 1 - kmp1[i + m - j]; r = j - kmp2[j + n - i] + 1; } } } } cout << res << '\n' << l << ' ' << r; }

Compilation message (stderr)

necklace.cpp: In function 'int main()':
necklace.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
necklace.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...