Submission #1095103

#TimeUsernameProblemLanguageResultExecution timeMemory
1095103BF001Necklace (Subtask 4) (BOI19_necklace4)C++17
15 / 15
271 ms600 KiB
#include<bits/stdc++.h> using namespace std; #define N 6005 #define fi first #define se second typedef pair<int, pair<int, int>> ii; int n, m, pi1[N], pi2[N]; ii res = {0, {0, 0}}; string s, t; ii solve(string s, string t, int ne){ ii rt = {0, {0, 0}}; int si = (int) s.size() - 1; for (int i = 0; i < (int) s.size(); i++){ string s1 = "", s2 = "",t2 = t; for (int j = 0; j <= i; j++) s1 += s[j]; for (int j = i + 1; j < (int) s.size(); j++) s2 += s[j]; s2 = s2 + "#" + t; reverse(t2.begin(), t2.end()); reverse(s1.begin(), s1.end()); s1 = s1 + "#" + t2; for (int j = 1; j < (int) s1.size(); j++){ int pos = pi1[j - 1]; while (pos > 0 && s1[pos] != s1[j]) pos = pi1[pos - 1]; if (s1[pos] == s1[j]) pos++; pi1[j] = pos; } for (int j = 1; j < (int) s2.size(); j++){ int pos = pi2[j - 1]; while (pos > 0 && s2[pos] != s2[j]) pos = pi2[pos - 1]; if (s2[pos] == s2[j]) pos++; pi2[j] = pos; } int n = (int) s1.size(); int m = (int) s2.size(); for (int j = 0; j < (int) t.size(); j++){ int suf = pi2[j + 1 + si - i]; int pre = 0; if (j != (int) t.size() - 1) pre = pi1[i + 1 + (int) t.size() - (j + 1)]; if (pre + suf > rt.fi) rt = {pre + suf, {i - pre + 1, j - suf + 1}}; } } if (ne) { rt.se.se = (int) t.size() - 1 - rt.se.se - rt.fi + 1; } return rt; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> s; cin >> t; res = solve(s, t, 0); reverse(t.begin(), t.end()); res = max(res, solve(s, t, 1)); cout << res.fi << "\n"; cout << res.se.fi << " " << res.se.se; return 0; }

Compilation message (stderr)

necklace.cpp: In function 'ii solve(std::string, std::string, int)':
necklace.cpp:37:13: warning: unused variable 'n' [-Wunused-variable]
   37 |         int n = (int) s1.size();
      |             ^
necklace.cpp:38:13: warning: unused variable 'm' [-Wunused-variable]
   38 |         int m = (int) s2.size();
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...