# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1076699 | 2024-08-26T15:40:13 Z | vjudge1 | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 199 ms | 568 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 194 ms | 348 KB | Output is correct |
2 | Correct | 140 ms | 556 KB | Output is correct |
3 | Correct | 199 ms | 348 KB | Output is correct |
4 | Correct | 159 ms | 568 KB | Output is correct |
5 | Correct | 126 ms | 568 KB | Output is correct |
6 | Correct | 124 ms | 348 KB | Output is correct |
7 | Correct | 151 ms | 568 KB | Output is correct |
8 | Correct | 164 ms | 348 KB | Output is correct |
9 | Correct | 181 ms | 564 KB | Output is correct |