QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#780086#9802. Light Up the GridTosakaUCWWA 156ms128828kbC++202.4kb2024-11-25 00:46:542024-11-29 22:50:55

Judging History

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

  • [2024-11-29 22:50:55]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:156ms
  • 内存:128828kb
  • [2024-11-25 00:46:55]
  • 评测
  • 测评结果:0
  • 用时:133ms
  • 内存:128808kb
  • [2024-11-25 00:46:54]
  • 提交

answer

#include <bits/stdc++.h>
using i64 = long long;
// #define int i64
#define pb push_back
#define ep emplace
#define eb emplace_back
using std::cerr;
using std::max, std::min, std::swap, std::array;
using std::cin, std::cout, std::string, std::vector;
int read(int x = 0, int f = 0, char ch = getchar()) {
    while (ch < 48 or 57 < ch) f = ch == 45, ch = getchar();
    while(48 <= ch and ch <= 57) x = x * 10 + ch - 48, ch = getchar();
    return f ? -x : x;
}
const int inf = 1e9;
using pii = std::pair<int, int>;
#define fi first
#define se second
int a[4];

struct Node {
    int dis, u;
    bool friend operator < (Node a, Node b) {
        return a.dis > b.dis;
    }
};

signed main() {
    int T = read();
    for (int i = 0; i < 4; i++) a[i] = read();

    const int opt[] = {1, 2, 4, 8, 12, 3, 10, 5, 15};
    const int val[] = {a[0], a[0], a[0], a[0], a[1], a[1], a[2], a[2], a[3]};

    int N = 1 << 16;

    vector<vector<pii>> g(N);

    for (int s = 0; s < N; s++) {

        for (int bit = 0; bit < 16; bit++) {
            if (!(s >> bit & 1)) continue;

            for (int i = 0; i < 9; i++) {
                int u = bit;
                int v = u ^ opt[i];
                int t = s;
                t ^= (1 << u);
                if (v != 15) t |= (1 << v);

                g[s].eb(t, val[i]);
                g[t].eb(s, val[i]);

            }
        }
    }

    vector<int> dis(N, inf);
    vector<int> vis(N, 0);

    int st = 0;
    std::priority_queue<Node> q;
    dis[st] = 0, q.ep(0, st);
    while (!q.empty()) {
        int u = q.top().u;
        q.pop();
        // cout << "u : " << u << '\n';
        if (vis[u]) continue;
        vis[u] = 1;
        for (auto [v, w] : g[u]) {
            // cout << "v w : " << v << " " << w << "\n";
            if (dis[v] > dis[u] + w) {
                dis[v] = dis[u] + w;
                q.ep(dis[v], v);
            }
        }
    }

    while (T--) {
        int n = read();
        int sta = 0;
        for (int i = 0; i < n; i++) {
            string s, t;
            cin >> s >> t;
            int x = (s[0] - '0') * 8 + (s[1] - '0') * 4
                  + (t[0] - '0') * 2 + (t[1] - '0');
            // cout << a[i] << '\n';
            sta |= (1 << x);
        }
        // cout << sta << '\n';
        cout << dis[sta] << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 108ms
memory: 128828kb

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: 111ms
memory: 128172kb

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: 104ms
memory: 128124kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 156ms
memory: 128468kb

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:

34
32
36
36
38
36
42
36
38
38
36
44
34
34
36
32
29
36
36
38
34
38
42
36
27
34
36
36
32
33
32
38
34
36
38
40
40
34
36
32
29
36
36
38
40
34
38
36
38
36
38
29
38
40
36
38
42
38
40
34
40
38
34
32
34
38
36
36
40
36
34
34
27
34
32
38
36
38
36
36
34
36
31
34
34
34
38
38
36
38
40
40
36
36
36
27
32
36
36
34
...

result:

wrong answer 5th numbers differ - expected: '40', found: '38'