/*
*
* ^v^
*
*/
#include <iostream>
#include <numeric>
#include <set>
#include <iomanip>
#include <chrono>
#include <queue>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <algorithm>
#include <array>
#include <random>
using namespace std;
using ll = long long int;
using ld = long double;
#define iamtefu ios_base::sync_with_stdio(false); cin.tie(0);
#define fl(i,a,n) for (ll i(a); i<n; i++)
#define rfl(i,a,n) for (ll i(n-1); i>=a; i--)
#define ty int _; for(cin>>_; _--;)
#define print(a) for(auto ele:a){cout<<ele<<" ";}cout<<'\n';
template <class T>
inline bool chmax(T &a, T b){if (a<b){a=b;return 1;}return 0;}
template <class T>
inline bool chmin(T &a, T b){if (a>b){a=b;return 1;}return 0;}
template <typename L, typename R>
ostream& operator<<(ostream &fout, pair<L, R> &p){
fout<<"{"<<p.first<<","<<p.second<<"}";
return fout;
}
template <typename T>
ostream& operator<<(ostream &fout, vector <T> &v){
for (auto &x:v){
fout<<x<<" ";
}
fout<<"\n";
return fout;
}
template <typename T>
ostream& operator<<(ostream &fout, set <T> &st){
for (auto &x:st){
fout<<x<<" ";
}
fout<<"\n";
return fout;
}
template <typename K, typename V>
ostream& operator<<(ostream &fout, map<K, V> &mp){
fout<<"[";
for (auto &[x,y]:mp){
fout<<x<<":"<<y<<" ";
}
fout<<"]\n";
return fout;
}
ll gcd(ll a, ll b){
if (b==0){
return a;
}
return gcd(b, a%b);
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll pw(ll a, ll b, ll m){
ll res=1;
a%=m;
while (b){
if (b&1){
res=(res*a)%m;
}
a=(a*a)%m;
b/=2;
}
return res;
}
void scn(){
string s, t; cin>>s>>t;
auto kmp=[&](string c){
vector <ll> a(c.size());
ll j = 0;
// cerr<<c<<"\n";
fl(i,1,(ll)c.size()){
// cerr<<i<<" "<<j<<" "<<c.size()<<" "<<a.size()<<" pl\n";
while (j>0 && c[i]!=c[j]){
// cerr<<j<<" pl\n";
j=a[j-1];
}
if (c[i]==c[j]){
j++;
}
// cerr<<c[i]<<" "<<c[j]<<" "<<c.size()<<" "<<a.size()<<" pl\n";
a[i]=j;
}
return a;
};
ll n = s.size(), m = t.size();
auto vl=[&](string s, string t, bool r){
vector <ll> ans(3);
fl(i,0,n){
string s1 = s.substr(0, i), s2 = s.substr(i, n-i);
string t1 = t, t2 = t;
reverse(s1.begin(), s1.end());
reverse(t2.begin(), t2.end());
auto v1 = kmp(s1+'$'+t2), v2 = kmp(s2+'$'+t1);
// cerr<<" pl\n";
fl(j,0,m){
chmax(ans, {v1[i+1+m-j-1]+v2[n-i+j], i-v1[i+1+m-j-1], (r ? m-j-v1[i+1+m-j-1] : j-v2[n-i+j])});
}
// cout<<v2.size()<<" "<<i<<" "<<m<<"\n"<<v1<<v2<<'\n';
// cerr<<" pl\n";
}
return ans;
};
auto ans = vl(s, t, 0);
reverse(t.begin(), t.end());
chmax(ans, vl(s, t, 1));
cout<<ans[0]<<"\n"<<ans[1]<<" "<<ans[2]<<"\n";
// not necessarily distinct
// right down
}
int main(){
iamtefu;
#if defined(airths)
auto t1=chrono::high_resolution_clock::now();
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// ty
{
scn();
}
#if defined(airths)
auto t2=chrono::high_resolution_clock::now();
ld ti=chrono::duration_cast<chrono::nanoseconds>(t2-t1).count();
ti*=1e-6;
cerr<<"Time: "<<setprecision(12)<<ti;
cerr<<"ms\n";
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
439 ms |
480 KB |
Output is correct |
2 |
Correct |
405 ms |
480 KB |
Output is correct |
3 |
Correct |
420 ms |
488 KB |
Output is correct |
4 |
Correct |
343 ms |
480 KB |
Output is correct |
5 |
Correct |
362 ms |
492 KB |
Output is correct |
6 |
Correct |
419 ms |
492 KB |
Output is correct |
7 |
Correct |
410 ms |
488 KB |
Output is correct |
8 |
Correct |
397 ms |
492 KB |
Output is correct |
9 |
Correct |
400 ms |
488 KB |
Output is correct |