QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#514819#5161. Last GuessToboWA 1ms3880kbC++203.7kb2024-08-11 11:37:522024-08-11 11:37:52

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 11:37:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3880kb
  • [2024-08-11 11:37:52]
  • 提交

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] == 'Y')
                cnt[a[i][j] - 'a']++;
        for (int j = 0; j < l; j++)
            if (res[i][j] != 'G' && ans[j] != ' ')
                cnt[ans[j] - 'a'] = max(0, cnt[ans[j] - 'a'] - 1);
        for (int c = 0; c < 26; c++)
            req[c] = max(req[c], cnt[c]);
    }

    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++)
    {
        if (ans[i] != ' ')
            continue;
        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++)
    {
        if (ans[i] != ' ')
            continue;
        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';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3496kb

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabzczzzbdde

result:

ok 

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3880kb

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzz...

result:

FAIL Condition failed: "answer.size() == n"