# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1076699 | vjudge1 | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 199 ms | 568 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |