QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21578 | #2840. 绿绿与串串 | ha114514ha# | TL | 3ms | 13988kb | C++20 | 3.1kb | 2022-03-07 15:24:35 | 2022-05-08 03:39:34 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#include<ctime>
#include<random>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define bc(x) __builtin_popcount(x)
#define re register
#define il inline
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
// #pragma GCC optimize(3)
//#define int long long
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace IO_BUFF{
mt19937 rnd(time(0)^(ll)(new char));
int rend(int x){
return rnd()%x+1;
}
void rendom_shuffle(int *a,int len){
shuffle(a+1,a+len+1,rnd);
}
const int BS=(1<<24)+5;char Buffer[BS],*HD,*TL;
inline int gc(){
if(HD==TL) TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);
return (HD==TL)?EOF:*HD++;
}
inline int inn(){
int x,ch,s=1;while((ch=gc())<'0'||ch>'9')if(ch=='-')s=-1;x=ch^'0';
while((ch=gc())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');return x*s;
}
char ssss[19999999],tttt[20];int ssl,ttl;
inline int print(int x)
{
if(x<0)ssss[++ssl]='-',x=(-x);
if(!x) ssss[++ssl]='0';for(ttl=0;x;x/=10) tttt[++ttl]=char(x%10+'0');
for(;ttl;ttl--) ssss[++ssl]=tttt[ttl];return ssss[++ssl]='\n';
}
inline int Flush(){return fwrite(ssss+1,sizeof(char),ssl,stdout),ssl=0,0;}
int read(){
char c=getchar();int x=1;int s=0;
while(c<'0' || c>'9'){if(c=='-')x=-1;c=getchar();}
while(c>='0' && c<='9'){
s=s*10+c-'0';c=getchar();
}
return s*x;
}
}using namespace IO_BUFF;
/*namespace CFConTest{
const int mod=998244353;
inline int add(const int &x,const int &y){
return (x+y>=mod?x+y-mod:x+y);
}
inline int del(const int &x,const int &y){
return (x-y<0?x-y+mod:x-y);
}
int ksm(int x,int k){
int base=1;
while(k){
if(k&1)base=1ll*base*x%mod;
k>>=1;
x=1ll*x*x%mod;
}
return base;
}
};
using namespace CFConTest;*/
const int N=1e6+5;
int T,n,top,c[N*2],r[N*2];
char a[N*2];
char b[N*2];
int st[N*2],head;
int main(){
#ifdef newbiewzs
freopen("data.in","r",stdin);
#else
#endif
T=read();
while(T--){
scanf("%s",a+1);
n=strlen(a+1);
if(n==1){
cout<<"1"<<'\n';
continue;
}
top=0;
for(int i=1;i<=n;i++){
b[++top]='#';
b[++top]=a[i];
}
b[++top]='#';
int maxx=0,jl=0;
for(int i=1;i<=top;i++){
if(maxx>i){
r[i]=min(r[2*jl-i],maxx-i);
}
while(i-r[i]>1 && i+r[i]<top && b[i-r[i]-1]==b[i+r[i]+1])r[i]++;
if(i+r[i]>maxx){
maxx=i+r[i];
jl=i;
}
}
for(int i=1;i<=n;i++){
c[i]=(r[i*2]-1)/2;
}
for(int i=n;i>=2;i--){
int u=i;
bool flag=1;
while(u+(u-1)<n){
if(c[u]!=u-1)flag=0;
u=u+1;
}
if(u+c[u]<n)flag=0;
if(flag)st[++head]=i;
}
while(head){
cout<<st[head--]<<" ";
}
cout<<'\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 13988kb
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
Time Limit Exceeded
input:
5 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...