QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#514837 | #5161. Last Guess | Tobo | WA | 1ms | 4192kb | C++20 | 3.8kb | 2024-08-11 11:57:29 | 2024-08-11 11:57:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int g, l;
cin >> g >> l;
g--;
vector<string> a(g), res(g);
for (int i = 0; i < g; i++)
cin >> a[i] >> res[i];
string ans = string(l, ' ');
for (int i = 0; i < g; i++)
for (int j = 0; j < l; j++)
if (res[i][j] == 'G')
ans[j] = a[i][j];
vector<vector<int>> ban(l, vector<int>(26));
vector<int> req(26);
vector<bool> lim(26);
for (int i = 0; i < g; i++)
{
for (int j = 0; j < l; j++)
if (res[i][j] != 'G')
ban[j][a[i][j] - 'a'] = 1;
for (int j = 0; j < l; j++)
if (res[i][j] == 'B')
lim[a[i][j] - 'a'] = 1;
vector<int> cnt(26);
for (int j = 0; j < l; j++)
if (res[i][j] != 'B')
cnt[a[i][j] - 'a']++;
for (int c = 0; c < 26; c++)
req[c] = max(req[c], cnt[c]);
}
for (int i = 0; i < l; i++)
if (ans[i] != ' ')
for (int c = 0; c < 26; c++)
if (char(c + 'a') != ans[i])
ban[i][c] = 1;
int s = 0, t = 26 + l + 1;
vector<int> head(t + 1, -1), nxt, to, cap;
auto add = [&](int x, int y, int z)
{
to.push_back(y);
cap.push_back(z);
nxt.push_back(head[x]);
head[x] = to.size() - 1;
to.push_back(x);
cap.push_back(0);
nxt.push_back(head[y]);
head[y] = to.size() - 1;
};
for (int c = 0; c < 26; c++)
add(s, c + 1, req[c]);
int sum = accumulate(req.begin(), req.end(), 0);
for (int i = 0; i < l; i++)
{
int id = 27 + i;
if (ans[i] != ' ')
add(ans[i] - 'a' + 1, id, 1);
add(id, t, 1);
}
vector<int> arc(t + 1), dis(t + 1);
auto bfs = [&]() -> bool
{
dis.assign(t + 1, -1);
dis[s] = 0;
queue<int> que;
que.push(s);
while (!que.empty())
{
int cur = que.front();
que.pop();
arc[cur] = head[cur];
for (int p = head[cur]; ~p; p = nxt[p])
{
if (cap[p] && dis[to[p]] == -1)
{
dis[to[p]] = dis[cur] + 1;
que.push(to[p]);
}
}
}
return dis[t] != -1;
};
auto dfs = [&](auto &dfs, int cur, int flow) -> int
{
if (cur == t)
return flow;
int used = 0;
for (int &p = arc[cur]; ~p; p = nxt[p])
{
if (dis[to[p]] == dis[cur] + 1 && cap[p])
{
int k = dfs(dfs, to[p], min(flow - used, cap[p]));
used += k;
cap[p] -= k, cap[p ^ 1] += k;
if (used == flow)
break;
}
}
return used;
};
while (bfs())
sum -= dfs(dfs, s, 1e9);
for (int i = 0; i < l; i++)
{
int id = 27 + i;
for (int c = 0; c < 26; c++)
if (!ban[i][c] && ans[i] == ' ')
add(c + 1, id, 1);
}
while (bfs())
sum -= dfs(dfs, s, 1e9);
assert(sum == 0);
for (int i = 0; i < l; i++)
{
int cur = 27 + i;
for (int p = head[cur]; ~p; p = nxt[p])
{
if (to[p] <= 26 && cap[p])
{
ans[i] = char('a' + to[p] - 1);
break;
}
}
if (ans[i] == ' ')
{
for (int c = 0; c < 26; c++)
if (!ban[i][c] && !lim[c])
ans[i] = char('a' + c);
}
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabzczzzbdde
result:
ok
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 4192kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzz...
result:
FAIL Condition failed: "answer.size() == n"