# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
525114 | LeticiaFCS | Necklace (Subtask 4) (BOI19_necklace4) | C++17 | 289 ms | 388 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"
#define st first
#define nd second
using lint = int64_t;
constexpr int MOD = int(1e9) + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr int NINF = 0xcfcfcfcf;
constexpr lint LINF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;
vector<int> kmp(const string &s){
int n = int(s.size());
vector<int> pi(n);
for(int i=1; i<n; i++){
pi[i] = pi[i-1];
while(pi[i] && s[i] != s[ pi[i] ])
pi[i] = pi[ pi[i]-1 ];
if( s[i] == s[ pi[i] ])
pi[i]++;
}
return pi;
}
int ans = 0, ans1=0, ans2=0;
void solve(const string &s, const string & t, bool rev = false){
int n = int(s.size());
int m = int(t.size());
string tr = t;
reverse(begin(tr), end(tr));
for(int p=0;p<=n; p++){
string a = s.substr(0, p);
string b = s.substr(p, n);
//cout<<a<<" "<<b<<"\n";
reverse(begin(a), end(a));
auto pi1 = kmp(a+"#"+tr);
auto pi2 = kmp(b+"#"+t);
for(int j=p+1; j+1<p+1+m; j++){
int j2 = j - (p+1);
int k = m-1-(j2+1);
k += int(b.size()+1);
int cur = pi1[j] + pi2[k];
if(cur > ans){
ans = cur;
ans1 = p;
ans2 = j2;
if(rev) ans2 = (m-1-ans2) - cur;
}
//cout<<pi1[j] + pi2[k]<<" "<<j2<<" "<<k<<"\n";
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
//int __; cin >> __; for( int _ = 1 ; _ <= __ ; _++ ){ }
string s, t;
cin>>s>>t;
solve(s, t);
reverse(t.begin(), t.end());
solve(s, t, true);
cout<<ans<<"\n"<<ans1<<" "<<ans2<<"\n";
return 0;
}
/*
[ ]Leu o problema certo???
[ ]Ver se precisa de long long
[ ]Viu o limite dos fors (é n? é m?)
[ ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[ ]Testar sample
[ ]Testar casos de borda
[ ]1LL no 1LL << i
[ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |