QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#276820 | #2840. 绿绿与串串 | SoyTony | AC ✓ | 128ms | 15504kb | C++14 | 1.1kb | 2023-12-06 11:13:14 | 2023-12-06 11:13:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+10;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
int t;
int n;
char s[maxn];
int d[maxn];
bool mark[maxn];
inline void Manacher(){
memset(d,0,sizeof(d));
for(int i=1,l=0,r=-1;i<=n;++i){
int j=l+r-i,k;
if(i>r) k=1;
else k=min(d[j],r-i+1);
while(i-k+1>=1&&i+k-1<=2*n-1&&(s[i-k+1]==s[i+k-1]||s[i+k-1]=='?')) d[i]=k++;
if(i+d[i]-1>r) l=i-d[i]+1,r=i+d[i]-1;
}
}
int main(){
t=read();
while(t--){
scanf("%s",s+1);
n=strlen(s+1);
for(int i=n+1;i<=2*n-1;++i) s[i]='?';
Manacher();
for(int i=1;i<=n;++i) mark[i]=0;
for(int i=n;i>=1;--i){
if(d[i]!=i) continue;
if(i+d[i]-1>=n) mark[i]=1;
else if(mark[i+d[i]-1]) mark[i]=1;
}
for(int i=1;i<=n;++i){
if(mark[i]) printf("%d ",i);
}
printf("\n");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 14032kb
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: 128ms
memory: 15296kb
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: 35ms
memory: 15504kb
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: 46ms
memory: 15468kb
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