QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21552 | #2840. 绿绿与串串 | hy_zheng_zai_nei_juan# | WA | 237ms | 20412kb | C++20 | 2.0kb | 2022-03-07 14:59:13 | 2022-05-08 03:37:46 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
#define BUF_SIZE 100000
bool IOerror=0;
inline char nc()
{
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if (p1==pend){
p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
if (pend==p1){IOerror=1;return -1;}
}
return *p1++;
}
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
inline ll read()
{
bool sign=0; char ch=nc();ll x=0;
for (;blank(ch);ch=nc());
if (IOerror)return 0;
if (ch=='-')sign=1,ch=nc();
for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
if (sign)x=-x;
return x;
}
#undef BUF_SIZE
};
using namespace fastIO;
char s[1000010];
int d[1000010],nxt[1000010];
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int T=qr;
int n;
while(T--)
{
n=0;
char ch=nc();
for(;isalpha(ch);ch=nc())s[++n]=ch;
if(n==1)
{
cout<<1<<'\n';
continue;
}
s[0]='~';
int r=0,p=0;
for(int i=1;i<=n;i++)
{
if(i<r)d[i]=min(d[p*2-i],d[p]+p-i);
else d[i]=1;
while(s[i-d[i]]==s[i+d[i]])d[i]++;
if(i+d[i]>r)r=i+d[i],p=i;
}
int j=0;nxt[1]=0;
for(int i=2;i<=n;i++)
{
while(s[i]!=s[j+1]&&j)j=nxt[j];
if(s[i]==s[j+1])j++;
nxt[i]=j;
}
// for(int i=1;i<=n;i++)cout<<nxt[i]<<'\n';
int now=nxt[n];
while(now)
{
int len=n-now;
if(len>1&&d[len/2+1]>=len/2+1)cout<<len/2+1<<' ';
now=nxt[now];
}
for(int i=n/2+1+n%2;i<=n;i++)if(d[i]>=n-i+1)cout<<i<<' ';cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 7692kb
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: -100
Wrong Answer
time: 237ms
memory: 20412kb
input:
5 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 53 54 5...
result:
wrong answer 1st lines differ - expected: '2 3 4 5 6 7 8 9 10 11 12 13 14...96 999997 999998 999999 1000000', found: '2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 ...6 999997 999998 999999 1000000 '