QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600356#5250. Combination Lockshzy99999WA 0ms3804kbC++204.0kb2024-09-29 16:05:452024-09-29 16:05:46

Judging History

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

  • [2024-09-29 16:05:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2024-09-29 16:05:45]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 1 << 10, M = (6000 + N) * 2, INF = 0x3f3f3f3f;
int t;
int n, c;
string a, b;
bool forbid[N], st[N];
int h[N], e[M], ne[M], f[M], idx;
int d[N], cur[N];
int S, T, match[N], cnt[N];
void add(int a, int b, int c)
{
    e[idx] = b, ne[idx] = h[a], f[idx] = c, h[a] = idx++;
    e[idx] = a, ne[idx] = h[b], f[idx] = 0, h[b] = idx++;
}
bool bfs()
{
    queue<int> q;
    for (int i = 0; i <= (1 << n) + 1; i++)
        d[i] = -1;
    d[S] = 0, cur[S] = h[S];
    q.push(S);
    while (q.size())
    {
        int t = q.front();
        q.pop();
        for (int i = h[t]; ~i; i = ne[i])
        {
            int j = e[i];
            if (d[j] == -1 && f[i])
            {
                d[j] = d[t] + 1;
                cur[j] = h[j];
                if (j == T)
                    return 1;
                q.push(j);
            }
        }
    }
    return 0;
}
int find(int u, int limit)
{
    int flow = 0;
    if (u == T)
        return limit;
    for (int i = cur[u]; ~i; i = ne[i])
    {
        cur[u] = i;
        int j = e[i];
        if (d[j] == d[u] + 1 && f[i])
        {
            int t = find(j, min(f[i], limit - flow));
            if (!t)
                d[j] = -1;
            flow += t, f[i] -= t, f[i ^ 1] += t;
        }
    }
    return flow;
}
int dinic()
{
    int res = 0, flow;
    while (bfs())
        while (flow = find(S, INF))
            res += flow;
    return res;
}
int calc(int x)
{
    int res = 0;
    for (int i = 0; i < n; i++)
        if (x >> i & 1)
            res++;
    return res % 2;
}
void work()
{
    S = 1 << n, T = (1 << n) + 1;
    for (int i = 0; i < 1 << n; i++)
        cnt[i] = calc(i);
    cnt[S] = cnt[T] = -1;
    for (int i = 0; i < 1 << n; i++) // 偶左,奇右
    {
        if (forbid[i] || cnt[i])
            continue;
        add(S, i, 1), add(i ^ 1, T, 1);
        for (int k = 0; k < n; k++)
        {
            int x = i ^ (1 << k);
            if (forbid[x])
                continue;
            add(i, x, 1);
        }
    }

    dinic();
    // cout << dinic() << endl;

    for (int i = 0; i < idx; i += 2)
        if (!f[i] && !cnt[e[i ^ 1]] && cnt[e[i]] == 1)
        {
            if (forbid[e[i ^ 1]] || forbid[e[i]])
                continue;
            match[e[i ^ 1]] = e[i], match[e[i]] = e[i ^ 1], st[e[i]] = st[e[i ^ 1]] = 1;
            // cout << ":" << e[i ^ 1] << ' ' << e[i] << endl;
        }
}
void bfs2()
{
    queue<int> q;
    for (int i = 0; i < 1 << n; i++)
        if (!st[i])
            q.push(i);
    while (q.size())
    {
        int t = q.front();
        q.pop();
        for (int i = h[t]; ~i; i = ne[i])
        {
            int j = e[i];
            if (!st[j])
                continue;
            if (!st[match[j]])
                continue;
            st[match[j]] = 0;
            q.push(match[j]);
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t--)
    {
        cin >> n >> c;
        cin >> a >> b;
        for (int i = 0; i <= (1 << n) + 1; i++)
            forbid[i] = st[i] = 0, h[i] = match[i] = -1;
        idx = 0;
        int ini = 0;
        for (int i = 0; i < n; i++)
            ini = ini * 2 + (a[i] == b[i]);
        while (c--)
        {
            string temp;
            int x = 0;
            cin >> temp;
            for (int i = 0; i < n; i++)
                x = x * 2 + (temp[i] == '=');
            forbid[x] = 1;
        }

        work();

        bfs2();
        // for (int i = 0; i < 1 << n; i++)
        //     if (st[i])
        //         cout << i << ' ';
        // cout << endl;

        if (st[ini])
            cout << "Alice" << endl;
        else
            cout << "Bob" << endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3612kb

input:

8
2 0
00
00
2 1
00
00
..
2 1
00
00
=.
2 2
00
00
..
=.
2 1
00
00
.=
2 2
00
00
..
.=
2 2
00
00
=.
.=
2 3
00
00
..
=.
.=

output:

Alice
Alice
Bob
Bob
Bob
Alice
Bob
Bob

result:

wrong answer 4th lines differ - expected: 'Alice', found: 'Bob'