QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21555#2840. 绿绿与串串hy_zheng_zai_nei_juan#AC ✓204ms28104kbC++202.1kb2022-03-07 15:00:382022-05-08 03:37:55

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:37:55]
  • 评测
  • 测评结果:AC
  • 用时:204ms
  • 内存:28104kb
  • [2022-03-07 15:00:38]
  • 提交

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],vis[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&&!vis[len/2+1])vis[len/2+1]=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';
		for(int i=1;i<=n;i++)vis[i]=0;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 204ms
memory: 28104kb

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: 61ms
memory: 28080kb

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: 40ms
memory: 28084kb

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