QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787206#9802. Light Up the Griducup-team059WA 52ms5172kbC++203.0kb2024-11-27 10:23:232024-11-27 10:23:25

Judging History

你现在查看的是测评时间为 2024-11-27 10:23:25 的历史记录

  • [2024-11-29 22:56:23]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:47ms
  • 内存:5224kb
  • [2024-11-27 10:23:25]
  • 评测
  • 测评结果:0
  • 用时:52ms
  • 内存:5172kb
  • [2024-11-27 10:23:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#define ll long long
#define int long long
#define PII pair<int, int>
//constexpr ll P = 998244353;
//const int N = 1e5, MOD = 1;


void solve() {
    int T;
    cin >> T;
    vector<int> a(4);
    for (int i = 0; i < 4; ++i) cin >> a[i];
    vector<PII> op;
    //01
    //23
    op.push_back({1, a[0]});
    op.push_back({1 << 1, a[0]});
    op.push_back({1 << 2, a[0]});
    op.push_back({1 << 3, a[0]});
    op.push_back({3, a[1]});
    op.push_back({(1 << 3) | (1 << 2), a[1]});
    op.push_back({1 | (1 << 2), a[2]});
    op.push_back({(1 << 1) | (1 << 3), a[2]});
    op.push_back({(1 << 4) - 1, a[3]});
    vector<int> to1((1 << 4) + 5, INT32_MAX);
    vector<int> st((1 << 4) + 5);
    int N = (1 << 4) - 1;
    to1[N] = 0;
    priority_queue<PII, vector<PII>, greater<PII> > q;
    q.push({to1[N], N});
    while (q.size()) {
        auto [dis, sta] = q.top();
        q.pop();
        if (st[sta]) continue;
        st[sta] = 1;
        for (auto [did, cost]: op) {
            int now = sta ^ did;
            if (st[now]) continue;
            if (to1[now] > dis + cost) {
                to1[now] = dis + cost;
                q.push({to1[now], now});
            }
        }
    }
    int M = (1 << 16) - 1;
    vector<int> vis(M + 5), val(M + 5, INT32_MAX);
    val[0] = 0;
    q.push({val[0], 0});
    while (q.size()) {
        auto [va, sta] = q.top();
        q.pop();
        if (vis[sta]) continue;
        vis[sta] = 1;
        vector<int> is, no;
        for (int i = 0; i < 16; ++i) {
            if ((sta >> i) & 1) is.push_back(i);
            else no.push_back(i);
        }
        for (auto x: no) {
            int p = x ^ N;
            int now = 1 << (x ^ p);
            for (auto y: is) {
                now |= 1 << (y ^ p);
            }
            if (vis[now]) continue;
            if (val[now] > va + to1[x]) {
                val[now] = va + to1[x];
                q.push({val[now], now});
            }
        }
    }
    while (T --) {
        int m;
        cin >> m;
        vector<int> aa(m);
        for (int i = 0; i < m; ++i) {
            int x, y;
            cin >> x >> y;
            if (x == 11) x = 3;
            else if (x == 10) x = 2;
            if (y == 11) y = 3;
            else if (y == 10) y = 2;
            aa.push_back((x << 2) | y);
        }
        int res = INT32_MAX;
        for (auto [x, y]: op) {
            auto b = aa;
            for (auto& v: b) {
                v ^= x;
            }
            for (auto v: b) {
                int p = v ^ N, sta = 0;
                for (auto u: b) {
                    sta |= (1 << (u ^ p));
                }
                res = min(res, val[sta] + y + to1[v]);
            }
        }
        cout << res << '\n';
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;

//    cin >> t;

    while (t--){
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 20ms
memory: 5172kb

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

1121
2

result:

ok 2 number(s): "1121 2"

Test #2:

score: 0
Accepted
time: 10ms
memory: 4792kb

input:

2 1 1 1 1
4
10
00

01
00

00
10

00
01
1
11
11

output:

5
2

result:

ok 2 number(s): "5 2"

Test #3:

score: 0
Accepted
time: 14ms
memory: 4628kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 52ms
memory: 4784kb

input:

10000 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
8
11
01

11
00

01
10

11
11

00
01

01
01

01
00

11
10
9
00
00

01
01

10
11

00
01

11
10

11
00

11
11

00
11

01
10
9
11
11

10
00

11
00

11
01

00
10

01
11

00
01

01
01

10
01
11
00
01

01
01

10
10

00
11

11
11

11
10
...

output:

38
36
36
40
42
40
42
38
40
41
36
44
37
37
37
36
29
39
39
40
38
39
44
41
29
37
41
38
34
34
36
41
36
38
41
43
44
34
37
37
29
40
39
40
44
36
43
41
38
38
41
29
44
41
39
41
43
40
41
38
42
39
37
34
38
38
42
37
42
40
37
40
28
36
32
42
36
39
38
37
36
42
34
38
38
36
42
40
38
42
40
40
37
40
42
29
36
40
36
37
...

result:

wrong answer 1st numbers differ - expected: '34', found: '38'