QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#685157#9522. A Simple String ProblemCrysflyAC ✓575ms183976kbC++145.5kb2024-10-28 17:58:582024-10-28 17:59:00

Judging History

你现在查看的是测评时间为 2024-10-28 17:59:00 的历史记录

  • [2024-11-10 22:37:22]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:512ms
  • 内存:184136kb
  • [2024-11-10 22:36:11]
  • hack成功,自动添加数据
  • (/hack/1163)
  • [2024-11-06 21:48:54]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:601ms
  • 内存:184596kb
  • [2024-11-06 21:48:00]
  • hack成功,自动添加数据
  • (/hack/1142)
  • [2024-10-28 17:59:00]
  • 评测
  • 测评结果:100
  • 用时:575ms
  • 内存:183976kb
  • [2024-10-28 17:58:58]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    int x;cin>>x;return x;
}

#define mod 1000000007
struct modint{
	unsigned int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x<o.x?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}


#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 500055
#define inf 0x3f3f3f3f

struct SA{
	int n,m,sa[maxn],x[maxn],y[maxn],c[maxn],h[maxn];
	char s[maxn];
	int st[21][maxn];
	void getsa()
	{
		m=127;
		For(i,1,n)c[x[i]=s[i]]++;
		For(i,2,m)c[i]+=c[i-1];
		Rep(i,n,1)sa[c[x[i]]--]=i;
		for(int k=1;k<=n;k<<=1)
		{
			int num=0;
			For(i,n-k+1,n)y[++num]=i;
			For(i,1,n)if(sa[i]>k)y[++num]=sa[i]-k;
			For(i,1,m)c[i]=0;
			For(i,1,n)c[x[i]]++;
			For(i,2,m)c[i]+=c[i-1];
			Rep(i,n,1)sa[c[x[y[i]]]--]=y[i],y[i]=0;
			swap(x,y);
			x[sa[1]]=num=1;
			For(i,2,n)
				x[sa[i]]=(y[sa[i]]==y[sa[i-1]] && y[sa[i]+k]==y[sa[i-1]+k])?num:++num;
			if(num==n)break;
			m=num;
		}
	}
	void geth(){
		int k=0;
		For(i,1,n)x[sa[i]]=i;
		For(i,1,n)
		{
			if(k)k--;
			int j=sa[x[i]-1];
			while(j+k<=n&&i+k<=n&&s[j+k]==s[i+k])k++;
			h[x[i]]=k; 
		}
	}
	void build(){
		getsa(),geth();
		For(i,1,n)st[0][i]=h[i];
		For(j,1,20)
			For(i,1,n+1-(1<<j))
				st[j][i]=min(st[j-1][i],st[j-1][i+(1<<(j-1))]);
	}
	inline int lcp(int a,int b){
		if(a==b)return n-a+1;
		int l=x[a],r=x[b];
		if(l>r)swap(l,r);
		l++;int k=__lg(r-l+1);
		return min(st[k][l],st[k][r-(1<<k)+1]);
	}
    void rever(){
        reverse(s+1,s+n+1);
    }
}sa,sa2;

int n;

char s[3][200005];
void GC(char&ch){
	while(!isalpha(ch=getchar()));
}
int id[3][200005];
int lcp(int x,int y,int xx,int yy){
    int u=id[x][y],v=id[xx][yy];
    if(!u||!v)return 0;
    int res=sa.lcp(u,v);
    res=min(res,min(n+(x-1)-y+1,n+(xx-1)-yy+1));
    return res;
}
int lcs(int x,int y,int xx,int yy){
    int u=id[x][y],v=id[xx][yy];
    if(!u||!v)return 0;
  //  cout<<"u,v "<<u<<" "<<v<<"\n";
    u=sa.n+1-u;
    v=sa.n+1-v;
 //   cout<<"idlcs: u,v: "<<u<<" "<<v<<"\n";
 //   For(i,1,sa2.n) cout<<sa2.s[i]<<" "; cout<<" sa2\n";
    int res=sa2.lcp(u,v);
    res=min(res,min(y-(x-1),yy-(xx-1)));
    return res;
}

