QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#819759#2840. 绿绿与串串MirasycleAC ✓103ms30700kbC++141.1kb2024-12-18 17:23:252024-12-18 17:23:26

Judging History

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

  • [2024-12-18 17:23:26]
  • 评测
  • 测评结果:AC
  • 用时:103ms
  • 内存:30700kb
  • [2024-12-18 17:23:25]
  • 提交

answer

#include<bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
const int maxn=2e6+10;
void chkmax(int &x,int y){ x=x>y?x:y; }
void chkmin(int &x,int y){ x=x<y?x:y; }
char s[maxn]; int n,m=0; vector<int> ans;
int r[maxn],vis[maxn],len[maxn]; char t[maxn];
void solve(){
	cin>>(s+1); n=strlen(s+1); ans.clear();
	if(n==1){ cout<<1<<endl; return ; }
	t[m=0]='#'; t[++m]='@';
	for(int i=1;i<=n;i++) t[++m]=s[i],t[++m]='@'; t[++m]='!';
	for(int i=1,R=0,c=0;i<m;i++){
		r[i]=i>R?1:min(r[2*c-i],R-i+1);
		while(t[i-r[i]]==t[i+r[i]]&&r[i]<m) r[i]++;
		if(i+r[i]-1>R) R=i+r[c=i]-1;
	}
	for(int i=1;i<=n;i++){ vis[i]=0; len[i]=r[i<<1]/2; }
	vis[n+1]=1;
	for(int i=n;i>=2;i--){
		if(i+len[i]-1==n) ans.pb(i),vis[i]=1; 
		else if(i==len[i]&&vis[i+len[i]-1]) ans.pb(i),vis[i]=1;
	}
	reverse(ans.begin(),ans.end());
	for(auto v:ans) cout<<v<<" "; cout<<endl;
}
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int T; cin>>T;
	while(T--) solve(); 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11732kb

input:

7
abcdcb
qwqwq
qaqaqqq
carnation
c
ab
aa

output:

4 6 
2 3 4 5 
6 7 
9 
1
2 
2 

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 103ms
memory: 30700kb

input:

5
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...

output:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 48ms
memory: 26468kb

input:

5
accabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbaccabbacca...

output:

1000000 
500005 500012 500019 500026 500033 500040 500047 500054 500061 500068 500075 500082 500089 500096 500103 500110 500117 500124 500131 500138 500145 500152 500159 500166 500173 500180 500187 500194 500201 500208 500215 500222 500229 500236 500243 500250 500257 500264 500271 500278 500285 5002...

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 41ms
memory: 25944kb

input:

5
wwcunkdbrnrbzqtgvzpnpyrpafjdnznmxpgkzlorbfsayoitnziexcuxhdaxeojdfrpfedyflshjgrewqmanowlybnvfdgkjxaqdfolqgsbpkfncunqimdinqdvujffihvonlzdrtfifmviglyrxdzktdfponuzurnhconwhuepgcxpnxgkafwvkenbrjalbpvfdkbmgidokadxzjjbphzblmccxeqytngyxhndrqrbtxauglwxtxzejbjgizhbmnclwrqojjrcguxnfvmaslhdpqlxruafjeqgvgwfppj...

output:

999995 
500500 501000 501500 502000 502500 503000 503500 504000 504500 505000 505500 506000 506500 507000 507500 508000 508500 509000 509500 510000 510500 511000 511500 512000 512500 513000 513500 514000 514500 515000 515500 516000 516500 517000 517500 518000 518500 519000 519500 520000 520500 52100...

result:

ok 5 lines