QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#341845#6224. 节日庆典ushg8877100 ✓340ms18320kbC++141.2kb2024-02-29 21:54:402024-02-29 21:54:41

Judging History

你现在查看的是最新测评结果

  • [2024-02-29 21:54:41]
  • 评测
  • 测评结果:100
  • 用时:340ms
  • 内存:18320kb
  • [2024-02-29 21:54:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MAXN=3e6+5;
int n,lcp[MAXN];char s[MAXN];
void exkmp(){
	for(int i=2,l=0,r=0;i<=n;i++){
		if(i<=r) lcp[i]=min(lcp[i-l+1],r-i+1);
		while(i+lcp[i]<=n&&s[lcp[i]+1]==s[i+lcp[i]]) lcp[i]++;
		if(i+lcp[i]-1>r) l=i,r=i+lcp[i]-1;
	}
}
bool chkmin(int x,int y,int r){// return s[x:r]+s[1:x-1]<s[y:r]+s[1+y-1]
	x=(x+r-y)+1;y=1;
	if(lcp[x]<r-x+1) return s[x+lcp[x]]<s[lcp[x]+1];
	y=(y+r-x)+1;
	if(lcp[y]<r-y+1) return s[lcp[y]+1]<s[y+lcp[y]];
	return true;
}
int main(){
	ios::sync_with_stdio(false);
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	cin>>s+1;n=strlen(s+1);
	exkmp();
	vector<int> cur,nxt;
	for(int i=1;i<=n;i++){
		cur.push_back(i);nxt.clear();
		for(int j:cur){
			bool flag=true;
			while(!nxt.empty()){
				int k=nxt.back();
				if(s[i-j+k]==s[i]) break;
				else if(s[i-j+k]<s[i]) {flag=false;break;}
				else nxt.pop_back();
			}
			if(flag&&(nxt.empty()||i-j<=j-nxt.back())) nxt.push_back(j);
		}
		cur=nxt;int ans=cur[0];
		for(int j:cur) ans=chkmin(ans,j,i)?ans:j;
		cout<<ans<<" \n"[i==n];
	}
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 1ms
memory: 3608kb

input:

cabacabacaccabbbaa

output:

1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 17

result:

ok 18 numbers

Test #2:

score: 10
Accepted
time: 0ms
memory: 3756kb

input:

cabacabacbaaabbccccaabbabbccabbbbbbbcaccbcbcccbbbccbccbbcccabacbacccbbcacbcabcbcbabbacbccbacbbbbbbaacbbbcccbbcccbbaacaccababaacacccbbbabbbcaaaabcabaacabcacaabbacabcbaccbbbbbcaacccabcacbbbabbaccabaccbbaacccababbacbaacaaabbbbabbbbbbbbcacbabaabababbbacabcbabacbccaaacbabcaaccbbcbacaaccbacbabaccaccbcbcbb...

output:

1 2 2 2 2 2 2 2 2 2 2 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11...

result:

ok 1000 numbers

Test #3:

score: 10
Accepted
time: 1ms
memory: 3616kb

input:

cabacabacbbaaaacbbabcbaaacbabcaaaacccaabaacbcccabbabcabbabcaacbccbbbcbbaabbabaabcbbaaacababccbbbbaacccbabbbcbbababcbbbaaabbbbcbcbbcbbacaaccbbaacbbcbccacaaabaccbccbaacbaaccaccacacbbcaacaacccbbabbbabbaaaacabcbaaacccbcacbabbaaccaccbbcbcbbccabbcbbababaaccabccbabaacacabcaacccbaccccacccbcbccccbabcbaccbcbc...

output:

1 2 2 2 2 2 2 2 2 2 2 2 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 31 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 ...

result:

ok 1000 numbers

Test #4:

score: 10
Accepted
time: 14ms
memory: 4660kb

input:

cabacabaacbbbcbaaacbbacbcccbccaacbcaaaacabcbcbbcabaabcbccbabcabcbacbaccaaccaccbccacbcaacaaaaabbaabcabacacbcbaccacabcbcccabcbbcccbbcccbaccccbcbabcccbcabacabcbaccacababbcabcaccaaabcbacccaabaaabcacacacbaacbccacccccaacaaabbbcabaabbbabbcccbccbccaabccaacabcacbbcabaccaacaacbacbcabcaccbababbaaababaaaabcaaba...

output:

1 2 2 2 2 2 2 2 8 8 8 8 8 8 8 8 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 89 89 89 89 89 89 89 89 89 89 89 89 89 89 8...

result:

ok 200000 numbers

Test #5:

score: 10
Accepted
time: 5ms
memory: 3792kb

input:

yzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzyzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxz...

output:

1 1 3 1 5 1 7 1 9 1 11 1 13 1 15 1 17 1 19 1 21 1 23 1 25 1 27 1 29 1 31 1 33 1 35 1 37 1 39 1 41 1 43 1 45 1 47 1 49 1 51 1 53 1 55 1 57 1 59 1 61 1 63 1 65 1 67 1 69 1 71 1 73 1 75 1 77 1 79 1 81 1 83 1 85 1 87 1 89 1 91 1 93 1 95 1 97 1 99 1 101 1 103 1 105 1 107 1 109 1 111 1 113 1 115 1 117 1 1...

result:

ok 49400 numbers

Test #6:

score: 10
Accepted
time: 92ms
memory: 7252kb

input:

tutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutxtutvtutwtutvtuttutvtutwtutvtutxtutvtutwtutvtutytutvtutwtutvtutx...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6...

result:

ok 1000000 numbers

Test #7:

score: 10
Accepted
time: 97ms
memory: 6676kb

input:

stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 1000000 numbers

Test #8:

score: 10
Accepted
time: 340ms
memory: 12400kb

input:

stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 3000000 numbers

Test #9:

score: 10
Accepted
time: 326ms
memory: 18320kb

input:

abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaiabacabadabacabaeabacabadabacabafabacabadabac...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 3000000 numbers

Test #10:

score: 10
Accepted
time: 249ms
memory: 10572kb

input:

stsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsystsustsvstsustswstsustsvstsustsxstsustsvstsustswstsustsvstsustsstsustsvstsustswstsustsvstsustsxstsustsvstsust...

output:

1 1 3 1 5 5 7 1 9 9 11 9 13 13 15 1 17 17 19 17 21 21 23 17 25 25 27 25 29 29 31 1 33 33 35 33 37 37 39 33 41 41 43 41 45 45 47 33 49 49 51 49 53 53 55 49 57 57 59 57 61 61 63 1 65 65 67 65 69 69 71 65 73 73 75 73 77 77 79 65 81 81 83 81 85 85 87 81 89 89 91 89 93 93 95 65 97 97 99 97 101 101 103 97...

result:

ok 3000000 numbers

Extra Test:

score: 0
Extra Test Passed