QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102813 | #5161. Last Guess | w4p3r# | RE | 6ms | 9828kb | C++20 | 3.4kb | 2023-05-03 18:07:20 | 2023-05-03 18:07:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=10010,M=1000010;
const int inf=0x3f3f3f3f;
int head[N],edge[M],ver[M],nxt[M],d[N];
int n,m,maxflow=0,tot=1,s=N-1,t=N-2,ss=N-3,tt=N-4;
void add_edge(int x,int y,int z)
{
ver[++tot]=y,edge[tot]=z,nxt[tot]=head[x],head[x]=tot;
}
void add(int x,int y,int z)
{
if(z) add_edge(x,y,z),add_edge(y,x,0);
}
void add(int x,int y,int l,int r)
{
add(ss,y,l),add(x,tt,l),add(x,y,r-l);
}
queue<int> q;
bool bfs(int S,int T)
{
while(q.size()) q.pop();
memset(d,0,sizeof(d));
q.push(S),d[S]=1;
while(q.size())
{
int x=q.front(); q.pop();
for(int i=head[x];i;i=nxt[i])
{
int y=ver[i];
if(edge[i]&&!d[y]) d[y]=d[x]+1,q.push(y);
}
}
return d[T];
}
int dinic(int x,int flow,int T)
{
if(x==T||!flow) return flow;
int res=flow,k;
for(int i=head[x];i&&res;i=nxt[i])
{
int y=ver[i];
if(edge[i]&&d[y]==d[x]+1)
{
k=dinic(y,min(edge[i],res),T);
if(!k) d[y]=0;
res-=k,edge[i]-=k,edge[i^1]+=k;
}
}
return flow-res;
}
int g,l;
int minn[33],maxn[33],maxG[33];
int cnt[33],cntG[33];
bool black[33];
bool ban[33][510];
char st[N],col[N];
char ans[N];
int main()
{
scanf("%d%d",&g,&l);
for(int i=0;i<26;i++) minn[i]=0,maxn[i]=l;
memset(ban,false,sizeof(ban));
for(int i=1;i<g;i++)
{
for(int j=0;j<26;j++) cnt[j]=cntG[j]=black[j]=0;
scanf("%s%s",st+1,col+1);
// cerr<<st+1<<" "<<col+1<<"\n";
for(int j=1;j<=l;j++)
{
if(col[j]=='G') ans[j]=st[j],cnt[st[j]-'a']++,cntG[st[j]-'a']++;
if(col[j]=='Y') cnt[st[j]-'a']++,ban[st[j]-'a'][j]=true;
if(col[j]=='B') black[st[j]-'a']=true,ban[st[j]-'a'][j]=true;
}
for(int j=0;j<26;j++)
{
maxG[j]=max(maxG[j],cntG[j]);
minn[j]=max(minn[j],cnt[j]);
if(black[j]) maxn[j]=min(maxn[j],cnt[j]);
}
}
/*
cerr<<"minn: \n";
for(int i=0;i<26;i++) cerr<<minn[i]<<" ";
cerr<<"\n";
cerr<<"maxn: \n";
for(int i=0;i<26;i++) cerr<<maxn[i]<<" ";
cerr<<"\n";
cerr<<"maxG: \n";
for(int i=0;i<26;i++) cerr<<maxG[i]<<" ";
cerr<<"\n";
cerr<<"ban: \n";
for(int i=0;i<26;i++,cerr<<"\n")
{
cerr<<(char)(i+'a')<<": ";
for(int j=1;j<=l;j++) cerr<<ban[i][j];
}
cerr<<"\n";
//*/
for(int i=0;i<26;i++) add(s,i,minn[i]-maxG[i],maxn[i]-maxG[i]);
for(int i=1;i<=l;i++)
{
if('a'<=ans[i]&&ans[i]<='z') continue;
add(26+i,t,1,1);
for(int ch=0;ch<26;ch++)
if(!ban[ch][i]) add(ch,26+i,0,1);
}
/*
for(int x=0;x<26;x++)
{
cerr<<(char)(x+'a')<<": \n";
for(int i=head[x];i;i=nxt[i])
{
int y=ver[i];
if(26+1<=y&&y<=26+l) cerr<<(char)(x+'a')<<" "<<y-26<<"\n";
}
}
//*/
/*
cerr<<"ss = "<<ss<<", tt = "<<tt<<"\n";
for(int x=0;x<N;x++)
{
for(int i=head[x];i;i=nxt[i])
{
int y=ver[i],z=edge[i];
if(z) cerr<<x<<" "<<y<<" "<<z<<"\n";
}
}
//*/
add(t,s,0,inf);
int flow=0;
while(bfs(ss,tt)) while(flow=dinic(ss,inf,tt)) maxflow+=flow;
for(int i=head[ss];i;i=nxt[i]) assert(!edge[i]);
// for(int i=head[ss];i;i=nxt[i]) edge[i]=edge[i^1]=0;
// for(int i=head[tt];i;i=nxt[i]) edge[i]=edge[i^1]=0;
// for(int i=head[t];i;i=nxt[i]) if(ver[i]==s) edge[i]=edge[i^1]=0;
edge[tot]=edge[tot-1]=0;
while(bfs(s,t)) while(flow=dinic(s,inf,t)) maxflow+=flow;
for(int i=0;i<26;i++)
{
for(int j=head[i];j;j=nxt[j])
{
int y=ver[j];
if(26+1<=y&&y<=26+l&&!edge[j]) ans[y-26]=i+'a';
}
}
for(int i=1;i<=l;i++) putchar(ans[i]);
putchar('\n');
// assert(maxflow+totG==l);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7704kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 7628kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabzczzzbdde
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 7708kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz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qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqq...
output:
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...
result:
ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 9828kb
input:
22 500 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...
result:
ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 9652kb
input:
30 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
vajlabmpqyavasaaravu
result:
ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
31 20 azzzzzzzzzzzzzzzzzzz GBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BYBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBYBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBGBBBBBBBBBBBBB ...
output:
ayyduiasiaafbuqvayya
result:
ok
Test #9:
score: 0
Accepted
time: 3ms
memory: 7704kb
input:
38 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBGBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
sawaakoaaaeaoaahaaal
result:
ok
Test #10:
score: 0
Accepted
time: 6ms
memory: 7748kb
input:
25 500 eppppsppppppappppapppaswppspwppeupppwpwppppwppspppppppapppppspppappwpppppspspuppppppppppupwppeppppppppuppppusppspppppppwppppppppspeppppppppppepspppeppuppppwpppppppppppppwpppppppwppupppppspppppppppppppupeppppppppsppppeppaeppppppppppppppppppappppppppppppppppsppwppuappppepupuapppeppppppapppppppp...
output:
vayjogcjsnarhzfrshqbxhgirsgmitjvlabdikinenuizmgwwuqtzohxzeudgtmnhsaiacratgwgjljtkyetowdwlaibdvksccbsonlmrdjlgbngconrstmidytrdknwgjvyxzueqskrnvqgzmtvaelfxubiaqctbexjeftotinkqfsusinolqbsxjgcrqwkerywwmyylevubemsnzagqjtuvcuhvrbcnfcxznfymkquskbhffkcxrezezkemfyfgfzirxlhanfbvrldlhfcavqzzcbyhycwtknftnxhomqg...
result:
ok
Test #11:
score: 0
Accepted
time: 3ms
memory: 7760kb
input:
25 500 smxeetdiacxotgkpibsieraggqfjdbjxykzpiinrjxkmcczngkgpidtnacrzonzmrjsyfaiptigawddifgqxiiqibyymxvzncvifqsyfxmeodqwvwgqegpizkzfvsyywomkaviwjcasacijfbpjibvsroitinpfddjzcdkmxeisynrzipizmoyveveqwsfaqixobgrkstwtdtcfbwrvyvrgwdcmjozmitwcfitpzqdnikqbcpzyerwwigzdiczfmagmvacqxwbbiiiqrgxwvprvicjdsajinpmrrn...
output:
lxrggumnthrcukqbzoljgstkkayvmovrpqfbjjwsvrqxhhfwkqkbnmuwthsfcwfxsvlpytjbuzktdmmnykarnnanoppxrefwhejyalpyrxgcmadedkagkbnfqfyelppdcxqtendvhtlthnvyobvzoelscnuzwbymmvfhmqxrgnlpwsfjbjfxcpegegadlytajrcoksqludumuhyodsepeskdmhxvcfxjudhyzubfamwnqaohbfpgsddzkfmjhfyxtkxethardoojjzaskrdebsenhvmltvzwbxsswengqqwz...
result:
ok
Test #12:
score: 0
Accepted
time: 3ms
memory: 9708kb
input:
25 500 zzzzzzzzzzezzzzzyzzzyfzzzzzyzfzzzzzuzzzzzzzzyezezzzyzzzzzzzzzzzzzzzuzzzzzzzzfzzzzzzzyzzezfzzzzzzzzzzzzzzzzzzzzzzzfzzzzzzzzzzzzzzuzzzzzzzzzzzzzzzzzzzzuzzzzzzzzzzzyzzzzuzzzzzzzyyzzzzzzzzzzzzzzzzzfzzzzzzzzzzyzzzzyzzzzzzeezzzzzzzzzzyzzzzzzzyzezzzfefzuzzzzzzzzzzzzzuzfzzzzzzezzzfzzzzzzzzzzyuezzfzzz...
output:
qjtwjfaynbvccrdxmkyemidubqxmbidthnhseryxlaeymvbvdqgmjplbtulcjwhffjcsftewuqbxixoaeklqmfcvjiyeuthdcnfrqlwcoynrwjtxyinarlkxyfwkcjwxsqbcldqgnhuohjjbalwyasdpgxqdrbenwmyonrsplnurofmmjjfkxwoqabotkkoatikpndnkqcqxmlpggmanbphuvvttrwehopqgmkreelbdmyvrhgivicskkpqgklfpyytlsxixrlogyvqanirnpjbxexfdmsvgfiepdgrsdfgd...
result:
ok
Test #13:
score: 0
Accepted
time: 1ms
memory: 7720kb
input:
26 500 ffafffffafffffffffffffaaffaffffffffffffffffffffffffafffaffafffffffafffffffffffffffffffffffafaffffffffffafffffafffffffffafaffffffffffffffffffffaffffffffffffffffaffaffffffffffffffaffffffffffafffffafffaaffffffafafffafffffffffffffffaaffffffafffffffffffafffffffffffafffffafffffffaffffffffffafafffff...
output:
jlfbhgclfgttbbjhnbeionffhnfhcvbntvnxbonioebgbbwobonfobtfnofjtwbtbpfnjtbbgwphwpgxgjcbvtnothftfwbhhpbcpjifdhjwwfhgdijtwdifhfponbphownknommrhrkojflkjklplbekwedltcfoefidwgchwiojoenkfnjlitodlohqpluwhqcusfgumbuhkqifumrqrrcdskehgmktsttqfwnsuwcqujjetdpkpbtqcweuhrupxsrfrtxhkqryirsusgtjplplipmrftgcutxivpqggci...
result:
ok
Test #14:
score: 0
Accepted
time: 1ms
memory: 7632kb
input:
26 500 eeeeeeeeeeleleeeleeleelleelellelleeeleeeeeeeeeeeeeeeeeeeleeeeeeeleeleeeeelelleeelleeeleeeeeeeeeeeeeeeeeeleeeeeeeleeeeeellleeeeeeleleeeeeeleeeleeeeeeeeeeeeeeleeeeleeeeeeeeeeeeeellleleeeeeeeeeeelleleeeeeleleeleleeeeeeeeeeleeleeelelelleeeeeeleeeleeeeeeeeeeelleeeeeeeeeeeleeeeeleeeeleleeeeeeeellee...
output:
ajmmzkdgsgnaegianrtejueeudecexaxegkcxrtppdcrdofsscijdakieapbbgacxkfxbbbireaexckchxcrbebmsmamkmffdrafprsghjdkbckgxrwpbkvxehbjgyyikakjgvivihdwrebtatpkrrdrftpjeuboaejkirryadabpybghxxihkvagkpvikjpxxuusgwbdhynwdxshjivadawgayxygnbtgkwhrxnfcrootkcbrxbyugoonsimbhnormuvpvvptbuzwannxtbstntxooiwmwswhxsvskhntns...
result:
ok
Test #15:
score: 0
Accepted
time: 3ms
memory: 7640kb
input:
26 500 dddddddddddkddddddddddddddddddddkdddddkddddddddkddddkddddddkddddddddkdddkddddddddddddddddddddddddddddddddddkdddddddddkdkddddddddddddddddddddddddddkdddddddddddkdkkkddddddddddddddddddddkddkddddddddddddddddddddddddddddddddddddddddddddddkdddddddddddddddddkdkdddkddkdddkddddddkdddddddddddddkddddddd...
output:
enecqarucfidncbebhgifbebcemelvfbdrnfcidebbjbbqqdrhiadezbchndhjnuhcubshtnehbeiultjhmejfnjlqeprjmtmtfjjthicttdttcanxghadlsoctemjtaqueenxucefhljotjopqrrqggoqtiyuqiqsduxwimewewtpnihipfppespldixnrxpfxffffmrfyujhpjiuxfwalhwftnrmrffttpjmljusytxuayjsgmugxvuxtdyshamdvsszamdjxriwmqumghwuspzuamasazgszpsgswsthu...
result:
ok
Test #16:
score: 0
Accepted
time: 3ms
memory: 7672kb
input:
2 1 s B
output:
z
result:
ok
Test #17:
score: 0
Accepted
time: 2ms
memory: 7612kb
input:
5 3 idn BBY mvh BBB cva BBG you BBB
output:
zna
result:
ok
Test #18:
score: 0
Accepted
time: 2ms
memory: 7676kb
input:
3 2 jt BB bg BB
output:
zz
result:
ok
Test #19:
score: 0
Accepted
time: 3ms
memory: 7612kb
input:
4 8 jzhqnmbc BBBBBBBY quubxmwq BBBBYBBB zkmtxamf BBBYYBBB
output:
yyyyyctx
result:
ok
Test #20:
score: -100
Dangerous Syscalls
input:
83 28 yyjekmbfltupxglbgnniupgrbbhh YYYYYYBYBBYYYYBBYYBBBBBYGBYY gvgwlfkbriylbdfmajjupyijghxk GYYYBYYYYBYBBYBYYYBYYYBGBYYB jjqnbpooxrfsqntbitwbgrplljzp YBYYYYBBYYYYBBBBBBYBYBBBBGBB lqdozqobdhvzmtusczvxthcfvymz BYGBBBBYBYYBYBYYBBBYBYBYBYBB tkhuvtpuhnmzphnqhpfzfsokewoh BYYYYBYBYYGBBBBYBBGBBYBBYYBB gjer...