QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600448#5250. Combination Lockshzy99999AC ✓4ms3964kbC++204.1kb2024-09-29 16:37:182024-09-29 16:37:22

Judging History

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

  • [2024-09-29 16:37:22]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3964kb
  • [2024-09-29 16:37:18]
  • 提交

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) + 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 && flow < limit; 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])
            continue;
        if (cnt[i] == 1)
        {
            add(i, T, 1);
            continue;
        }
        add(S, i, 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] && !forbid[i])
            q.push(i);
    while (q.size())
    {
        int t = q.front();
        q.pop();
        for (int i = 0; i < n; i++)
        {
            int j = t ^ (1 << i);
            if (!st[j] || forbid[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: 3708kb

input:

2
1 0
0
0
1 1
0
0
.

output:

Alice
Bob

result:

ok 2 lines

Test #2:

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

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
Alice
Bob
Alice
Bob
Bob

result:

ok 8 lines

Test #3:

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

input:

20
4 4
4714
5245
..=.
..==
.==.
==..
4 1
2697
1438
.=..
4 5
9255
0677
...=
..==
=..=
==.=
====
4 12
3292
7326
...=
..=.
..==
.=..
.=.=
.==.
=...
=..=
=.==
==..
==.=
====
4 9
8455
2536
...=
..==
.=..
.=.=
.==.
.===
=...
==..
===.
4 12
5755
1517
...=
..=.
..==
.=..
.=.=
.===
=..=
=.=.
=.==
==..
==.=
=...

output:

Alice
Bob
Alice
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Bob

result:

ok 20 lines

Test #4:

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

input:

20
5 30
99942
90170
.....
....=
...==
..=..
..=.=
..==.
..===
.=...
.=..=
.=.=.
.=.==
.==..
.==.=
.===.
.====
=...=
=..=.
=..==
=.=..
=.=.=
=.==.
=.===
==...
==..=
==.=.
==.==
===..
===.=
====.
=====
5 14
11760
95480
...=.
...==
..=..
..=.=
.=...
.=..=
.====
=....
=...=
=.=..
=.==.
==...
==.==
=====...

output:

Bob
Alice
Alice
Alice
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Bob

result:

ok 20 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

20
6 62
188256
588825
......
.....=
....=.
....==
...=..
...=.=
...==.
...===
..=...
..=..=
..=.=.
..=.==
..==..
..==.=
..===.
..====
.=....
.=...=
.=..=.
.=..==
.=.=..
.=.=.=
.=.==.
.=.===
.==..=
.==.=.
.==.==
.===..
.===.=
.=====
=.....
=....=
=...=.
=...==
=..=..
=..=.=
=..==.
=..===
=.=...
=.=.....

output:

Bob
Bob
Alice
Alice
Alice
Bob
Bob
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Alice

result:

ok 20 lines

Test #6:

score: 0
Accepted
time: 1ms
memory: 3824kb

input:

20
7 34
1829551
8802318
....=.=
...=.==
...===.
..=..=.
..=..==
..=.==.
.=...==
.=..===
.=.=.=.
.=.==..
.==....
.==...=
.==.=.=
.==.===
.===.==
=.....=
=..=.=.
=..=.==
=..==..
=..==.=
=.=.=..
=.=.=.=
=.==..=
=.==.=.
=.===..
=.===.=
=.=====
==.....
==..===
==.==.=
===....
===..==
====.==
=====.=
7 56...

output:

Alice
Bob
Bob
Alice
Bob
Bob
Alice
Bob
Alice
Bob
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Bob
Alice
Bob

result:

ok 20 lines

Test #7:

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

input:

20
8 101
98515990
35971617
......==
....==..
....==.=
...=.=..
...=.=.=
...=.==.
...==...
...==.==
...===..
...===.=
...====.
..=..=..
..=..==.
..=.=..=
..=.=.==
..=.==.=
..=.===.
..==...=
..==..==
..==.=..
..==.=.=
..===..=
.=...=..
.=...=.=
.=...===
.=..=...
.=..=..=
.=..==.=
.=..===.
.=..====
.=....

output:

Alice
Alice
Bob
Alice
Alice
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Alice
Bob
Alice
Bob
Bob
Alice
Bob

result:

ok 20 lines

Test #8:

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

input:

20
9 280
799210637
072013670
.........
......=.=
......==.
.....=...
.....=..=
.....=.=.
.....===.
.....====
....=....
....=.==.
....==...
....==..=
....==.==
....=====
...=.....
...=....=
...=...==
...=..=..
...=..=.=
...=..==.
...=.=...
...=.=..=
...=.=.=.
...=.=.==
...=.==.=
...=.====
...==..=.
....

output:

Alice
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Alice
Bob
Bob
Alice
Alice
Bob
Alice
Bob

result:

ok 20 lines

Test #9:

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

input:

20
3 0
000
000
3 1
000
000
...
3 1
000
000
=..
3 2
000
000
...
=..
3 1
000
000
.=.
3 2
000
000
...
.=.
3 2
000
000
=..
.=.
3 3
000
000
...
=..
.=.
3 1
000
000
==.
3 2
000
000
...
==.
3 2
000
000
=..
==.
3 3
000
000
...
=..
==.
3 2
000
000
.=.
==.
3 3
000
000
...
.=.
==.
3 3
000
000
=..
.=.
==.
3 4
0...

output:

Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice

result:

ok 20 lines

Test #10:

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

input:

20
3 2
000
000
.=.
..=
3 3
000
000
...
.=.
..=
3 3
000
000
=..
.=.
..=
3 4
000
000
...
=..
.=.
..=
3 2
000
000
==.
..=
3 3
000
000
...
==.
..=
3 3
000
000
=..
==.
..=
3 4
000
000
...
=..
==.
..=
3 3
000
000
.=.
==.
..=
3 4
000
000
...
.=.
==.
..=
3 4
000
000
=..
.=.
==.
..=
3 5
000
000
...
=..
.=.
=...

output:

Alice
Alice
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Alice
Bob
Alice
Alice

result:

ok 20 lines

Test #11:

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

input:

20
3 2
000
000
==.
=.=
3 3
000
000
...
==.
=.=
3 3
000
000
=..
==.
=.=
3 4
000
000
...
=..
==.
=.=
3 3
000
000
.=.
==.
=.=
3 4
000
000
...
.=.
==.
=.=
3 4
000
000
=..
.=.
==.
=.=
3 5
000
000
...
=..
.=.
==.
=.=
3 2
000
000
..=
=.=
3 3
000
000
...
..=
=.=
3 3
000
000
=..
..=
=.=
3 4
000
000
...
=..
....

output:

Bob
Bob
Bob
Bob
Bob
Bob
Alice
Bob
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Bob
Alice
Bob

result:

ok 20 lines

Test #12:

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

input:

20
3 4
000
000
.=.
==.
..=
=.=
3 5
000
000
...
.=.
==.
..=
=.=
3 5
000
000
=..
.=.
==.
..=
=.=
3 6
000
000
...
=..
.=.
==.
..=
=.=
3 1
000
000
.==
3 2
000
000
...
.==
3 2
000
000
=..
.==
3 3
000
000
...
=..
.==
3 2
000
000
.=.
.==
3 3
000
000
...
.=.
.==
3 3
000
000
=..
.=.
.==
3 4
000
000
...
=..
....

output:

Alice
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Alice
Bob

result:

ok 20 lines

Test #13:

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

input:

20
3 2
000
000
..=
.==
3 3
000
000
...
..=
.==
3 3
000
000
=..
..=
.==
3 4
000
000
...
=..
..=
.==
3 3
000
000
.=.
..=
.==
3 4
000
000
...
.=.
..=
.==
3 4
000
000
=..
.=.
..=
.==
3 5
000
000
...
=..
.=.
..=
.==
3 3
000
000
==.
..=
.==
3 4
000
000
...
==.
..=
.==
3 4
000
000
=..
==.
..=
.==
3 5
000
0...

output:

Alice
Bob
Alice
Alice
Alice
Alice
Alice
Alice
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Bob
Bob

result:

ok 20 lines

Test #14:

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

input:

20
3 3
000
000
.=.
=.=
.==
3 4
000
000
...
.=.
=.=
.==
3 4
000
000
=..
.=.
=.=
.==
3 5
000
000
...
=..
.=.
=.=
.==
3 3
000
000
==.
=.=
.==
3 4
000
000
...
==.
=.=
.==
3 4
000
000
=..
==.
=.=
.==
3 5
000
000
...
=..
==.
=.=
.==
3 4
000
000
.=.
==.
=.=
.==
3 5
000
000
...
.=.
==.
=.=
.==
3 5
000
000
=...

output:

Bob
Bob
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Alice
Bob
Alice
Bob
Alice
Alice

result:

ok 20 lines

Test #15:

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

input:

8
3 4
000
000
==.
..=
=.=
.==
3 5
000
000
...
==.
..=
=.=
.==
3 5
000
000
=..
==.
..=
=.=
.==
3 6
000
000
...
=..
==.
..=
=.=
.==
3 5
000
000
.=.
==.
..=
=.=
.==
3 6
000
000
...
.=.
==.
..=
=.=
.==
3 6
000
000
=..
.=.
==.
..=
=.=
.==
3 7
000
000
...
=..
.=.
==.
..=
=.=
.==

output:

Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob

result:

ok 8 lines

Test #16:

score: 0
Accepted
time: 4ms
memory: 3752kb

input:

20
10 815
4819325421
9470583705
.........=
........=.
.......=..
.......=.=
.......==.
.......===
......=...
......=..=
......=.=.
......=.==
......==..
......===.
......====
.....=....
.....=..==
.....=.=..
.....==...
.....==..=
.....==.=.
.....==.==
.....===..
.....===.=
.....====.
.....=====
.......

output:

Alice
Alice
Alice
Bob
Alice
Alice
Alice
Alice
Alice
Bob
Alice
Alice
Bob
Bob
Alice
Bob
Alice
Alice
Alice
Alice

result:

ok 20 lines

Test #17:

score: 0
Accepted
time: 3ms
memory: 3964kb

input:

20
10 7
9410870639
8237933369
.....=.=.=
...==.==..
..===....=
=..==..=.=
=..==.=.==
=.====.=.=
====.===.=
10 285
0225666838
4493031931
..........
.......=..
.......===
......==..
......==.=
......===.
.....=.=..
.....=.===
.....==...
.....==.==
.....===..
....=...=.
....=..===
....=.=...
....=.=..=...

output:

Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob
Bob

result:

ok 20 lines