社区讨论
关于 G
P1421小玉买文具参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @miagkvg5
- 此快照首次捕获于
- 2025/11/22 23:43 4 个月前
- 此快照最后确认于
- 2025/11/23 12:41 4 个月前
为啥三个小样例一直 T 啊,其它点都没问题 /yiw
CPP#include<bits/stdc++.h>
#define int long long
#ifdef __linux__
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?0:*p1++)
#define pc putchar_unlocked
#else
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?0:*p1++)
#define pc _putchar_nolock
#endif
using namespace std;
char buf[1<<21],*p1,*p2,*top, buffer[1<<21];
inline bool blank(const char x) {return !(x^32)||!(x^10)||!(x^13)||!(x^9);}template<typename Tp> inline void read(Tp &x) {x=0; register bool z=true; register char a=gc(); for(;!isdigit(a);a=gc()) if(a=='-') z=false; for(;isdigit(a);a=gc()) x=(x<<1)+(x<<3)+(a^48); x=(z?x:~x+1);}inline void read(double &x) {x=0.0; register bool z=true; register double y=0.1; register char a=gc(); for(;!isdigit(a);a=gc()) if(a=='-') z=false; for(;isdigit(a);a=gc()) x=x*10+(a^48); if(a!='.') return x=z?x:-x,void(); for(a=gc();isdigit(a);a=gc(),y/=10) x+=y*(a^48); x=(z?x:-x);}inline void read(char &x) {for(x=gc();blank(x)&&(x^-1);x=gc());}inline void read(char *x) {register char a=gc(); for(;blank(a)&&(a^-1);a=gc()); for(;!blank(a)&&(a^-1);a=gc()) *x++=a; *x=0;}inline void read(string &x) {x=""; register char a=gc(); for(;blank(a)&&(a^-1);a=gc()); for(;!blank(a)&&(a^-1);a=gc()) x+=a;}template<typename T,typename ...Tp> inline void read(T &x,Tp &...y) {read(x),read(y...);}template<typename Tp> inline void write(Tp x) {if(!x) return pc(48),void(); if(x<0) pc('-'),x=~x+1; register int len=0; register char tmp[64]; for(;x;x/=10) tmp[++len]=x%10+48; while(len) pc(tmp[len--]);}inline void write(const double x) {register int a=6; register double b=x,c=b; if(b<0) pc('-'),b=-b,c=-c; register double y=5*powl(10,-a-1); b+=y,c+=y; register int len=0; register char tmp[64]; if(b<1) pc(48); else for(;b>=1;b/=10) tmp[++len]=floor(b)-floor(b/10)*10+48; while(len) pc(tmp[len--]); pc('.'); for(c*=10;a;a--,c*=10) pc(floor(c)-floor(c/10)*10+48);}template<typename T>inline void write(const pair<T,double>x) {register int a=x.first; if(a<7) {register double b=x.second,c=b; if(b<0) pc('-'),b=-b,c=-c; register double y=5*powl(10,-a-1); b+=y,c+=y; register int len=0; register char tmp[64]; if(b<1) pc(48); else for(;b>=1;b/=10) tmp[++len]=floor(b)-floor(b/10)*10+48; while(len) pc(tmp[len--]); a&&(pc('.')); for(c*=10;a;a--,c*=10) pc(floor(c)-floor(c/10)*10+48);} else cout<<fixed<<setprecision(a)<<x.second;}inline void write(const char x) {pc(x);}inline void write(const bool x) {pc(x?49:48);}inline void write(char *x) {fputs(x,stdout);}inline void write(const char *x) {fputs(x,stdout);}inline void write(const string &x) {fputs(x.c_str(),stdout);}template<typename T,typename ...Tp> inline void write(T x,Tp ...y) {write(x),write(y...);}
struct node{
struct State{
int len,link,next[26];
State():len(0),link(-1){
memset(next,-1,sizeof next);
}
};
vector<State>st;
int last;
node(int S){
st.reserve(S*4);
st.push_back(State());
last=0;
}
void extend(int c){
int cur=st.size();
st.push_back(State());
st[cur].len=st[last].len+1;
int p=last;
while(p!=-1&&st[p].next[c]==-1){
st[p].next[c]=cur;
p=st[p].link;
}
if(p==-1)st[cur].link=0;
else{
int q=st[p].next[c];
if(st[p].len+1==st[q].len)st[cur].link=q;
else{
int cl=st.size();
st.push_back(st[q]);
st[cl].len=st[p].len+1;
while(p!=-1&&st[p].next[c]==q){
st[p].next[c]=cl;
p=st[p].link;
}
st[q].link=st[cur].link=cl;
}
}
last=cur;
}
};
int T;
signed main(){
read(T);
while(T--){
string S;
read(S);
int n=S.size();
node sam(n);
for(char ch:S)sam.extend(ch-'a');
int cnt=sam.st.size();
vector<int>g[200005];
for(int i=0;i<cnt;i++){
if(sam.st[i].len<=n){
g[sam.st[i].len].push_back(i);
}
}
vector<int>sg(cnt,0);
bool mex[30];
for(int len=n;len>=0;len--){
for(int u:g[len]){
memset(mex,0,sizeof mex);
for(int c=0;c<26;c++){
int v=sam.st[u].next[c];
if(v!=-1){
int s=sg[v];
if(s<26)mex[s]=1;
}
}
int s=0;
while(s<26&&mex[s])s++;
sg[u]=s;
}
}
if(sg[0]!=0)write("Alice\n");
else write("Bob\n");
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...