QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#206492 | #5161. Last Guess | willow# | WA | 0ms | 3876kb | C++17 | 2.5kb | 2023-10-07 20:49:10 | 2023-10-07 20:49:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int g, l, least[26], most[26], cnt[26], cant[505][26], id, match[505], vis[505], clk;
char word[505], op[505], ans[505], ch[1005];
vector<int> G[505];
int Dfs(int u) {
for(auto v : G[u]) {
if(vis[v] != clk) {
vis[v] = clk;
if(!match[v] || Dfs(match[v])) {
match[v] = u;
return 1;
}
}
}
return 0;
}
int main() {
scanf("%d%d", &g, &l);
fill(most, most + 26, l + 1);
for(int i = 1; i <= l; ++ i)
ans[i] = ' ';
for(int i = 1; i < g; ++ i) {
scanf("%s%s", word + 1, op + 1);
fill(cnt, cnt + 26, 0);
for(int j = 1; j <= l; ++ j) {
int c = word[j] - 'a';
if(op[j] == 'G') {
++ cnt[c];
ans[j] = word[j];
}
}
for(int j = 1; j <= l; ++ j) {
int c = word[j] - 'a';
if(op[j] == 'Y') {
++ cnt[c];
cant[j][c] = 1;
}
else if(op[j] == 'B') {
most[c] = min(most[c], cnt[c]);
cant[j][c] = 1;
}
}
for(int j = 0; j < 26; ++ j)
least[j] = max(least[j], cnt[j]);
}
for(int i = 1; i <= l; ++ i)
if(ans[i] != ' ')
-- least[ans[i] - 'a'], -- most[ans[i] - 'a'];
for(int i = 0; i < 26; ++ i) {
assert(least[i] >= 0);
for(int k = id + 1; k <= id + least[i]; ++ k) {
ch[k] = i + 'a';
}
for(int j = 1; j <= l; ++ j) {
if(ans[j] == ' ' && !cant[j][i]) {
for(int k = id + 1; k <= id + least[i]; ++ k) {
G[k].push_back(j);
}
}
}
id += least[i];
}
// cerr << id << endl;
// for(int i = 1; i <= id; ++ i)
// cerr << ch[i] << " ";
// cerr << endl;
for(int i = 1; i <= id; ++ i) {
++ clk;
assert(Dfs(i));
}
for(int i = 1; i <= l; ++ i) {
if(ans[i] == ' ') {
if(match[i]) {
ans[i] = ch[match[i]];
}
else {
for(int j = 0; j < 26; ++ j) {
if(!cant[i][j] && least[j] < most[j]) {
ans[i] = j + 'a';
++ least[j];
break;
}
}
}
}
}
for(int i = 1; i <= l; ++ i)
putchar(ans[i]);
puts("");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3752kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabecdbadaaa
result:
ok
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3872kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
zyxwvutsrpooonmlkjihgfedcbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaa...
result:
FAIL Condition failed: "answer.size() == n"