void work()
{
    n=read();
    For(i,1,n) GC(s[1][i]),sa.s[++sa.n]=s[1][i],id[1][i]=sa.n;
    For(i,1,n) GC(s[2][i+1]),sa.s[++sa.n]=s[2][i+1],id[2][i+1]=sa.n;

    sa2=sa;
    sa2.rever();
    sa.build();
    sa2.build();
    
  /*  For(j,1,2){
        For(i,1,n+1) cout<<id[j][i]<<" ";
        cout<<"\n";
    }
    For(i,1,sa.n) cout<<sa.s[i]<<" "; cout<<"\n";*/


    int res=0;
    Rep(w,(n+1)/2,1){
        for(int i=w;i+w<=n+1;i+=w){
            int l=i,r=i+w;

          //  cout<<"l,r "<<l<<" "<<r<<"\n";
            {
                //case up
                int ls=lcs(1,l,1,r);
                int lp=lcp(1,l,1,r);
                lp+=lcp(1,l+lp,2,r+lp);
              //  cout<<"ls,lp "<<ls<<" "<<lp<<"\n";
                if(ls+lp>=w+1) res=max(res,w);
            }
            {
                // case dw
                int lp=lcp(2,l,2,r);
                int ls=lcs(2,l,2,r);
                ls+=lcs(1,l-ls,2,r-ls);
             //   cout<<"LS,LP "<<ls<<" "<<lp<<"\n";
                if(ls+lp>=w+1) res=max(res,w);
            }
            {
                // case up dw
                int ls1=lcs(1,l,2,r);
                int ls2=lcs(1,l-ls1,1,r-ls1);
                int lp1=lcp(1,l,2,r);
                int lp2=lcp(2,l+lp1,2,r+lp1);
            //    cout<<"ls1,ls2 lp1,lp2 "<<ls1<<" "<<ls2<<" "<<lp1<<" "<<lp2<<"\n";
                if((ls1+lp1+lp2)>=w+1 || (ls2+ls1+lp1)>=w+1){
                    res=max(res,w);
                }
            }
        }
        if(res>0){
            cout<<res*2<<"\n";
            exit(0);
        }
    }
    cout<<0<<"\n";
}

signed main()
{
    int T=1;
    while(T--)work();
	return 0;
}
/*
6
aabbab
 aabbaa
*/

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 12ms
memory: 120624kb

input:

5
abcab
acabc

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 11ms
memory: 120016kb

input:

6
babbaa
babaaa

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 15ms
memory: 119224kb

input:

2
ne
fu

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 20ms
memory: 120848kb

input:

6
baabba
baabab

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 24ms
memory: 118860kb

input:

6
aaabba
aabbba

output:

2

result:

ok single line: '2'

Test #6:

score: 0
Accepted
time: 20ms
memory: 119176kb

input:

6
abaabb
bbbaba

output:

4

result:

ok single line: '4'

Test #7:

score: 0
Accepted
time: 274ms
memory: 183312kb

input:

200000
wvblpxtatzytphgshchrevqqpnbljlorfoqubygysrivtemegmgrepemnlcbfqalpqqpvuockkbbvjnouhcerxqibevbipsxuscjejlcdtxoxipwrfrjwnriubvdgdgzlydwwiueovtrzljqxwfegejukncmahbcbsraxboukdesrzbwfvbpxpdntauidrybccwaocfwntohdkhxkfqhnoccyaylvvfebckmslrthubxrxvjoqcredanofbmgtsnswgszwhjckqeiddzvpnxphjkrwlsbthdvhzgn...

output:

200000

result:

ok single line: '200000'

Test #8:

score: 0
Accepted
time: 264ms
memory: 182256kb

input:

199999
klwumjcvuqinrkcsyvgfixhwvrwbmazkclblcnlpyxtlmmpkllkpukmxaurpukvgibcsuigcoqnnreivrlrwfdqofqcwubpolnnxcansyaevdjvnhnzvjeoejktaodusltockhtuqrohqfsrezdzurowghmcateztzlltkzlqynxpgbqsvgqtpukmfgdxopynqaegmjxvjixyzjrhbgahxwkswgpanhrdgpyvtvcpsihdvmtixfskuiprfqrfknohthfblkzlrcyqewdycoljgwrhjkmoxqmtogmg...

output:

200000

result:

ok single line: '200000'

Test #9:

score: 0
Accepted
time: 276ms
memory: 183236kb

