QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876587#9802. Light Up the GridArkweedyWA 116ms17388kbC++202.3kb2025-01-31 01:24:392025-01-31 01:24:40

Judging History

This is the latest submission verdict.

  • [2025-01-31 01:24:40]
  • Judged
  • Verdict: WA
  • Time: 116ms
  • Memory: 17388kb
  • [2025-01-31 01:24:39]
  • Submitted

answer

#include<bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using i64 = long long;

using namespace std;


void solve()
{
    int t;
    cin >> t;
    int a[4];
    for (int i = 0; i < 4; i++) {
        cin >> a[i];
    }
    vector<int>cost(16);
    cost[1] = cost[2] = cost[4] = cost[8] = a[0];
    cost[3] = cost[12] = min(a[0] * 2, a[1]);
    cost[5] = cost[10] = min(a[0] * 2, a[2]);
    cost[6] = cost[9] = min(a[0] * 2, a[1] + a[2]);
    cost[7] = cost[11] = cost[13] = cost[14] = min({ a[0] * 3,a[0] + a[1],a[0] + a[2],a[0] + a[3] });
    cost[15] = min({ 4 * a[0],2 * a[1],2 * a[2],a[3] });
    
    vector<vector<pair<int,int>>>g(1 << 16);//no clear
    for (int i = 0; i < (1 << 16); i++) {
        for (int j = 1; j < 16; j++) {
            int to = 0;
            for (int k = 0; k < 16; k++) {
                if ((i >> k) & 1) {
                    to |= (1 << (k ^ j));
                }
            }
            if (to & (1 << 15) || i == (1<<15)) {//ocurr full
                to &= ((1 << 15) - 1);
                g[to].push_back(make_pair(cost[j], i));
            }
            /*if (to == 0 && i != (1<<15)) {
                g[1 << 16].push_back(make_pair(cost[j], i));
            }*/
        }
    }
    const int inf = INT_MAX / 2;
    priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
    vector<int>dis(1 << 16, inf);
    //dis[1<<16] = 0;
    for (auto pr : g[0])
        q.push(pr);
    unordered_multiset<int>st;
    while(!q.empty()) {
        auto [d, p] = q.top();
        dis[p] = d;
        st.insert(p);
        for (auto [len, s] : g[p]) {
            q.push(make_pair(dis[p] + len, s));
        }
        while (!q.empty() && dis[q.top().second] != inf)
            q.pop();
    }

    while (t--) {
        int m;
        cin >> m;
        int getans = 0;
        for (int i = 0; i < m; i++) {
            string h, l;
            cin >> h >> l;
            int x = 8 * (h[0] - '0') + 4 * (h[1] - '0') + 2 * (l[0] - '0') + l[1] - '0';
            getans |= (1 << x);
        }
        cout << dis[getans] << endl;
    }
    return;
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 110ms
memory: 17244kb

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: 103ms
memory: 14612kb

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: 108ms
memory: 14496kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 116ms
memory: 17388kb

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
40
36
42
38
40
41
36
44
34
37
37
32
29
39
39
40
38
39
44
37
29
37
37
38
34
34
32
41
34
36
41
40
44
34
37
34
29
36
39
40
42
35
44
37
38
38
41
29
40
41
36
41
43
40
41
38
42
39
37
33
34
38
41
37
42
40
34
39
28
34
32
38
36
39
38
37
36
38
34
38
34
34
42
40
38
38
40
40
37
40
41
29
36
40
36
34
...

result:

wrong answer 47th numbers differ - expected: '39', found: '44'