QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669093 | #9514. 研心 | ANIG | 100 ✓ | 2188ms | 413412kb | C++23 | 9.2kb | 2024-10-23 17:15:07 | 2024-10-23 17:15:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
const int N=4e5+5,T=80;
namespace tt{
struct node{
int lson,rson,laz;
}p[N*100];
int idx;
void add(int x,int l,int r,int sm,int nl,int nr){
if(l<=nl&&r>=nr){
p[x].laz+=sm;
return;
}
int mid=nl+nr>>1;
if(l<=mid){
if(!p[x].lson)p[x].lson=++idx;
add(p[x].lson,l,r,sm,nl,mid);
}
if(r>mid){
if(!p[x].rson)p[x].rson=++idx;
add(p[x].rson,l,r,sm,mid+1,nr);
}
}
void gets(int x,int d,int&res,int nl,int nr){
if(!x)return;
res+=p[x].laz;
if(nl==nr)return;
int mid=nl+nr>>1;
if(d<=mid)gets(p[x].lson,d,res,nl,mid);
else gets(p[x].rson,d,res,mid+1,nr);
}
}
struct tr{
struct node{
int l,r,rt;
}p[N<<1];
int lth;
void reset(int x,int l,int r){
p[x].l=l,p[x].r=r;p[x].rt=++tt::idx;
if(l==r)return;
int mid=l+r>>1;
reset(x<<1,l,mid);
reset(x<<1|1,mid+1,r);
}
void add(int x,int d,int l,int r,int sm){
if(l>r)return;
tt::add(p[x].rt,l,r,sm,1,lth);
if(p[x].l==p[x].r)return;
if(d<=(p[x].l+p[x].r>>1))add(x<<1,d,l,r,sm);
else add(x<<1|1,d,l,r,sm);
}
void gets(int x,int l,int r,int d,int&res){
if(l>r)return;
if(l<=p[x].l&&r>=p[x].r){
tt::gets(p[x].rt,d,res,1,lth);
return;
}
int mid=p[x].l+p[x].r>>1;
if(l<=mid)gets(x<<1,l,r,d,res);
if(r>mid)gets(x<<1|1,l,r,d,res);
}
}t1,t2;
long long res;
int n,m,l1[N],l2[N],zd1[N],zd2[N],bh[N<<1],db[2][N],idx1,idx2,idx,f[N<<1],st[N<<1][22];
vector<int>q1[N],q2[N],mk1[N],mk2[N],p[2][N],tmp[2][N],w1[N],w2[N];
vector<ull>qh1[N],qh2[N],hh1[N],hh2[N];
ull pw[N];
ull h1(vector<ull>&h,int l,int r){
return h[r]-h[l-1]*pw[r-l+1];
}
ull h2(vector<ull>&h,int l,int r){
return h[l]-h[r+1]*pw[r-l+1];
}
int glh(vector<ull>&qh,vector<ull>&hh,int n){
int res=0;
for(int i=1;i<=n;i++){
int l=1,r=min(i,n-i+1);
while(l<r){
int mid=l+r+1>>1;
if(h1(qh,i-mid+1,i+mid-1)==h2(hh,i-mid+1,i+mid-1))l=mid;
else r=mid-1;
}
res=max(res,2*l-1);
}
return res;
}
struct msg{
int op,bh,x;
}g[N<<1];
vector<msg>jl[N<<1];
int gets(msg x){
if(!x.bh)return -1;
if(x.op)return q2[x.bh][x.x];
return q1[x.bh][x.x];
}
bool cmp(msg a,msg b){
return gets(a)<gets(b);
}
ull h(msg x,int k){
if(x.op)return h1(qh2[x.bh],x.x-k+1,x.x);
return h1(qh1[x.bh],x.x-k+1,x.x);
}
struct node{
int l1,r1,l2,r2,sm;
};
vector<node>q;
struct nodes{
int l,r,sm;
friend bool operator<(nodes a,nodes b){
return a.sm<b.sm;
}
};
vector<nodes>f1[N],f2[N];
void add(int op,int l,int r,int x,int sm){
if(l>r)return;
if(op)f2[x].push_back({l,r,sm});
else f1[x].push_back({l,r,sm});
}
struct qj{
int l,r,sm;
friend bool operator<(qj a,qj b){
return a.r<b.r;
}
};
struct xg{
int op,x,l,r,sm;
friend bool operator<(xg a,xg b){
return a.sm>b.sm;
}
};
vector<xg>jj;
void split(set<qj>&q,int x){
auto w=q.lower_bound({x,x});
if(x==(*w).l)return;
auto t=*w;
q.erase(w);
q.insert({t.l,x-1,t.sm});
q.insert({x,t.r,t.sm});
}
void upt(vector<nodes>&g,int n){
set<qj>q;
sort(g.begin(),g.end());
q.insert({1,n,0});
for(auto c:g){
split(q,c.l);if(c.r<n)split(q,c.r+1);
while(1){
auto w=q.lower_bound({c.l,c.l});
if(w==q.end()||(*w).r>c.r)break;
q.erase(w);
}
q.insert({c.l,c.r,c.sm});
}
g.clear();
for(auto c:q)g.push_back({c.l,c.r,c.sm});
}
void SA(){
for(int i=1;i<=n;i++){
for(int j=1;j<=l1[i];j++)g[++idx]={0,i,j};
p[0][i].resize(q1[i].size());
tmp[0][i].resize(q1[i].size());
}
for(int i=1;i<=m;i++){
for(int j=1;j<=l2[i];j++)g[++idx]={1,i,j};
p[1][i].resize(q2[i].size());
tmp[1][i].resize(q2[i].size());
}
sort(g+1,g+idx+1,cmp);
int cnt=0;
for(int i=1;i<=idx;i++){
if(gets(g[i])!=gets(g[i-1]))cnt++;
p[g[i].op][g[i].bh][g[i].x]=cnt;
}
for(int i=1;i<=20;i++){
for(int j=1;j<=idx;j++){
if(g[j].x-(1<<i-1)>0)jl[p[g[j].op][g[j].bh][g[j].x-(1<<i-1)]].push_back(g[j]);
else jl[0].push_back(g[j]);
}
idx=0;
for(int j=0;j<=cnt;j++){
for(auto c:jl[j])g[++idx]=c;
jl[j].clear();
}
for(int j=1;j<=idx;j++)jl[p[g[j].op][g[j].bh][g[j].x]].push_back(g[j]);
idx=0;
for(int j=0;j<=cnt;j++){
for(auto c:jl[j])g[++idx]=c;
jl[j].clear();
}
cnt=0;
auto g1=[&](msg x){
return p[x.op][x.bh][x.x];
};
auto g2=[&](msg x){
if(x.x-(1<<i-1)<=0)return 0;
return p[x.op][x.bh][x.x-(1<<i-1)];
};
for(int j=1;j<=idx;j++){
if(j==1||g1(g[j])!=g1(g[j-1])||g2(g[j])!=g2(g[j-1]))cnt++;
tmp[g[j].op][g[j].bh][g[j].x]=cnt;
}
for(int j=1;j<=n;j++)swap(tmp[0][j],p[0][j]);
for(int j=1;j<=m;j++)swap(tmp[1][j],p[1][j]);
}
for(int i=1;i<=idx;i++)p[g[i].op][g[i].bh][g[i].x]=i;
for(int i=1;i<idx;i++){
int l=0,r=min(g[i].x,g[i+1].x);
while(l<r){
int mid=l+r+1>>1;
if(h(g[i],mid)==h(g[i+1],mid))l=mid;
else r=mid-1;
}
f[i]=l;
st[i][0]=f[i];
}
for(int i=1;i<=20;i++){
for(int j=1;j<=idx-(1<<i);j++){
st[j][i]=min(st[j][i-1],st[j+(1<<i-1)][i-1]);
}
}
for(int i=1;i<=idx;i++){
if(g[i].op){
if(g[i].x==l2[g[i].bh])bh[i]=++idx2,db[1][g[i].bh]=idx2;
}else{
if(g[i].x==l1[g[i].bh])bh[i]=++idx1,db[0][g[i].bh]=idx1;
}
}
int nw1=0,nw2=0;
auto ADD=[&](int i){
if(bh[i]){
if(g[i].op)nw2=bh[i];
else nw1=bh[i];
}
};
q.push_back({1,0,1,0,-1});
ADD(1);
for(int i=2;i<=idx;i++){
while(q.size()&&q.back().sm>=f[i-1])q.pop_back();
q.push_back({q.back().r1+1,nw1,q.back().r2+1,nw2,f[i-1]});
if(g[i].op){
if(g[i].x<l2[g[i].bh])
if(mk2[g[i].bh][g[i].x+1]){
for(auto c:q){
if(c.sm>T)break;
add(1,c.l1,c.r1,db[1][g[i].bh],l2[g[i].bh]-g[i].x+2*c.sm);
}
}
}else{
if(g[i].x<l1[g[i].bh])
if(mk1[g[i].bh][g[i].x+1]){
for(auto c:q){
if(c.sm>T)break;
add(0,c.l2,c.r2,db[0][g[i].bh],l1[g[i].bh]-g[i].x+2*c.sm);
}
}
}
ADD(i);
}
nw1=n+1,nw2=m+1;
q.clear();
q.push_back({n+1,n,m+1,m,-1});
ADD(idx);
for(int i=idx-1;i>=1;i--){
while(q.size()&&q.back().sm>=f[i])q.pop_back();
q.push_back({nw1,q.back().l1-1,nw2,q.back().l2-1,f[i]});
if(g[i].op){
if(g[i].x<l2[g[i].bh])
if(mk2[g[i].bh][g[i].x+1]){
for(auto c:q){
if(c.sm>T)break;
add(1,c.l1,c.r1,db[1][g[i].bh],l2[g[i].bh]-g[i].x+2*c.sm);
}
}
}else{
if(g[i].x<l1[g[i].bh])
if(mk1[g[i].bh][g[i].x+1]){
for(auto c:q){
if(c.sm>T)break;
add(0,c.l2,c.r2,db[0][g[i].bh],l1[g[i].bh]-g[i].x+2*c.sm);
}
}
}
ADD(i);
}
for(int i=1;i<=n;i++)add(0,1,m,db[0][i],zd1[i]);
for(int i=1;i<=m;i++)add(1,1,n,db[1][i],zd2[i]);
for(int i=1;i<=n;i++)upt(f1[i],m);
for(int i=1;i<=m;i++)upt(f2[i],n);
for(int i=1;i<=n;i++)for(auto c:f1[i])jj.push_back({0,i,c.l,c.r,c.sm});
for(int i=1;i<=m;i++)for(auto c:f2[i])jj.push_back({1,i,c.l,c.r,c.sm});
sort(jj.begin(),jj.end());
t1.lth=n;t2.lth=m;
t1.reset(1,1,m);t2.reset(1,1,n);
for(auto c:jj){
if(c.op){
int sm=0;
t2.gets(1,c.l,c.r,c.x,sm);
res+=1ll*(c.r-c.l+1-sm)*c.sm;
t1.add(1,c.x,c.l,c.r,1);
}else{
int sm=0;
t1.gets(1,c.l,c.r,c.x,sm);
res+=1ll*(c.r-c.l+1-sm)*c.sm;
t2.add(1,c.x,c.l,c.r,1);
}
}
}
int gets(int l,int r){
int k=__lg(r-l+1);
return min(st[l][k],st[r-(1<<k)+1][k]);
}
int gets(int a,int b,int k1,int k2){
if(!k1||!k2)return 0;
int l=p[0][a][k1],r=p[1][b][k2];
if(l>r)swap(l,r);
return gets(l,r-1);
}
int solve(int a,int b){
int res=max(zd1[a],zd2[b]),ans=max(zd1[a],zd2[b]);
for(auto i:w1[a]){
int tmp=gets(a,b,i-1,l2[b]);
res=max(res,l1[a]-i+1+tmp*2);
if(tmp<=T)ans=max(ans,l1[a]-i+1+tmp*2);
}
for(auto i:w2[b]){
int tmp=gets(a,b,l1[a],i-1);
res=max(res,l2[b]-i+1+tmp*2);
if(tmp<=T)ans=max(ans,l2[b]-i+1+tmp*2);
}
return res-ans;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;
pw[0]=1;
for(int i=1;i<N;i++)pw[i]=pw[i-1]*131;
for(int i=1;i<=n;i++){
string s;
cin>>s;
l1[i]=s.size();
q1[i].push_back(0);
for(auto c:s)q1[i].push_back(c-'a');
qh1[i].resize(q1[i].size());
hh1[i].resize(q1[i].size());
mk1[i].resize(q1[i].size());
for(int j=1;j<=l1[i];j++)qh1[i][j]=qh1[i][j-1]*131+q1[i][j]+1;
for(int j=l1[i];j>=1;j--)hh1[i][j]=hh1[i][j+1]*131+q1[i][j]+1;
for(int j=1;j<=l1[i];j++)if(l1[i]-j+1&1)mk1[i][j]=h1(qh1[i],j,l1[i])==h2(hh1[i],j,l1[i]);
zd1[i]=glh(qh1[i],hh1[i],l1[i]);
for(int j=1;j<=l1[i];j++)if(mk1[i][j])w1[i].push_back(j);
}
for(int i=1;i<=m;i++){
string s;
cin>>s;
l2[i]=s.size();
q2[i].push_back(0);
for(auto c:s)q2[i].push_back(c-'a');
reverse(q2[i].begin()+1,q2[i].end());
qh2[i].resize(q2[i].size());
hh2[i].resize(q2[i].size());
mk2[i].resize(q2[i].size());
for(int j=1;j<=l2[i];j++)qh2[i][j]=qh2[i][j-1]*131+q2[i][j]+1;
for(int j=l2[i];j>=1;j--)hh2[i][j]=hh2[i][j+1]*131+q2[i][j]+1;
for(int j=1;j<=l2[i];j++)if(l2[i]-j+1&1)mk2[i][j]=h1(qh2[i],j,l2[i])==h2(hh2[i],j,l2[i]);
zd2[i]=glh(qh2[i],hh2[i],l2[i]);
for(int j=1;j<=l2[i];j++)if(mk2[i][j])w2[i].push_back(j);
}
SA();
for(int i=1;i<=n;i++)if(l1[i]>T)for(int j=1;j<=m;j++)if(l2[j]>T)res+=solve(i,j);
cout<<(res+1ll*n*m)/2;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 10ms
memory: 31840kb
input:
10 100 aabaababaaaababbabaaaababaababbbaabbbaabaabaabbbaababaaababbaababababbbaababbbbbbbbaabbbbaabbbbbbbbaabaabbbaabbbbbabbbbbaabbbaabaa bbaaabaabbbbaaabaaaaabbbbbabaabbabbaabbaabbaabbabbababaabaabbaabbbbbbaaaabbbbabaaaabaaabbbabaaaaaabbaaaabbbabbbbbaaaabbabaababbaabbaaabbbbbbaaaabbbababaabbaaaba b...
output:
10468
result:
ok single line: '10468'
Test #2:
score: 20
Accepted
time: 12ms
memory: 31780kb
input:
10 100 abbacbbaabababcaabbaabbbabcaccabcabbabbbccaacabaabacccbacaaabbaaabbbaacaabbabcabbbcbacaaaaabaaaabaaacbbccbacacbbaaccacbabcbccacbaaacaaacccbabbaccacaaacaabbbccaaccbbabaabcbbcbcbb bccabcacbacccbcababaccccaaabbccacaccccabbaabbcacabaccabacbbbaaaabaabccbcaacaaccbcacabcbbbcccccabccbaababccccabcabab...
output:
6384
result:
ok single line: '6384'
Test #3:
score: 20
Accepted
time: 17ms
memory: 33892kb
input:
50 50 aaaaabbabbbbbaababbaaaababaababababbbbaabaaaaaaaabaabbaaabaaaabaaabaabbbabbbababbbbabbbabbaaababbabaabbabbabbabbaaababaaaaabbbbbbaabaabaabbbbbabaaababb abbabbbaabaaaaabababaabbabaabbbbab bababbbbaabaabbaabbbbaabaabbbaabbbbaaabbabbbaaabbbbaaabaabbaaaaaabbbabaaaaabbaabaabaaabaaababbbbbaaabbbbbba...
output:
21362
result:
ok single line: '21362'
Test #4:
score: 20
Accepted
time: 9ms
memory: 33824kb
input:
50 50 aababcabbbcbaacaaaaccababbacbbaaabcbaaccabbababbcccaacaaaacacbcbaaabaacabbbbbbaccaaacbbacaacacbcccbbacabbcbcbacababcbbacaccaacacbcccbababaccabccccbabaccababccccbcbabcabcabccaaccababcbccacbbaaaacc cbaccababccbaaacbccabbcccacacacaaaabaaababcacabaccbccacbcbaaaaabbacbbaccabba ccbcbcacbcaccabbbccaa...
output:
13421
result:
ok single line: '13421'
Test #5:
score: 20
Accepted
time: 23ms
memory: 38580kb
input:
1000 1000 a aabbab bbbbababbbba bb baaaaa ba a baa a bbaaaabaaaba ba a a a bbababbbbbb b aaabb bbbbbaabbabab bbaaa aaaa aa aaaaaababb a bbaba baaa aabbab babaab b aab bbbabb aaaabbbbbaaaaaa bbbbbbbaabab bb ab aaa aaababb babaaaabab aa aaabaaababa abbabaaaaabb bbaa abaabb baa abba aaaa abbbb aab b aa...
output:
3159935
result:
ok single line: '3159935'
Subtask #2:
score: 30
Accepted
Test #6:
score: 30
Accepted
time: 1118ms
memory: 294300kb
input:
1 10000 bcacacbcdadbcbccbdddaaddabcaccccbaabbcdcdaabdacccadacbbbabdaaacadacdccadcbdadadcaaabdbdbdcdcccbacbdbccacbdadcaaaacbabdadcacdcacadcadaabdaaabccccdcbcdbcadcaabbbaacaadaccdaccadbddcdbccbcddcaadcaadaadbbaadbcdbddbcbadbccbaddaacabcdccbadaddcadcbababccabcaadbcbdbcbbcdcbdbcdbdaaddbacddcabbbdccbddba...
output:
1160913325
result:
ok single line: '1160913325'
Test #7:
score: 30
Accepted
time: 1139ms
memory: 280280kb
input:
1 1000 caaadbacdaaccbdcaccbdbddcdaccaaaaaccdccaadbadbcdccaacdadcccaddadcbacbbdcaadbbcdaddcadddccdbabccdadcaacabcabbbdbbbbdbbaaccddcdddcddddddbdbbadbddcbacdcdbdabcbbdbbaaadbdacaccdbaaabacbacabdaccaabaadddccbabacdbdddbdcadadcdccabaabbccbacddddcbcdbabaadaddbbdabadaccbdbaaabdadadaadabbdbadacacbdcbcbdccc...
output:
134272327
result:
ok single line: '134272327'
Test #8:
score: 30
Accepted
time: 1117ms
memory: 301328kb
input:
1 10000 bbcbcaacaaaacacbacacbaacbacbaababaacacbacbacbccaacbbacbbccababcaaaccabaaccbbbaaaabbababaacbbccabcaccaaccbacccaacabcaacacaccababbbbbcbacaaabbcbaccacaaaaabbacbbcbbcabccaabcabcabaabbbabbababbabcacbcaccabacaababbacccabbcaaacacccbcbcccbbbbaababbabcaaabaccccbbbabccabacbcbabccccaccbcccccbcccccccbbc...
output:
1375114968
result:
ok single line: '1375114968'
Test #9:
score: 30
Accepted
time: 1150ms
memory: 303064kb
input:
1 10000 cbaacaaaaccacaacbbcacabccbbabbababbababbacbababbcabcbacabbaaaacccacbbaaacacbacccbababaabccbbcabbbcaacbcbbbcbcbccccbabcacccccaabbbccacccacabccbcccbaaaccbbbacbaabbcbaabccccaabacabccaaccbbbaccbbcbcaabcaacbcbbcacbcbcabbacbababcbcabcbaabbbbbcccccbcacbabbcccccaacccbaccbaacbccbcababbabcbbccbbbbacab...
output:
1363955024
result:
ok single line: '1363955024'
Test #10:
score: 30
Accepted
time: 1091ms
memory: 301260kb
input:
1 10000 aacbabccacabcccbccbbcacbbcbcacbbcacbbcbcacacbaaabbbbccaabcbbccccaccccbbcbbcacbbcbbcacbbcbcacacbaaabbbbccaabcbbccccaccccbbcbcbbccccaccccbbbccccaccccbbcbcbbccccaccccbbcbaaccbbbbaaaaabbbbccaabcbbccccaccccbbcbcbbccccaccccbbbccccaccccbbcbcbbccccaccccbbcbaaccbbbbaaabcacacbcbbcacbbcacacbaaabbbbccaa...
output:
1951994915
result:
ok single line: '1951994915'
Test #11:
score: 30
Accepted
time: 1073ms
memory: 300824kb
input:
1 10000 bbaabbaaaabbbaaabbbaabaabaababbbbbabaabbababaaabbbbbbabbaaaabbbbbbaabababbbbabbaababbbbabaabaabaaabbabababbbbbaabababbaabbabbbababbbabaaaaabaaaaaaabaabaaabababbbabbabbaaaabababbbbabaabbaaababbaabbbbabbabbabbabbabaababaaaabbbaabbaababbabbbbaaaaaaaaaababbbbabbbabbaabbbbaaabaabbbbbaabbaababbaba...
output:
424739578
result:
ok single line: '424739578'
Subtask #3:
score: 20
Accepted
Test #12:
score: 20
Accepted
time: 1176ms
memory: 243592kb
input:
100 1000 abbabbbbabbbbabaabaabbbbabaaabbbaabaabbabaabaabbaabbaabbababbabbababbbaabaabbaabbbabaabbbaaaabaaaabaababbaaaaaaaaabaabbaababbbbbbabbbabbbbababbbaaaaaabaaaabaaabbabbaaaaabbbabbabaabbabababbaaababbbaaaabbabbbabbabbabbbbbbabaabaabbbaabaaabbaabbabbbbaabbabaaabaabaabbbabbbbbabaababbbabababaabbba...
output:
1289287
result:
ok single line: '1289287'
Test #13:
score: 20
Accepted
time: 1184ms
memory: 247692kb
input:
1000 1000 babbbabaabaaaabbbbbababaaabbaabbbbbabbaababbbbaaabbbbaaabbbababbaaaabaaabbbbbbbbaabbabbbabbabbaaabaabbbbbbbababaabbbbabaaabbaaaaabbbaababbaaaaabbbbaaaabbbaabaaababaaabbabbbabbabbbabbaabbabbbabaaaaaabaabbabbababbbbbabaaabbbbababbbaabbbaaabbababaababbbbbaaabbbabbabaaaababbbaabaaaabbbabaaabbb...
output:
10431998
result:
ok single line: '10431998'
Test #14:
score: 20
Accepted
time: 1246ms
memory: 289784kb
input:
1000 10000 babbababbbaaaaaaaaababbabbbababbbbbbbbabaaaaaabbaababbbbbbbaaaabbaaaaabbbbbbbababbabaaaaabbaaabaaaaaaabbbabbabbaaabbbabbbbababababbabbababbabbbbaabbbbaababbaababbababbbaaabbbbaaabaaaabababbbbaabaababbabbbaabbbbbabbbaaabaabaabbaabaaaaabbabbbbaaabbabbbaababbbaabaaaabbbababbbbbbbabababbaabab...
output:
94347164
result:
ok single line: '94347164'
Test #15:
score: 20
Accepted
time: 1945ms
memory: 413412kb
input:
10000 10000 bbbabbaababbbbbababbbbaabbabaaaababbabbbabababaaaaaababbbaabaabbababbbbbaa b aaabbbbbbabbaabbbbbbaabaaababbbabbabaaabababbababaaabbaabaabaabbbbabb abbaabbaababbbabaabababaaaaaaaabaabbbb bbbbbabbaabbaaaabaabaababbbababbbbbaaaabbabbbabbaabbbabaaababababaabbaaaabaabbaaabbbaaaaaababababbbabb...
output:
694099162
result:
ok single line: '694099162'
Test #16:
score: 20
Accepted
time: 1224ms
memory: 243696kb
input:
100 100 ababababbbababbabbaabbbbbaabaaaaabbabaaaaabbbaabbbabababbbaaaaababbaabbbababaababbaabbaaababaabbaabbbbbbaaababbbaabaaaababbaababbbaaaabbbbaababaabaabaaabaaaabaababaaababbbbabbaabbbbababbaaabaaabaabaabaaaabaaaabbbbbabaaaabababaaababbbbbabbaaaabbbaaaaaaabababbaaababbbabbbbbaaaaaaaaaabbaabababa...
output:
138444
result:
ok single line: '138444'
Subtask #4:
score: 30
Accepted
Test #17:
score: 30
Accepted
time: 1222ms
memory: 234496kb
input:
100 1000 bcbccabbbabacabaabbccbaaabbbbcbbbaaaacaaabbccbababbacbbabbbaccccccccbccabcaacbbccbbbbcaaacabcccaccbaacccbcbaaaccbcaaaaaaaabccaaaacccbabacbcababbacbbbcaabaaacbbcaccbaccccbbcbacabaacbcaccacbcbcbbcbccccbbcacccaabbabcaabbacabaaacccbbcbccbabbcbccbcbbbabbaabacbccbacababbacbababbbaacccacbabcabcaba...
output:
833103
result:
ok single line: '833103'
Test #18:
score: 30
Accepted
time: 1173ms
memory: 243844kb
input:
1000 1000 cacccababcaaccbaaabcbcabcbbccbcbcbbcacbbcabcaaccabcccaacabccaacaaaababbbbbcbbcbcbbbcacbaabccaccbaacaaacabbbcbcbaabbcccacaababbbabcaabbaabaabaabaabccaacccbabcbaacccbbbccaacbbacacacaacccbcbcbaccbccaaacabaacbcbaacbcbacaccbacbbcaccbabbbabbbaccccbbbcacccccaacbbaaaccacabaaacaccabacacbaaaaacbacab...
output:
6757759
result:
ok single line: '6757759'
Test #19:
score: 30
Accepted
time: 1254ms
memory: 266800kb
input:
1000 10000 cbacbccbcbbcccbbcccaacccbbbacbccaaaccabacaabacccbbbcbabcaacabbabbabcaaaabccbabcaaacaaabbbacccacabcacccaaababcacbaacaccbccbcaaaaaaaaccabbcaaaaabccacaacbccabacabcccaabbcaccbcabbccbabbbccaacbabcbacacabbaaaababbccbcbacbbbcaccaabacbcaabbaaacaacccaaabbbcabbbcccacacaccaacbccabccbcacbbbbbabcbabbc...
output:
61388196
result:
ok single line: '61388196'
Test #20:
score: 30
Accepted
time: 1582ms
memory: 347392kb
input:
10000 10000 aababaaccbcbabaccbaccbcaaabbcbbbbacbcbababbccbccbbac cbcccccacaccabcbbbaaabcaaccabccccccbabacbbabbaaacbabccbcaacacbbbabbbbcbbcbcbaaccaccbabccabbbbbabcabcbcccababbcabaccbbccbaaacaabacbcbcbbabbcbaabcaccaaaccbbcacaaabcabacabccbaabbacabccacbabbaababb cacbcbabc caacccaabaaccbbbabaababbbbcbcac...
output:
462062051
result:
ok single line: '462062051'
Test #21:
score: 30
Accepted
time: 1215ms
memory: 236764kb
input:
100 100 abcababbbbbcaccccbcacacabbccccbbccacbbabacabbbbacacaacaaabbcaabcaaaaabaaccbaaacbbcbbcabbaaababacabcccaabbcbbbbaaaacaabbbacbcabacbbccbbacacbaaabacabbcbbcaabaccababccaaababbcbcacbabababcbcccccccababcbbbaaabbacbaabbaababcabaacbccacbbaccbbbbcbbabbccaacbaccaaabaccbaacaaaaabbcaccbbbaaccaaccccbbbaa...
output:
90325
result:
ok single line: '90325'
Test #22:
score: 30
Accepted
time: 734ms
memory: 257572kb
input:
430 800 aaaccaccaacbcccbccbccaaaaaabccabbcbccabcacbcaabcbacbccbbacccaccabccacbbcccccbacaacbabbbaaaaacbbbcabacbccaabcabcbacccacbabaacacbcaacbabbabbbbbaacacabbaccaabcccbacbbabccccccbabbaaaaababcababaabcaabbcbbaaccaccabbaabcabccbbcbacacaaabcbaaccccbcbacbccacaaacbbaabaabccabaacbccccbbbbcabccbbcbbcbccaba...
output:
157989035
result:
ok single line: '157989035'
Test #23:
score: 30
Accepted
time: 1333ms
memory: 183080kb
input:
400 400 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
40039936
result:
ok single line: '40039936'
Test #24:
score: 30
Accepted
time: 2188ms
memory: 346548kb
input:
400 400 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabaaaaabbbbaabbb...
output:
108484268
result:
ok single line: '108484268'