input:

200000
yagcbqaxecsgdijvsdsqlemrrhyyuysvlbkkgultlmrapzokempkzmyyvgabgtqifgqhwyudzbkbjncsuixvyffpvtuczjakknocyskvqaohfvxomjhzirykpdwisgkmyomejaxbzamrnfcxjwjouskvjfuriurzknmhfvpvbdqunfckdmxhndvffhuybezncgohzwxvwfscltbhwvgvbrrejtuixsdwetkdxlogepphsvhyzybisqixsledftgegzbslkqsalhoifysrxsbjxvpojjxkqqoumlkj...

output:

114514

result:

ok single line: '114514'

Test #10:

score: 0
Accepted
time: 575ms
memory: 182736kb

input:

200000
cbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbabcbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbabcbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcbabcacbabcbacabcacbacabcbabcacbacabcacbabcbacabcacbacabcbabcacbabcbaca...

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 223ms
memory: 183024kb

input:

200000
bbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbaba...

output:

150050

result:

ok single line: '150050'

Test #12:

score: 0
Accepted
time: 252ms
memory: 183976kb

input:

200000
babababbaaaaaaabbbaaabbbbaaabbaaaabbaababbabbbbbababbbabbbaaabaaabaabbaabbaabbabbaaaaaababbbbbbaaaabaababbabaaabbbbbbabaaaabaaabaaaababaaabbbbbbaaabaabaaabbabbbabbbabaaaabbbbbbabbaabbaaaaaaaaabababbabbbbbaabaabaaabababbaabbbbbbabbaaaaababaabbaaaabbbbaaababbabbaabaabaabaaabbabaaaaabbabababbbaa...

output:

131072

result:

ok single line: '131072'

Test #13:

score: 0
Accepted
time: 497ms
memory: 182920kb

input:

200000
rhqtphowacdrsxqisrqjhcsmxvwqtbmsvawxxxujgibnowkeyzhnjihsvsuklueukevgvlfqnrhalhglqlknerjwzizhxxszwjtnroubsjdhbnekbolwxaigyeypumuncdhmqqeljoyewehkhsqfoirchdnwazypwtefdyvtockpluejsftmffgbgdcotjnnkimawpflzwurdwrmpeudobzhpoyktufkgyvxpbfhuzswkrmnfzultfxdefoffvrfmuoufylyfvexnxgwgqfbiqvwpyenoqxncisuz...

output:

8

result:

ok single line: '8'

Test #14:

score: 0
Accepted
time: 11ms
memory: 120888kb

input:

10
aaabaabaaa
aabbbaaaba

output:

6

result:

ok single line: '6'

Test #15:

score: 0
Accepted
time: 20ms
memory: 120776kb

input:

17
ababbbaabbbaaaaba
abbabbbbbaabaabba

output:

10

result:

ok single line: '10'

Test #16:

score: 0
Accepted
time: 25ms
memory: 119860kb

input:

22
aaabbbaaaababbabbbbbbb
bbaabbbbbaaabbbabaaaaa

output:

8

result:

ok single line: '8'

Test #17:

score: 0
Accepted
time: 11ms
memory: 119588kb

input:

15
abaabaaaaabbbab
abbbabbbabababa

output:

8

result:

ok single line: '8'

Test #18:

score: 0
Accepted
time: 12ms
memory: 119376kb

input:

5
aabba
baaba

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 15ms
memory: 120708kb

input:

1
a
a

output:

2

result:

ok single line: '2'

Test #20:

score: 0
Accepted
time: 22ms
memory: 120724kb

input:

100
baabaaaabaabaabaaabaabbbabbbbbaababbabbbabbbbababaaabbabbaaaabbbaaabaabbbaaaaaababaababbbbbaaabbaabb
abbbbbbbbaaaaababbabbabbbbbaaaabbabbbaaaaabababbbabbababbbabbaabbabbabbbaaababbabbabbabbbabbbababaaa

output:

20

result:

ok single line: '20'

Test #21:

score: 0
Accepted
time: 16ms
memory: 119060kb

input:

32
babbbbbabbababaabbbaaaaabbaababa
abbbaaababaabababbaaabaaabbaaaab

output:

18

result:

ok single line: '18'

Extra Test:

score: 0
Extra Test Passed