QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797786#9802. Light Up the GridDLYdly1105WA 49ms4640kbC++141.7kb2024-12-03 18:24:082024-12-03 18:24:09

Judging History

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

  • [2024-12-03 18:24:09]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:4640kb
  • [2024-12-03 18:24:08]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,a[10]={1,2,4,8,3,12,5,10,15},b[10];
int f[100][100],dp[(1<<16)+10];
void init()
{
    for(int i=0;i<16;i++)
    {
        for(int j=0;j<16;j++)f[i][j]=1e18;
        f[i][i]=0;
    }
    for(int i=0;i<16;i++)
    {
        for(int j=0;j<=8;j++)
        {
            f[i][i^a[j]]=min(f[i][i^a[j]],b[j]);
        }
    }
    for(int k=0;k<16;k++)
    {
        for(int i=0;i<16;i++)
        {
            for(int j=0;j<16;j++)
            {
                f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
            }
        }
    }
    for(int i=1;i<(1<<16);i++)dp[i]=1e18;
    for(int i=1;i<(1<<16);i++)
    {
        for(int j=0;j<16;j++)
        {
            if((i&(1<<j)))
            {
                for(int k=0;k<16;k++)
                {
                    if(j!=k&&((i&(1<<k))))
                    {
                        dp[i]=min(dp[i],dp[i-(1<<j)]+f[k][j]);
                    }
                }
            }
            if(i==(1<<j))dp[i]=f[15][j];
        }
    }
    dp[(1<<15)]=min(b[0],min(b[4],min(b[6],b[8])))*2;
    return;
}
signed main()
{
    scanf("%lld%lld%lld%lld%lld",&T,&b[0],&b[4],&b[6],&b[8]);
    b[1]=b[0];
    b[2]=b[0];
    b[3]=b[0];
    b[5]=b[4];
    b[7]=b[6];
    init();
    while(T--)
    {
        int m,id=0;
        string str;
        scanf("%lld",&m);
        for(int i=1;i<=m;i++)
        {
            int x=0;
            cin>>str;
            x=(str[0]-'0')*8+(str[1]-'0')*4;
            cin>>str;
            x+=(str[0]-'0')*2+(str[1]-'0');
            id|=(1<<x);
        }
        printf("%lld\n",dp[id]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 30ms
memory: 4352kb

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: 29ms
memory: 4640kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 49ms
memory: 4280kb

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
36
36
40
38
40
36
34
42
34
34
36
30
29
34
38
40
36
36
40
34
25
32
34
36
32
31
32
36
32
34
36
38
38
34
36
32
29
34
34
36
38
35
35
34
38
34
36
29
36
38
36
36
42
36
40
30
39
38
32
30
34
36
32
34
40
38
32
30
27
34
32
36
34
38
34
36
32
34
29
30
32
34
36
38
34
36
40
38
34
34
32
25
34
38
36
34
...

result:

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