QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53540 | #385. 游戏 | not_so_organic | 100 ✓ | 14ms | 8288kb | C++11 | 2.8kb | 2022-10-05 13:17:00 | 2022-10-05 13:17:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double louble;
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}
template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return b<a?a:b;}
namespace ae86{
const int bufl = 1<<15;
char buf[bufl],*s=buf,*t=buf;
inline int fetch(){
if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
return *s++;
}
inline int ty(){
int a=0,b=1,c=fetch();
while(!isdigit(c))b^=c=='-',c=fetch();
while(isdigit(c))a=a*10+c-48,c=fetch();
return b?a:-a;
}
inline int tc(){
int c=fetch();
while(c<=32 && c!=EOF)c=fetch();
return c;
}
template<typename T> inline int ts(T s[]){
int a=0,c=fetch();
while(c<=32 && c!=EOF)c=fetch();
while(c>32 && c!=EOF)s[a++]=c,c=fetch();
return a;
}
}
using ae86::ty;
using ae86::tc;
using ae86::ts;
const int _ = 100007 , X = 9 , M = 200007 , N = 200007 , E = 1333333;
int to[E],ne[E],he[N]={0},ecnt=1;
void adde(int a,int b){to[++ecnt]=b,ne[ecnt]=he[a],he[a]=ecnt;}
int n,nn,bel[N]={0},stk[N],top;
int m,xcnt,xloc[X],lims[M][4],temp[N];
char s[_];
inline int loca(int x,int c){
if(s[x]-'a'==c)return 0;
return x+x-(c==(s[x]=='a'?1:0));
}
inline int tran(int x){return (x&1)?(x+1):(x-1);}
int dfs(int x){
int xx=(x+1)/2;
stk[++top]=xx,bel[xx]=(x+1)&1;
for(int i=he[x];i;i=ne[i]){
int b=to[i],bb=(b+1)/2;
if(bel[bb]<0){if(!dfs(b))return 0;}
else if(bel[bb]!=((b+1)&1))return 0;
}
return 1;
}
void finder(){
ecnt=1;
for(int i=1;i<=nn;i++)he[i]=0,bel[i]=-1;
for(int i=1;i<=m;i++){
int a=lims[i][0],b=lims[i][2],tara=lims[i][1],tarb=lims[i][3];
if(tara==s[a]-'a')continue;
if(tarb==s[b]-'a'){adde(loca(a,tara),tran(loca(a,tara)));continue;}
adde(loca(a,tara),loca(b,tarb));
adde(tran(loca(b,tarb)),tran(loca(a,tara)));
}
for(int i=1;i<=n;i++)temp[i]=i;
random_shuffle(temp+1,temp+n+1);
for(int i=1;i<=n;i++){
int a=temp[i];
if(bel[a]>=0)continue;
top=0;
if(dfs(a+a-1))continue;
for(int j=1;j<=top;j++)bel[stk[j]]=-1;
top=0;
if(!dfs(a+a))return;
}
for(int i=1;i<=n;i++){
if(s[i]=='a')putchar('B'+bel[i]);
if(s[i]=='b')putchar('A'+bel[i]+bel[i]);
if(s[i]=='c')putchar('A'+bel[i]);
}
puts("");
exit(0);
}
#define pick(a,b) (((a)>>(b))&1)
int states[261]={0},statecnt=0;
int main(){
srand(time(0));
n=ty(),xcnt=ty(),ts(s+1),m=ty(),nn=n+n;
for(int i=1;i<=m;i++)
lims[i][0]=ty(),lims[i][1]=tc()-'A',lims[i][2]=ty(),lims[i][3]=tc()-'A';
for(int i=1,a=0;i<=n;i++)if(s[i]=='x')xloc[++a]=i;
for(int i=0;i<(1<<xcnt);i++)states[statecnt++]=i;
random_shuffle(states,states+statecnt);
for(int i=0;i<statecnt;i++){
for(int j=1;j<=xcnt;j++)s[xloc[j]]='a'+pick(states[i],j-1);
finder();
}
puts("-1");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 2ms
memory: 3604kb
input:
2 0 ba 4 2 C 2 C 1 B 1 A 2 C 1 C 2 B 1 A
output:
AB
result:
ok
Test #2:
score: 5
Accepted
time: 2ms
memory: 3676kb
input:
2 1 xc 4 2 B 2 A 2 A 1 C 2 C 2 C 2 B 1 A
output:
CA
result:
ok
Test #3:
score: 5
Accepted
time: 2ms
memory: 3580kb
input:
5 0 bcbbb 10 1 B 1 C 3 C 1 C 2 B 5 A 1 C 1 C 2 A 5 A 3 A 1 C 2 B 1 C 3 A 1 B 1 B 4 B 1 B 4 A
output:
CACAA
result:
ok
Test #4:
score: 5
Accepted
time: 2ms
memory: 3684kb
input:
5 2 acxax 10 2 B 1 A 3 C 4 C 4 B 3 C 5 B 3 B 2 B 3 A 3 A 2 A 5 B 1 C 3 B 1 B 2 C 4 C 4 B 2 A
output:
BABCC
result:
ok
Test #5:
score: 5
Accepted
time: 1ms
memory: 3612kb
input:
10 0 abbbacabab 20 5 A 3 B 9 A 4 C 4 C 10 A 8 B 3 C 6 C 10 A 5 A 9 C 8 A 2 C 5 A 8 B 10 A 10 A 5 B 4 B 6 C 10 C 2 C 4 B 5 C 7 B 5 A 10 B 3 A 7 B 6 B 4 B 3 C 8 B 1 B 3 B 4 B 3 C 8 A 2 A
output:
CAAACABCBA
result:
ok
Test #6:
score: 5
Accepted
time: 2ms
memory: 3680kb
input:
10 4 xbbxccxbxc 20 2 A 10 A 10 C 4 C 1 A 5 A 2 A 2 A 9 C 2 B 2 B 6 C 2 B 9 A 3 B 2 B 4 B 9 A 4 A 5 A 2 B 10 A 3 B 6 A 8 C 8 B 3 B 3 B 3 B 7 A 9 C 6 C 6 A 8 C 4 A 10 A 2 C 4 B 9 C 7 B
output:
BAABABAAAA
result:
ok
Test #7:
score: 5
Accepted
time: 2ms
memory: 3608kb
input:
20 0 cccccccccccccccccccc 40 15 A 13 C 6 B 19 A 3 C 5 B 20 C 6 C 1 C 10 B 10 C 7 C 13 B 17 A 1 A 3 A 15 A 15 A 13 B 18 B 14 A 4 A 1 A 3 A 4 C 14 A 1 B 6 B 2 B 8 B 3 C 15 A 1 B 17 B 6 A 17 A 12 B 6 A 8 B 1 C 15 B 1 B 18 C 3 C 2 A 8 A 14 B 6 B 15 C 9 A 17 A 10 C 15 A 7 A 8 C 6 A 18 B 12 C 14 C 10 A 9 ...
output:
BAABABAAAAAAABBABAAA
result:
ok
Test #8:
score: 5
Accepted
time: 2ms
memory: 3584kb
input:
20 0 caaabacbacabbcacabaa 40 7 B 19 C 15 A 12 B 2 A 12 C 20 B 1 B 4 B 4 A 4 A 18 C 4 A 3 A 15 C 12 A 2 C 12 C 15 B 6 A 10 A 12 B 13 C 7 C 2 C 6 C 16 C 18 A 12 B 17 B 8 C 11 B 14 B 11 A 8 B 8 C 19 A 7 C 6 C 3 C 1 C 4 B 1 C 5 A 13 B 4 C 14 B 9 A 11 A 9 C 8 B 16 B 2 C 20 A 2 A 14 C 10 B 13 A 17 A 19 B ...
output:
BBBCABAABBBAAACABACC
result:
ok
Test #9:
score: 5
Accepted
time: 2ms
memory: 3720kb
input:
20 8 xccccccxxcxcccccxxxx 40 12 A 18 C 16 C 14 C 10 B 2 C 1 A 10 A 11 A 13 B 15 A 6 B 8 A 14 B 16 A 15 B 4 C 5 C 19 C 4 B 17 C 11 A 12 B 14 C 18 B 17 B 14 A 11 C 16 C 6 C 13 C 20 B 16 B 13 C 8 B 7 C 9 B 16 B 1 B 18 A 7 B 6 A 8 B 19 A 16 C 17 A 8 A 6 A 10 A 14 B 20 C 6 B 13 C 5 A 14 A 3 C 20 B 14 C 4...
output:
CAABBBACAABAABBAACCC
result:
ok
Test #10:
score: 5
Accepted
time: 0ms
memory: 3604kb
input:
20 8 cbabxccxxxxxbaxxaaac 40 8 C 7 C 19 C 12 C 19 A 6 B 6 C 20 B 12 B 18 B 6 A 10 B 11 B 14 B 20 C 18 B 4 A 7 C 18 A 1 A 18 C 14 A 5 B 13 B 3 B 7 A 8 C 1 C 14 B 4 C 13 A 1 A 7 A 19 A 11 B 16 A 9 A 7 A 11 C 4 B 10 B 1 A 1 A 1 B 5 A 8 C 20 C 13 A 3 B 11 B 18 C 13 A 11 A 20 B 3 A 16 C 17 A 5 C 6 C 17 B...
output:
BCCCCBBACCAACBABCBBB
result:
ok
Test #11:
score: 5
Accepted
time: 2ms
memory: 3616kb
input:
100 0 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 200 62 A 60 B 22 A 46 A 87 A 67 B 29 A 43 A 64 B 28 B 83 B 16 A 50 A 64 B 48 A 95 A 28 B 90 A 5 A 12 A 23 B 86 A 62 A 81 B 64 B 9 B 5 A 10 B 89 B 18 B 69 B 62 A 63 A 55 A 28 B 92 B 49 A 43 A 71...
output:
BABAAAABBBAAAAAABBAABAAABBABAAAABAABBAAABAAABAAAABBABBAABABBBAAABABABAABABABBAABBABABAAABABBAAAAABBA
result:
ok
Test #12:
score: 5
Accepted
time: 2ms
memory: 3600kb
input:
100 0 cabaabbaaabacbaccbccacbcaaccccbbcccbabbaaaacccbaaabbcaaabaabcaabcbbcaabaabaaccacbaabbacbbacaaabcbbca 200 94 C 31 A 29 B 48 B 89 C 52 A 49 B 11 C 10 C 66 C 90 B 49 B 80 B 19 B 26 B 54 B 20 B 65 B 52 A 80 B 51 A 33 A 94 C 6 C 18 C 60 A 87 B 45 B 12 C 7 A 26 B 57 A 89 C 54 B 4 B 29 B 39 A 67 C 22...
output:
ABCCBACCBBABAABAAAAABAABBCBAAACCBBBCCACBCCBAAACCCBCCACBBABBCABBCAAABBCABBCBBAABAACCACBAAACABBBABCCBB
result:
ok
Test #13:
score: 5
Accepted
time: 0ms
memory: 3484kb
input:
100 8 cccccxccccccxccccxccccccxcccccccxccccxccccccccccxccccccccccccccccccccccccccccccccccccccxcccccccccccc 200 38 A 13 B 60 A 18 B 36 B 76 B 95 A 7 B 25 A 58 B 53 A 27 A 21 A 78 A 15 A 48 A 52 B 59 A 65 B 68 A 72 A 47 A 95 A 48 A 96 A 67 A 96 A 47 A 46 B 96 A 79 B 36 B 60 A 90 B 5 B 95 A 17 A 99 A 2...
output:
AABBAAABAABAABBABABABAAABAAABBAAABAAACABBBAABABAABBABAABBABBABAAAAABAAABBAAABBAAAABABBBBBABBAABBAABA
result:
ok
Test #14:
score: 5
Accepted
time: 0ms
memory: 3720kb
input:
100 8 ccbbcaacxxbcxacbcaabxaaccbxcaabacbccaccacbcacxcacccccccbcacbaabbabaacbbababaxabcccacaxabaaacabbcbccc 200 41 A 8 A 75 C 86 C 93 B 26 A 83 C 55 A 49 B 69 B 50 B 54 B 41 A 85 C 43 B 4 A 75 C 95 A 2 A 54 B 14 C 3 A 18 C 79 A 5 B 8 A 61 C 90 B 48 C 96 B 84 A 40 C 55 A 58 B 77 A 47 A 36 A 60 A 2 A 8...
output:
BBCCABBBAACBCBBAABBCBBBABCAABCCBAAABCAABBCABAAABAAAAAABCACACBBCCBCBBACCBABACCBCBBABBBBCCCBBACCCAABAA
result:
ok
Test #15:
score: 5
Accepted
time: 1ms
memory: 4056kb
input:
5000 0 ccbbbbacccabaacccbccaabcbcbabcabbbcbccacbbcccbccbcacbacaacbccaaacbcaabbacacabaaaccacbaccbbbccaabbbcabcbabaaccbaacacbaaccbacaccababcabbbccacbcabaabababaacccbbababbaabbbaccbabaabbbcbacbbbbbacbbabcabacbbcbaaaaaaccbaaaabccccacaaacabaabaccacabbaacaaccbbcbcaaaccbbccbccbccaacbccacbcbbacaaaaabbacbaab...
output:
-1
result:
ok
Test #16:
score: 5
Accepted
time: 3ms
memory: 4160kb
input:
5000 8 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
ABBAABABABABABBAABABABABBABAABBAABABBABABAABABABBAABABBAABABABABBABAABBAABABBABABAABABABBABABAABABABBABABAABABBAABBABABAABABBABABAABABBABABABABAABABBABABAABABABBAABABBAABBABAABABBABAABABBABABAABABBABAABBAABBAABABABABABBAABABABABABBABABAABBABABABAABBAABBAABABABBAABBABAABABBABAABBAABABBABABAABBABABABA...
result:
ok
Test #17:
score: 5
Accepted
time: 1ms
memory: 4072kb
input:
5000 8 abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab...
output:
BCABCABCACABBCABCABCACABCABCABBCACABBCABCABCACABCABCABBCACABBCABCACABBCABCABCACABCABBCABCACABCABBCABCABCACABBCABCABCABCABCABCACABBCABCABCACABBCABCABCACABBCABCABCABCABCABCABCABCABCACABCABBCABCABCABCACABBCABCABCABCACABBCACABBCACABBCABCABCABCACABBCABCABCABCACABBCACABCABCABBCABCABCABCABCABCACABBCACABBCA...
result:
ok
Test #18:
score: 5
Accepted
time: 8ms
memory: 6688kb
input:
50000 0 baabcbbaacbbabababbbabcbcbbcabccaaacccbaaabcabccccbbaacbaaacbcacbabbbbabccabaabbcabacacaaabbaccccbcacaaacbcaacbcacbbabbcbabccbbcacbacbbccacbcabcbcbcacbaacaaccbcbabaaacbcbbccbcacacccbbcabcaccacaaaaaacbcaccaacbbbaaaccaaccaaacbacbaaccaabccaababbabaaaaacbaabaccabacbcbabbcbaabacbbacbbaaabababccac...
output:
ABBAAAABBAAABABABAAABAAAAAAABAAABBBAAAABBBAABAAAAAAABBAABBBAAABAABAAAABAAABABBAAABABABABBBAABAAAAAABABBBAAABBAAABAAABAAAABAAAAAABAABAAAAABAAABAAAAAABAABBABBAAAAABABBBAAAAAAAAABABAAAAAABAABAABABBBBBBAAABAABBAAAABBBAABBAABBBAABAABBAABBAAABBABAABABBBBBAABBABAABABAAAABAAAABBABAAABAAABBBABABAAABABBAABAAA...
result:
ok
Test #19:
score: 5
Accepted
time: 14ms
memory: 8288kb
input:
50000 8 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
BABABABABABABAABABBABABABAABBAABABBAABBAABABBAABABBABAABBAABABBAABABBABAABABABBAABBAABBAABBAABBABABAABABBAABBABABABABAABABABBABABAABABBAABABABBABABAABABBAABABABBABAABABABABABABBABABABAABBAABABABBABABAABABBABAABBAABBAABABABBAABABBAABABBAABABABBABAABBAABABABBAABABABBAABABBABABAABABABABABABBABAABABABBA...
result:
ok
Test #20:
score: 5
Accepted
time: 5ms
memory: 8280kb
input:
50000 8 abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca...
output:
CABBCACABBCABCACABCABBCABCABCABCABCABCABCABCACABBCABCABCABCABCACABBCABCABCACABBCABCABCACABCABBCACABBCABCACABCABBCABCABCABCABCACABBCABCACABBCABCABCABCABCACABBCABCACABCABBCACABBCABCACABBCABCACABBCABCABCACABCABBCACABBCABCACABBCACABBCACABCABCABBCABCABCACABBCABCABCACABBCACABCABBCABCACABBCACABCABCABBCABCA...
result:
ok
Extra Test:
score: 0
Extra Test Passed