QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#815688#9802. Light Up the GridKafuuChinocpp#WA 31ms6976kbC++142.5kb2024-12-15 16:25:582024-12-15 16:26:03

Judging History

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

  • [2024-12-15 16:26:03]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:6976kb
  • [2024-12-15 16:25:58]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int max1 = 16, max2 = 1 << max1;
const int inf = 0x3f3f3f3f;

int T, a[4];

int edge[max1 + 5][max1 + 5];
int f[max2 + 5][max1 + 5];

int main ()
{
    scanf("%d%d%d%d%d", &T, &a[0], &a[1], &a[2], &a[3]);

    memset(edge, 0x3f, sizeof(edge));
    for ( int i = 0; i < max1; i ++ )
        edge[i][i] = 0;
    
    for ( int i = 0; i < max1; i ++ )
    {
        int t = i ^ 1;
        edge[i][t] = min(edge[i][t], a[0]);

        t = i ^ 2;
        edge[i][t] = min(edge[i][t], a[0]);
        
        t = i ^ 4;
        edge[i][t] = min(edge[i][t], a[0]);

        t = i ^ 8;
        edge[i][t] = min(edge[i][t], a[0]);

        t = i ^ 1 ^ 2;
        edge[i][t] = min(edge[i][t], a[1]);

        t = i ^ 4 ^ 8;
        edge[i][t] = min(edge[i][t], a[1]);

        t = i ^ 1 ^ 4;
        edge[i][t] = min(edge[i][t], a[2]);

        t = i ^ 2 ^ 8;
        edge[i][t] = min(edge[i][t], a[2]);

        t = i ^ 1 ^ 2 ^ 4 ^ 8;
        edge[i][t] = min(edge[i][t], a[3]);
    }

    for ( int k = 0; k < max1; k ++ )
        for ( int i = 0; i < max1; i ++ )
            for ( int j = 0; j < max1; j ++ )
                edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
    
    memset(f, 0x3f, sizeof(f));
    f[0][max1 - 1] = 0;

    for ( int s = 0; s < max2; s ++ )
    {
        for ( int i = 0; i < max1; i ++ )
        {
            if ( f[s][i] != inf )
            {
                for ( int j = 0; j < max1; j ++ )
                {
                    if ( !((s >> j) & 1) )
                    {
                        f[s | (1 << j)][j] = min(f[s | (1 << j)][j], f[s][i] + edge[i][j]);
                    }
                }
            }
        }
    }

    int k;
    char str[5][5];
    while ( T -- )
    {
        scanf("%d", &k);

        int s = 0, x = 0;
        for ( int i = 1; i <= k; i ++ )
        {
            scanf("%s", str[0]);
            scanf("%s", str[1]);

            x = (str[0][0] - '0') | ((str[0][1] - '0') << 1) | ((str[1][0] - '0') << 2) | ((str[1][1] - '0') << 3);
            s |= 1 << x;

            // printf("x = %d\n", x);
        }

        int ans = inf;
        for ( int i = 0; i < max1; i ++ )
            ans = min(ans, f[s][i]);
        
        if ( !ans )
            ans = min(a[0], min(a[1], min(a[2], a[3]))) * 2;

        printf("%d\n", ans);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 6964kb

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: 24ms
memory: 6976kb

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: 25ms
memory: 6904kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 31ms
memory: 6908kb

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:

32
30
34
34
40
36
41
38
40
37
34
42
34
37
37
31
29
35
39
40
38
36
40
34
25
34
34
38
34
31
32
37
34
36
37
40
40
34
37
34
29
35
35
36
42
35
35
34
38
34
37
29
38
38
36
37
43
36
41
30
40
39
33
33
34
36
34
34
42
40
34
32
28
34
32
37
34
39
34
37
32
36
30
30
32
34
38
40
34
36
40
39
34
36
34
25
36
40
36
34
...

result:

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