QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#815899#9802. Light Up the Griducup-team1769WA 457ms25720kbC++202.4kb2024-12-15 18:33:432024-12-15 18:33:43

Judging History

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

  • [2024-12-15 18:33:43]
  • 评测
  • 测评结果:WA
  • 用时:457ms
  • 内存:25720kb
  • [2024-12-15 18:33:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// #define int long long

signed main()
{
    // cin.tie(0)->ios::sync_with_stdio(false);

    int t = 1;
    cin >> t;

    vector<int> C(5);

    for (int i = 1; i <= 4; i++)
        cin >> C[i];

    map<set<int>, int> id;

    int _id = 0;
    auto dfs = [&](auto &&dfs, int x, set<int> st) -> void
    {
        if (id.count(st))
            return;
        id[st] = _id++;

        for (int i = x; i < 15; i++)
        {
            st.insert(i);
            dfs(dfs, i + 1, st);
            st.erase(i);
        }
    };

    id[{15}] = _id++;

    dfs(dfs, 0, {});

    vector<int> op = {0b0000, 0b1000, 0b0100, 0b0010, 0b0001, 0b1100, 0b0011, 0b1010, 0b0101, 0b1111};

    vector<vector<pair<int, int>>> g(_id);

    for (auto [st, _] : id)
    {
        for (int i = 1; i <= 9; i++)
        {
            set<int> tmp;
            for (auto v : st)
            {
                v ^= op[i];
                if (v < 15)
                    tmp.insert(v);
            }

            if (i <= 4)
                g[id[tmp]].push_back({_, C[1]});
            else if (i <= 6)
                g[id[tmp]].push_back({_, C[2]});
            else if (i <= 8)
                g[id[tmp]].push_back({_, C[3]});
            else
                g[id[tmp]].push_back({_, C[4]});
        }
    }

    // return 0;

    vector<int> dis(_id, 1e9);
    int s = id[{}];
    dis[s] = 0;

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    vector<bool> vis(_id);

    pq.push({0, s});

    while (pq.size())
    {
        auto [d, u] = pq.top();
        pq.pop();

        if (vis[u])
            continue;
        vis[u] = true;

        for (auto [v, w] : g[u])
        {
            if (dis[v] > dis[u] + w)
            {
                dis[v] = dis[u] + w;
                if (!vis[v])
                    pq.push({dis[v], v});
            }
        }
    }

    // return 0;

    while (t--)
    {
        int n;
        cin >> n;

        set<int> st;
        for (int k = 0; k < n; k++)
        {
            int num = 0;
            for (int i = 3; i >= 0; i--)
            {
                char ch;
                cin >> ch;
                num |= (ch == '1') << i;
            }
            st.insert(num);
        }

        cout << dis[id[st]] << '\n';
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 412ms
memory: 23024kb

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: 400ms
memory: 22860kb

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: 401ms
memory: 22916kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 457ms
memory: 25720kb

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:

4
4
4
4
4
36
4
38
40
4
4
4
34
37
37
4
29
4
39
40
38
4
4
4
4
4
4
38
34
4
32
4
4
4
4
4
4
34
37
34
29
4
4
4
4
35
4
4
38
4
4
29
4
4
36
4
43
4
41
4
4
39
4
4
34
4
4
4
42
40
4
4
28
34
32
4
4
39
4
37
4
4
4
4
4
34
4
40
4
4
40
4
4
4
4
4
36
40
36
34
29
27
36
4
34
4
4
4
4
32
38
4
38
4
42
4
4
33
34
37
4
4
32
36
...

result:

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