# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
974999 | Mighilon | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 200 ms | 848 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "../Library/debug.h"
#else
#define dbg(x...)
// #define cin fin
// #define cout fout
// const string FILE_NAME = ""; ifstream fin(FILE_NAME + ".in"); ofstream fout(FILE_NAME + ".out");
#endif
typedef long long ll;
// typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
// typedef vector<pl> vpl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; --i)
#define trav(a, x) for (auto& a : x)
#define f first
#define s second
#define pb push_back
// #define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int mxN = 1e7;
int p1[6001], p2[6001];
void fill_p(string s, int *p){
for(int i = 1, j = 0; i < (int)s.size(); ++i){
while(j > 0 && s[i] != s[j])
j = p[j - 1];
if(s[i] == s[j]) j++;
p[i] = j;
}
}
tuple<int, int, int> solve(string s, string t, bool rev){
int n = s.size(), m = t.size();
tuple<int, int, int> ans = {0, 0, 0};
F0R(i, n){
string s1 = s.substr(0, i), s2 = s.substr(i, n - i);
reverse(all(s1));
string t1 = t, t2 = t;
reverse(all(t2));
fill_p(s1 + "#" + t1, p1), fill_p(s2 + "#" + t2, p2);
FOR(j, 1, m + 1){
ans = max(ans, {p1[i + j] + p2[n + m - i - j], i - p1[i + j],
rev ? m - j - p2[n + m - i -j] : j - p1[i + j]});
}
}
return ans;
}
void solve(){
string s, t;
cin >> s >> t;
tuple<int, int, int> ans = solve(s, t, false);
reverse(all(t));
ans = max(ans, solve(s, t, true));
cout << get<0>(ans) << nl << get<1>(ans) << " " << get<2>(ans);
}
int32_t main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int TC = 1;
/* cin >> TC; */
while(TC--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |