QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712691 | #9514. 研心 | zjy0001 | 100 ✓ | 3324ms | 434280kb | C++20 | 7.1kb | 2024-11-05 16:41:41 | 2024-11-05 16:41:41 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=4e5+5,M=N*4,BL=150;
const int B=233,P=1e9+9;
int n,m,sL,cnt=128;
LL ans;
int s[M];
int pwB[N];
int SF[N],TF[N];
string S[N],T[N];
vector<tuple<int,int,int>>Q[N];
int sa[M],rk[M],height[M],ST[21][M];
vector<int>SQ[N],TQ[N],Sid[N],Tid[N];
vector<int>preS[N],sufS[N],preT[N],sufT[N];
template<class T>inline void SA(T* s,int n){
static int t1[M],t2[M],cnt[M];
int *x=t1,*y=t2,m=*max_element(s+1,s+n+1);
for(int i=1;i<=n;++i)++cnt[x[i]=s[i]];
for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
for(int i=n;i>=1;--i)sa[cnt[x[i]]--]=i;
fill(cnt,cnt+m+1,0);
for(int k=1;;k<<=1){
int p=0;
for(int i=n-k+1;i<=n;++i)y[++p]=i;
for(int i=1;i<=n;++i)if(sa[i]>k)y[++p]=sa[i]-k;
for(int i=1;i<=n;++i)++cnt[x[i]];
for(int i=1;i<=m;++i)cnt[i]+=cnt[i-1];
for(int i=n;i>=1;--i)sa[cnt[x[y[i]]]--]=y[i],y[i]=0;
fill(cnt,cnt+m+1,0);
swap(x,y),x[sa[p=1]]=1;
for(int i=2;i<=n;++i)
x[sa[i]]=p=p+1-(y[sa[i]]==y[sa[i-1]]&&(sa[i]+k<=n?y[sa[i]+k]:0)==(sa[i-1]+k<=n?y[sa[i-1]+k]:0));
if((m=p)>=n)break;
}
for(int i=1;i<=n;++i)rk[sa[i]]=i;
for(int i=1,j=0;i<=n;++i){
j=max(j-1,0);
if(rk[i]==1)continue;
int k=sa[rk[i]-1];
while(i+j<=n&&j+k<=n&&s[i+j]==s[j+k])++j;
height[rk[i]]=j;
}
copy_n(height+1,n,ST[0]+1);
for(int j=0,jj=1;jj*2<=n;++j,jj*=2)
for(int i=n-jj*2+1;i>=1;--i)
ST[j+1][i]=min(ST[j][i],ST[j][i+jj]);
}
inline int LCP(int x,int y){
if((x=rk[x])>(y=rk[y]))swap(x,y);
const int t=__lg(y-(x++));
return min(ST[t][x],ST[t][y-(1<<t)+1]);
}
struct Trie{
int n,tim;
vector<int>gap[N];
vector<pair<int,int>>G[N];
int T[N][26],dL[N],dR[N],pos[N],W[N],rk[N],ed[N],d[N];
Trie(){n=1;}
inline void ins(string s,vector<int>q,int id){
int p=1;
for(int i=0;i<s.length();++i){
const int c=s[i]-'a';
if(!T[p][c])T[p][c]=++n;
p=T[p][c];
if(i%2==0&&q[i/2])W[p]=1;
}
++ed[p],pos[id]=p;
}
inline void dfs(int u){
gap[d[u]].emplace_back(u);
rk[dL[u]=++tim]=u;
for(int i=0;i<26;++i)if(T[u][i])
G[u].emplace_back(T[u][i],i),d[T[u][i]]=d[u]+1,dfs(T[u][i]);
dR[u]=tim;
}
}SE,TE;
struct segtree{
int s[N*4],ad[N*4],mn[N*4];
inline void build(int p,int l,int r){
mn[p]=0,ad[p]=0;
if(l==r)return s[p]=SE.ed[SE.rk[l]],void();
const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
build(ls,l,mid),build(rs,mid+1,r);
s[p]=s[ls]+s[rs];
}
inline void upd(int p,int l,int r,int x,int y,int z){
if(x<=l&&r<=y)return ad[p]+=z,mn[p]+=z,void();
const int mid=(l+r)>>1,ls=p*2,rs=p*2+1;
if(ad[p])ad[ls]+=ad[p],mn[ls]+=ad[p],ad[rs]+=ad[p],mn[rs]+=ad[p],ad[p]=0;
if(x<=mid)upd(ls,l,mid,x,y,z);
if(mid<y)upd(rs,mid+1,r,x,y,z);
mn[p]=min(mn[ls],mn[rs]),s[p]=(mn[ls]==mn[p]?s[ls]:0)+(mn[rs]==mn[p]?s[rs]:0);
}
}tr;
inline int Spre(int x,int l,int r){
return (preS[x][r+1]+1ll*preS[x][l]*(P-pwB[r-l+1]))%P;
}
inline int Ssuf(int x,int l,int r){
return (sufS[x][l]+1ll*sufS[x][r+1]*(P-pwB[r-l+1]))%P;
}
inline int Tpre(int x,int l,int r){
return (preT[x][r+1]+1ll*preT[x][l]*(P-pwB[r-l+1]))%P;
}
inline int Tsuf(int x,int l,int r){
return (sufT[x][l]+1ll*sufT[x][r+1]*(P-pwB[r-l+1]))%P;
}
inline int solve(string s){
int n=s.length();
s=" "+s+"$";
vector<int>p(n+2);
for(int i=2,j=1,k=2;i<=n;++i){
p[i]=min(k-i,(j+j>=i?p[j+j-i]:0));
for(;s[i-p[i]]==s[i+p[i]];++p[i]);
if(i+p[i]>k)k=i+p[i],j=i;
}
return *max_element(p.begin(),p.end());
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;
pwB[0]=1;
for(int i=1;i<N;++i)pwB[i]=1ll*pwB[i-1]*B%P;
for(int i=0;i<n;++i)cin>>S[i];
for(int i=0;i<m;++i)cin>>T[i];
for(int i=0;i<n;++i){
preS[i].resize(S[i].length()+1);
sufS[i].resize(S[i].length()+1);
SQ[i].resize(S[i].length());
for(int j=0;j<S[i].length();++j)preS[i][j+1]=(1LL*preS[i][j]*B+S[i][j])%P;
for(int j=S[i].length();j--;)sufS[i][j]=(1LL*sufS[i][j+1]*B+S[i][j])%P;
for(int j=0;j<S[i].length();++j){
int z=0;
for(int l=1,r=min(j+1,(int)S[i].length()-j);l<=r;){
const int mid=(l+r)>>1;
if(Spre(i,j-mid+1,j)==Ssuf(i,j,j+mid-1))z=mid,l=mid+1;
else r=mid-1;
}
SF[i]=max(SF[i],z);
if(z==S[i].length()-j)SQ[i][j]=1;
}
}
for(int i=0;i<m;++i){
preT[i].resize(T[i].length()+1);
sufT[i].resize(T[i].length()+1);
TQ[i].resize(T[i].length());
for(int j=0;j<T[i].length();++j)preT[i][j+1]=(1LL*preT[i][j]*B+T[i][j])%P;
for(int j=T[i].length();j--;)sufT[i][j]=(1LL*sufT[i][j+1]*B+T[i][j])%P;
for(int j=0;j<T[i].length();++j){
int z=0;
for(int l=1,r=min(j+1,(int)T[i].length()-j);l<=r;){
const int mid=(l+r)>>1;
if(Tpre(i,j-mid+1,j)==Tsuf(i,j,j+mid-1))z=mid,l=mid+1;
else r=mid-1;
}
TF[i]=max(TF[i],z);
if(z==j+1)TQ[i][j]=1;
}
}
for(int i=0;i<n;++i)
SE.ins(string(S[i].rbegin(),S[i].rend()),vector<int>(SQ[i].rbegin(),SQ[i].rend()),i);
for(int i=0;i<m;++i)
TE.ins(T[i],TQ[i],i);
SE.dfs(1),TE.dfs(1);
vector<pair<int,int>>cur;
for(int i=1;i<=BL;++i){
for(int j=0;j<n;++j)if(SF[j]>=i)
Q[TE.dL[1]].emplace_back(SE.dL[SE.pos[j]],SE.dL[SE.pos[j]],1),
Q[TE.dR[1]+1].emplace_back(SE.dL[SE.pos[j]],SE.dL[SE.pos[j]],1);
for(int j=0;j<m;++j)if(TF[j]>=i)
Q[TE.dL[TE.pos[j]]].emplace_back(SE.dL[1],SE.dR[1],1),
Q[TE.dL[TE.pos[j]]+1].emplace_back(SE.dL[1],SE.dR[1],-1);
vector<pair<int,int>>nxt;
for(auto [x,y]:cur)for(auto [z,c]:SE.G[x])if(TE.T[y][c])nxt.emplace_back(z,TE.T[y][c]);
if(i>1){
for(auto u:SE.gap[i+i-3])if(SE.W[u])for(auto [v,c]:SE.G[u])if(TE.T[1][c])nxt.emplace_back(v,TE.T[1][c]);
for(auto u:TE.gap[i+i-3])if(TE.W[u])for(auto [v,c]:TE.G[u])if(SE.T[1][c])nxt.emplace_back(SE.T[1][c],v);
}
sort(nxt.begin(),nxt.end()),nxt.erase(unique(nxt.begin(),nxt.end()),nxt.end());
for(auto [x,y]:nxt)Q[TE.dL[y]].emplace_back(SE.dL[x],SE.dR[x],1),Q[TE.dR[y]+1].emplace_back(SE.dL[x],SE.dR[x],-1);
tr.build(1,1,SE.n);
for(int j=1;j<=TE.n;++j){
for(auto [l,r,v]:Q[j])tr.upd(1,1,SE.n,l,r,v);
ans+=TE.ed[TE.rk[j]]*(n-(tr.mn[1]?0:tr.s[1])),Q[j].clear();
}
cur=nxt;
}
for(int i=0;i<n;++i){
Sid[i].resize(S[i].length());
for(int j=S[i].length();j--;)s[Sid[i][j]=++sL]=S[i][j];
s[++sL]=cnt++;
}
for(int i=0;i<m;++i){
Tid[i].resize(T[i].length());
for(int j=0;j<T[i].length();++j)s[Tid[i][j]=++sL]=T[i][j];
s[++sL]=cnt++;
}
SA(s,sL);
for(int i=0;i<n;++i)if(S[i].length()>BL)
for(int j=0;j<m;++j)if(T[j].length()<=BL){
int z=max(SF[i],TF[j]),r=T[j].length();
for(int k=z;k>=max(1,z-r);--k)if(SQ[i][S[i].length()-k])
z=max(z,k+(k+k<=S[i].length()?LCP(Sid[i][S[i].length()-k-k],Tid[j][0]):0));
if(z>BL)ans+=z-BL;
}
for(int j=0;j<m;++j)if(T[j].length()>BL)
for(int i=0;i<n;++i)if(S[i].length()<=BL){
int z=max(SF[i],TF[j]),r=S[i].length();
for(int k=z;k>=max(1,z-r);--k)if(TQ[j][k-1])
z=max(z,k+(k+k<=T[j].length()?LCP(Sid[i][S[i].length()-1],Tid[j][k+k-1]):0));
if(z>BL)ans+=z-BL;
}
for(int i=0;i<n;++i)if(S[i].length()>BL)
for(int j=0;j<m;++j)if(T[j].length()>BL){
int z=solve(S[i]+T[j]);
if(z>BL)ans+=z-BL;
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 16ms
memory: 142108kb
input:
10 100 aabaababaaaababbabaaaababaababbbaabbbaabaabaabbbaababaaababbaababababbbaababbbbbbbbaabbbbaabbbbbbbbaabaabbbaabbbbbabbbbbaabbbaabaa bbaaabaabbbbaaabaaaaabbbbbabaabbabbaabbaabbaabbabbababaabaabbaabbbbbbaaaabbbbabaaaabaaabbbabaaaaaabbaaaabbbabbbbbaaaabbabaababbaabbaaabbbbbbaaaabbbababaabbaaaba b...
output:
10468
result:
ok single line: '10468'
Test #2:
score: 20
Accepted
time: 15ms
memory: 142328kb
input:
10 100 abbacbbaabababcaabbaabbbabcaccabcabbabbbccaacabaabacccbacaaabbaaabbbaacaabbabcabbbcbacaaaaabaaaabaaacbbccbacacbbaaccacbabcbccacbaaacaaacccbabbaccacaaacaabbbccaaccbbabaabcbbcbcbb bccabcacbacccbcababaccccaaabbccacaccccabbaabbcacabaccabacbbbaaaabaabccbcaacaaccbcacabcbbbcccccabccbaababccccabcabab...
output:
6384
result:
ok single line: '6384'
Test #3:
score: 20
Accepted
time: 19ms
memory: 142028kb
input:
50 50 aaaaabbabbbbbaababbaaaababaababababbbbaabaaaaaaaabaabbaaabaaaabaaabaabbbabbbababbbbabbbabbaaababbabaabbabbabbabbaaababaaaaabbbbbbaabaabaabbbbbabaaababb abbabbbaabaaaaabababaabbabaabbbbab bababbbbaabaabbaabbbbaabaabbbaabbbbaaabbabbbaaabbbbaaabaabbaaaaaabbbabaaaaabbaabaabaaabaaababbbbbaaabbbbbba...
output:
21362
result:
ok single line: '21362'
Test #4:
score: 20
Accepted
time: 23ms
memory: 141896kb
input:
50 50 aababcabbbcbaacaaaaccababbacbbaaabcbaaccabbababbcccaacaaaacacbcbaaabaacabbbbbbaccaaacbbacaacacbcccbbacabbcbcbacababcbbacaccaacacbcccbababaccabccccbabaccababccccbcbabcabcabccaaccababcbccacbbaaaacc cbaccababccbaaacbccabbcccacacacaaaabaaababcacabaccbccacbcbaaaaabbacbbaccabba ccbcbcacbcaccabbbccaa...
output:
13421
result:
ok single line: '13421'
Test #5:
score: 20
Accepted
time: 11ms
memory: 139520kb
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: 889ms
memory: 422884kb
input:
1 10000 bcacacbcdadbcbccbdddaaddabcaccccbaabbcdcdaabdacccadacbbbabdaaacadacdccadcbdadadcaaabdbdbdcdcccbacbdbccacbdadcaaaacbabdadcacdcacadcadaabdaaabccccdcbcdbcadcaabbbaacaadaccdaccadbddcdbccbcddcaadcaadaadbbaadbcdbddbcbadbccbaddaacabcdccbadaddcadcbababccabcaadbcbdbcbbcdcbdbcdbdaaddbacddcabbbdccbddba...
output:
1160913325
result:
ok single line: '1160913325'
Test #7:
score: 30
Accepted
time: 1435ms
memory: 420216kb
input:
1 1000 caaadbacdaaccbdcaccbdbddcdaccaaaaaccdccaadbadbcdccaacdadcccaddadcbacbbdcaadbbcdaddcadddccdbabccdadcaacabcabbbdbbbbdbbaaccddcdddcddddddbdbbadbddcbacdcdbdabcbbdbbaaadbdacaccdbaaabacbacabdaccaabaadddccbabacdbdddbdcadadcdccabaabbccbacddddcbcdbabaadaddbbdabadaccbdbaaabdadadaadabbdbadacacbdcbcbdccc...
output:
134272327
result:
ok single line: '134272327'
Test #8:
score: 30
Accepted
time: 950ms
memory: 422660kb
input:
1 10000 bbcbcaacaaaacacbacacbaacbacbaababaacacbacbacbccaacbbacbbccababcaaaccabaaccbbbaaaabbababaacbbccabcaccaaccbacccaacabcaacacaccababbbbbcbacaaabbcbaccacaaaaabbacbbcbbcabccaabcabcabaabbbabbababbabcacbcaccabacaababbacccabbcaaacacccbcbcccbbbbaababbabcaaabaccccbbbabccabacbcbabccccaccbcccccbcccccccbbc...
output:
1375114968
result:
ok single line: '1375114968'
Test #9:
score: 30
Accepted
time: 873ms
memory: 426760kb
input:
1 10000 cbaacaaaaccacaacbbcacabccbbabbababbababbacbababbcabcbacabbaaaacccacbbaaacacbacccbababaabccbbcabbbcaacbcbbbcbcbccccbabcacccccaabbbccacccacabccbcccbaaaccbbbacbaabbcbaabccccaabacabccaaccbbbaccbbcbcaabcaacbcbbcacbcbcabbacbababcbcabcbaabbbbbcccccbcacbabbcccccaacccbaccbaacbccbcababbabcbbccbbbbacab...
output:
1363955024
result:
ok single line: '1363955024'
Test #10:
score: 30
Accepted
time: 899ms
memory: 434280kb
input:
1 10000 aacbabccacabcccbccbbcacbbcbcacbbcacbbcbcacacbaaabbbbccaabcbbccccaccccbbcbbcacbbcbbcacbbcbcacacbaaabbbbccaabcbbccccaccccbbcbcbbccccaccccbbbccccaccccbbcbcbbccccaccccbbcbaaccbbbbaaaaabbbbccaabcbbccccaccccbbcbcbbccccaccccbbbccccaccccbbcbcbbccccaccccbbcbaaccbbbbaaabcacacbcbbcacbbcacacbaaabbbbccaa...
output:
1951994915
result:
ok single line: '1951994915'
Test #11:
score: 30
Accepted
time: 898ms
memory: 422736kb
input:
1 10000 bbaabbaaaabbbaaabbbaabaabaababbbbbabaabbababaaabbbbbbabbaaaabbbbbbaabababbbbabbaababbbbabaabaabaaabbabababbbbbaabababbaabbabbbababbbabaaaaabaaaaaaabaabaaabababbbabbabbaaaabababbbbabaabbaaababbaabbbbabbabbabbabbabaababaaaabbbaabbaababbabbbbaaaaaaaaaababbbbabbbabbaabbbbaaabaabbbbbaabbaababbaba...
output:
424739578
result:
ok single line: '424739578'
Subtask #3:
score: 20
Accepted
Test #12:
score: 20
Accepted
time: 1919ms
memory: 370844kb
input:
100 1000 abbabbbbabbbbabaabaabbbbabaaabbbaabaabbabaabaabbaabbaabbababbabbababbbaabaabbaabbbabaabbbaaaabaaaabaababbaaaaaaaaabaabbaababbbbbbabbbabbbbababbbaaaaaabaaaabaaabbabbaaaaabbbabbabaabbabababbaaababbbaaaabbabbbabbabbabbbbbbabaabaabbbaabaaabbaabbabbbbaabbabaaabaabaabbbabbbbbabaababbbabababaabbba...
output:
1289287
result:
ok single line: '1289287'
Test #13:
score: 20
Accepted
time: 3324ms
memory: 365112kb
input:
1000 1000 babbbabaabaaaabbbbbababaaabbaabbbbbabbaababbbbaaabbbbaaabbbababbaaaabaaabbbbbbbbaabbabbbabbabbaaabaabbbbbbbababaabbbbabaaabbaaaaabbbaababbaaaaabbbbaaaabbbaabaaababaaabbabbbabbabbbabbaabbabbbabaaaaaabaabbabbababbbbbabaaabbbbababbbaabbbaaabbababaababbbbbaaabbbabbabaaaababbbaabaaaabbbabaaabbb...
output:
10431998
result:
ok single line: '10431998'
Test #14:
score: 20
Accepted
time: 1360ms
memory: 363224kb
input:
1000 10000 babbababbbaaaaaaaaababbabbbababbbbbbbbabaaaaaabbaababbbbbbbaaaabbaaaaabbbbbbbababbabaaaaabbaaabaaaaaaabbbabbabbaaabbbabbbbababababbabbababbabbbbaabbbbaababbaababbababbbaaabbbbaaabaaaabababbbbaabaababbabbbaabbbbbabbbaaabaabaabbaabaaaaabbabbbbaaabbabbbaababbbaabaaaabbbababbbbbbbabababbaabab...
output:
94347164
result:
ok single line: '94347164'
Test #15:
score: 20
Accepted
time: 903ms
memory: 354396kb
input:
10000 10000 bbbabbaababbbbbababbbbaabbabaaaababbabbbabababaaaaaababbbaabaabbababbbbbaa b aaabbbbbbabbaabbbbbbaabaaababbbabbabaaabababbababaaabbaabaabaabbbbabb abbaabbaababbbabaabababaaaaaaaabaabbbb bbbbbabbaabbaaaabaabaababbbababbbbbaaaabbabbbabbaabbbabaaababababaabbaaaabaabbaaabbbaaaaaababababbbabb...
output:
694099162
result:
ok single line: '694099162'
Test #16:
score: 20
Accepted
time: 1004ms
memory: 376424kb
input:
100 100 ababababbbababbabbaabbbbbaabaaaaabbabaaaaabbbaabbbabababbbaaaaababbaabbbababaababbaabbaaababaabbaabbbbbbaaababbbaabaaaababbaababbbaaaabbbbaababaabaabaaabaaaabaababaaababbbbabbaabbbbababbaaabaaabaabaabaaaabaaaabbbbbabaaaabababaaababbbbbabbaaaabbbaaaaaaabababbaaababbbabbbbbaaaaaaaaaabbaabababa...
output:
138444
result:
ok single line: '138444'
Subtask #4:
score: 30
Accepted
Test #17:
score: 30
Accepted
time: 1751ms
memory: 370960kb
input:
100 1000 bcbccabbbabacabaabbccbaaabbbbcbbbaaaacaaabbccbababbacbbabbbaccccccccbccabcaacbbccbbbbcaaacabcccaccbaacccbcbaaaccbcaaaaaaaabccaaaacccbabacbcababbacbbbcaabaaacbbcaccbaccccbbcbacabaacbcaccacbcbcbbcbccccbbcacccaabbabcaabbacabaaacccbbcbccbabbcbccbcbbbabbaabacbccbacababbacbababbbaacccacbabcabcaba...
output:
833103
result:
ok single line: '833103'
Test #18:
score: 30
Accepted
time: 3158ms
memory: 374104kb
input:
1000 1000 cacccababcaaccbaaabcbcabcbbccbcbcbbcacbbcabcaaccabcccaacabccaacaaaababbbbbcbbcbcbbbcacbaabccaccbaacaaacabbbcbcbaabbcccacaababbbabcaabbaabaabaabaabccaacccbabcbaacccbbbccaacbbacacacaacccbcbcbaccbccaaacabaacbcbaacbcbacaccbacbbcaccbabbbabbbaccccbbbcacccccaacbbaaaccacabaaacaccabacacbaaaaacbacab...
output:
6757759
result:
ok single line: '6757759'
Test #19:
score: 30
Accepted
time: 1223ms
memory: 374800kb
input:
1000 10000 cbacbccbcbbcccbbcccaacccbbbacbccaaaccabacaabacccbbbcbabcaacabbabbabcaaaabccbabcaaacaaabbbacccacabcacccaaababcacbaacaccbccbcaaaaaaaaccabbcaaaaabccacaacbccabacabcccaabbcaccbcabbccbabbbccaacbabcbacacabbaaaababbccbcbacbbbcaccaabacbcaabbaaacaacccaaabbbcabbbcccacacaccaacbccabccbcacbbbbbabcbabbc...
output:
61388196
result:
ok single line: '61388196'
Test #20:
score: 30
Accepted
time: 844ms
memory: 359296kb
input:
10000 10000 aababaaccbcbabaccbaccbcaaabbcbbbbacbcbababbccbccbbac cbcccccacaccabcbbbaaabcaaccabccccccbabacbbabbaaacbabccbcaacacbbbabbbbcbbcbcbaaccaccbabccabbbbbabcabcbcccababbcabaccbbccbaaacaabacbcbcbbabbcbaabcaccaaaccbbcacaaabcabacabccbaabbacabccacbabbaababb cacbcbabc caacccaabaaccbbbabaababbbbcbcac...
output:
462062051
result:
ok single line: '462062051'
Test #21:
score: 30
Accepted
time: 951ms
memory: 370836kb
input:
100 100 abcababbbbbcaccccbcacacabbccccbbccacbbabacabbbbacacaacaaabbcaabcaaaaabaaccbaaacbbcbbcabbaaababacabcccaabbcbbbbaaaacaabbbacbcabacbbccbbacacbaaabacabbcbbcaabaccababccaaababbcbcacbabababcbcccccccababcbbbaaabbacbaabbaababcabaacbccacbbaccbbbbcbbabbccaacbaccaaabaccbaacaaaaabbcaccbbbaaccaaccccbbbaa...
output:
90325
result:
ok single line: '90325'
Test #22:
score: 30
Accepted
time: 1859ms
memory: 327040kb
input:
430 800 aaaccaccaacbcccbccbccaaaaaabccabbcbccabcacbcaabcbacbccbbacccaccabccacbbcccccbacaacbabbbaaaaacbbbcabacbccaabcabcbacccacbabaacacbcaacbabbabbbbbaacacabbaccaabcccbacbbabccccccbabbaaaaababcababaabcaabbcbbaaccaccabbaabcabccbbcbacacaaabcbaaccccbcbacbccacaaacbbaabaabccabaacbccccbbbbcabccbbcbbcbccaba...
output:
157989035
result:
ok single line: '157989035'
Test #23:
score: 30
Accepted
time: 179ms
memory: 175996kb
input:
400 400 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
40039936
result:
ok single line: '40039936'
Test #24:
score: 30
Accepted
time: 1376ms
memory: 294700kb
input:
400 400 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabaaaaabbbbaabbb...
output:
108484268
result:
ok single line: '108484268'