QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201540 | #5161. Last Guess | BoulevardDust# | WA | 2ms | 4240kb | C++20 | 3.4kb | 2023-10-05 15:04:42 | 2023-10-05 15:04:43 |
Judging History
answer
#include <iostream>
#include <cstdio>
using namespace std;
const int inf = 1000000000;
struct E {
int to, nxt, w;
}e[100005];
int g, l, nlk[233][505];
int n, s, t, u, v, w, cnt, Ans, h[666], cur[666], dis[666], q[666];
char s1[505][505], s2[505][505], ans[505];
int vis[233], mnvis[233], mxvis[233], vans[505], anscnt[233], visB[233];
void add(int u, int v, int w) {
e[++cnt] = (E){v, h[u], w}, h[u] = cnt;
}
int bfs() {
for(int i = 1; i <= n; ++i) {
dis[i] = inf;
}
dis[s] = 0, q[1] = s;
int hd = 0, tl = 1;
while(hd < tl) {
int u = q[++hd];
for(int i = h[u]; i; i = e[i].nxt) {
int v = e[i].to;
if(e[i].w > 0 && dis[v] == inf) {
q[++tl] = v, dis[v] = dis[u] + 1;
if(v == t) return 1;
}
}
}
return 0;
}
int dfs(int u, int flow) {
if(u == t) return flow;
int res = 0;
for(int i = cur[u]; i; i = e[i].nxt) {
int v = e[i].to;
if(e[i].w > 0 && dis[v] == dis[u] + 1) {
int F = dfs(v, min(flow, e[i].w));
if(!F) dis[v] = inf;
e[i].w -= F, e[i ^ 1].w += F, res += F, flow -= F;
if(!flow) break;
}
}
return res;
}
int main() {
scanf("%d%d", &g, &l);
for(int i = 1; i < g; ++i) {
scanf("%s %s", s1[i] + 1, s2[i] + 1);
for(int j = 1; j <= l; ++j) {
if(s2[i][j] == 'G') {
vans[j] = 1, ans[j] = s1[i][j];
}
}
}
for(int i = 1; i <= l; ++i) if(vans[i]) {
++anscnt[ans[i]];
}
for(int c = 'a'; c <= 'z'; ++c) {
mxvis[c] = l;
}
for(int i = 1; i < g; ++i) {
for(int c = 'a'; c <= 'z'; ++c) {
vis[c] = visB[c] = 0;
}
for(int j = 1; j <= l; ++j) {
if(s2[i][j] == 'Y') {
nlk[s1[i][j]][j] = 1;
++vis[s1[i][j]];
}
else if(s2[i][j] == 'G') {
++vis[s1[i][j]];
}
else {
visB[s1[i][j]] = 1;
}
// if(s2[i][j] == 'G') {
// continue;
// }
// else {
// ++vis[s1[i][j]];
// if(s2[i][j] == 'Y') {
// nlk[s1[i][j]][j] = 1;
// }
// }
}
for(int c = 'a'; c <= 'z'; ++c) {
mnvis[c] = max(mnvis[c], vis[c] - anscnt[c]);
if(visB[c]) {
mxvis[c] = min(mxvis[c], vis[c] - anscnt[c]);
}
}
}
cnt = 1;
s = 26 + l + 1, t = 26 + l + 2;
n = t;
for(int i = 1; i <= 26; ++i) {
add(s, i, mnvis['a' + i - 1]), add(i, s, 0);
for(int j = 1; j <= l; ++j) if(!nlk['a' + i - 1][j] && !vans[j]) {
add(i, 26 + j, 1), add(26 + j, i, 0);
}
}
for(int i = 1; i <= l; ++i) if(!vans[i]) {
add(26 + i, t, 1), add(t, 26 + i, 0);
}
while(bfs()) {
for(int i = 1; i <= n; ++i) {
cur[i] = h[i];
}
Ans += dfs(s, inf);
}
for(int i = 1; i <= 26; ++i) {
for(int j = h[i]; j; j = e[j].nxt) {
if(e[j].w < 1) {
ans[e[j].to - 26] = 'a' + i - 1;
vans[e[j].to - 26] = 1;
}
}
}
for(int i = 1; i <= 26; ++i) {
// printf("%c %d %d\n", 'a' + i - 1, mxvis['a' + i - 1], mnvis['a' + i - 1]);
add(s, i, mxvis['a' + i - 1] - mnvis['a' + i - 1]), add(i, s, 0);
}
for(int i = 1; i <= l; ++i) if(vans[i]) {
for(int j = h[26 + i]; j; j = e[j].nxt) {
e[j].w = e[j ^ 1].w = 0;
}
}
while(bfs()) {
for(int i = 1; i <= n; ++i) {
cur[i] = h[i];
}
Ans += dfs(s, inf);
}
for(int i = 1; i <= 26; ++i) {
for(int j = h[i]; j; j = e[j].nxt) {
if(!vans[e[j].to - 26] && e[j].w < 1) {
ans[e[j].to - 26] = 'a' + i - 1;
vans[e[j].to - 26] = 1;
}
}
}
for(int i = 1; i <= l; ++i) {
putchar(ans[i]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabzczzzbdde
result:
ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 4168kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 4016kb
input:
24 500 vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvuvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
result:
ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 4240kb
input:
23 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqq...
output:
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...
result:
ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 4240kb
input:
22 500 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
result:
ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
30 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
vayjablpmyavasaaqaru
result:
ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3860kb
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: 0ms
memory: 3724kb
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: 0ms
memory: 3912kb
input:
25 500 eppppsppppppappppapppaswppspwppeupppwpwppppwppspppppppapppppspppappwpppppspspuppppppppppupwppeppppppppuppppusppspppppppwppppppppspeppppppppppepspppeppuppppwpppppppppppppwpppppppwppupppppspppppppppppppupeppppppppsppppeppaeppppppppppppppppppappppppppppppppppsppwppuappppepupuapppeppppppapppppppp...
output:
vayjogcjsnarhzfrshqbxhgirsgmitjvlabdikinenuizmgwwuqtzohxzeudgtmnhsaiacratgwgjljtkyetowdwlaibdvksccbsonlmrdjlgbngconrstmidytrdknwgjvyxzueqskrnvqgzmtvaelfxubiaqctbexjeftotinkqfsusinolqbsxjgcrqwkerywwmyylevubemsnzagqjtuvcuhvrbcnfcxznfymkquskbhffkcxrezezkemfyfgfzirxlhanfbvrldlhfcavqzzcbyhycwtknftnxhomqg...
result:
ok
Test #11:
score: 0
Accepted
time: 2ms
memory: 3956kb
input:
25 500 smxeetdiacxotgkpibsieraggqfjdbjxykzpiinrjxkmcczngkgpidtnacrzonzmrjsyfaiptigawddifgqxiiqibyymxvzncvifqsyfxmeodqwvwgqegpizkzfvsyywomkaviwjcasacijfbpjibvsroitinpfddjzcdkmxeisynrzipizmoyveveqwsfaqixobgrkstwtdtcfbwrvyvrgwdcmjozmitwcfitpzqdnikqbcpzyerwwigzdiczfmagmvacqxwbbiiiqrgxwvprvicjdsajinpmrrn...
output:
lxrggumnthrcukqbzoljgstkkayvmovrpqfbjjwsvrqxhhfwkqkbnmuwthsfcwfxsvlpytjbuzktdmmnykarnnanoppxrefwhejyalpyrxgcmadedkagkbnfqfyelppdcxqtendvhtlthnvyobvzoelscnuzwbymmvfhmqxrgnlpwsfjbjfxcpegegadlytajrcoksqludumuhyodsepeskdmhxvcfxjudhyzubfamwnqaohbfpgsddzkfmjhfyxtkxethardoojjzaskrdebsenhvmltvzwbxsswengqqwz...
result:
ok
Test #12:
score: 0
Accepted
time: 2ms
memory: 3968kb
input:
25 500 zzzzzzzzzzezzzzzyzzzyfzzzzzyzfzzzzzuzzzzzzzzyezezzzyzzzzzzzzzzzzzzzuzzzzzzzzfzzzzzzzyzzezfzzzzzzzzzzzzzzzzzzzzzzzfzzzzzzzzzzzzzzuzzzzzzzzzzzzzzzzzzzzuzzzzzzzzzzzyzzzzuzzzzzzzyyzzzzzzzzzzzzzzzzzfzzzzzzzzzzyzzzzyzzzzzzeezzzzzzzzzzyzzzzzzzyzezzzfefzuzzzzzzzzzzzzzuzfzzzzzzezzzfzzzzzzzzzzyuezzfzzz...
output:
qjtwjfaynbvccrdxmkyemidubqxmbidthnhseryxlaeymvbvdqgmjplbtulcjwhffjcsftewuqbxixoaeklqmfcvjiyeuthdcnfrqlwcoynrwjtxyinarlkxyfwkcjwxsqbcldqgnhuohjjbalwyasdpgxqdrbenwmyonrsplnurofmmjjfkxwoqabotkkoatikpndnkqcqxmlpggmanbphuvvttrwehopqgmkreelbdmyvrhgivicskkpqgklfpyytlsxixrlogyvqanirnpjbxexfdmsvgfiepdgrsdfgd...
result:
ok
Test #13:
score: -100
Wrong Answer
time: 1ms
memory: 4236kb
input:
26 500 ffafffffafffffffffffffaaffaffffffffffffffffffffffffafffaffafffffffafffffffffffffffffffffffafaffffffffffafffffafffffffffafaffffffffffffffffffffaffffffffffffffffaffaffffffffffffffaffffffffffafffffafffaaffffffafafffafffffffffffffffaaffffffafffffffffffafffffffffffafffffafffffffaffffffffffafafffff...
output:
lwqbkmxwsmvvbbzzzbzzzzzzzcccccccccccccccccdddddddddddddddddeeeeeeeeeeeeeefffffffffffffffffffffffffffffggggggggggggggggghhhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkblllllllllllllllllbmmmmmmmmmmmmmmmbbnnnnnnnnnnnnnnnnnnnnnooooooooooooooooooooooppppppppppppppppppppq...
result:
FAIL Wrong answer: does not fit word 0