QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#514831 | #5161. Last Guess | Tobo | WA | 1ms | 3760kb | C++20 | 3.6kb | 2024-08-11 11:49:45 | 2024-08-11 11:49:46 |
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;
for (int c = 0; c < 26; c++)
if (!ban[i][c])
add(c + 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);
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);
}
assert(ans[i] != ' ');
}
cout << ans << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3760kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3544kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabacabbcdde
result:
FAIL Wrong answer: does not fit word 0