QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#787670#9802. Light Up the GridAbracaSoraWA 46ms20212kbC++231.8kb2024-11-27 13:57:522024-11-29 22:56:38

Judging History

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

  • [2024-11-29 22:56:38]
  • 管理员手动重测本题所有提交记录
  • 测评结果:WA
  • 用时:46ms
  • 内存:20212kb
  • [2024-11-27 13:57:53]
  • 评测
  • 测评结果:0
  • 用时:44ms
  • 内存:20152kb
  • [2024-11-27 13:57:52]
  • 提交

answer

#include <bits/stdc++.h>
#define int int64_t
using namespace std;
int cost[16];
int dis[18][18];
int dp[1ll<<17][16];
signed main() {
    int t,a0,a1,a2,a3;
    cin >> t >> a0 >> a1 >> a2 >> a3;
    for (int i = 0; i < 16; i++) {
        cost[i] = 1e18;
    }
    cost[1] = cost[2] = cost[4] = cost[8] = a0;
    cost[3] = cost[12] = a1;
    cost[5] = cost[10] = a2;
    cost[15] = a3;
    for (int i = 0; i < 16; i++) {
        for (int j = 0; j < 16; j++) {
            dis[i][j] = dis[j][i] = cost[i^j];
        }
        if (i != 15) {
            dis[i][16] = dis[16][i] = cost[i^15];
        } else {
            dis[i][16] = dis[16][i] = 1e18;
        }
    }

    for (int k = 0; k < 17; k++) {
        for (int i = 0; i < 17; i++) {
            for (int j = 0; j < 17; j++) {
                dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
            }
        }
    }
    for (int i = 0; i < (1ll<<17); i++) {
        for (int j = 0; j < 17; j++) {
            dp[i][j] = 1e18;
        }
    }

    for (int i = 0; i < 16; i++) {
        dp[1ll<<i][i] = 0;
    }

    for (int i = 0; i < (1ll<<17); i++) {
        for (int j = 0; j < 17; j++) {
            if ((1ll << j) & i) {
                for (int k = 0; k < 17; k++) {
                    dp[i|(1ll<<k)][k] = min(dp[i|(1ll<<k)][k],dp[i][j]+dis[j][k]);
                }
            }
        }
    }
    while (t--) {
        int m;
        cin >> m;
        int ans = 0;
        while (m--) {
            string a,b;
            cin >> a >> b;
            a += b;
            int x = 0;
            for (int i = 0; i < 4; i++) {
                x = x*2 + (a[i] == '1');
            }
            ans |= 1ll << x;
        }
        ans |= 1ll << 16;
        cout <<dp[ans][16] << endl;
    }
}

详细

Test #1:

score: 100
Accepted
time: 26ms
memory: 19984kb

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: 26ms
memory: 19932kb

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: 31ms
memory: 20024kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 46ms
memory: 20212kb

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

result:

wrong answer 14th numbers differ - expected: '37', found: '36'