QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793773#9802. Light Up the GridgswjWA 30ms3800kbC++141.7kb2024-11-30 00:20:102024-11-30 00:20:10

Judging History

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

  • [2024-11-30 00:20:10]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:3800kb
  • [2024-11-30 00:20:10]
  • 提交

answer

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

int all, line, col, single;
void solve(){
    int n;
    cin>>n;
    string s, t;
    vector<int> num(n, 0);
    vector<bool> vis(17, false);
    int now=15, min=0x3f3f3f3f3f3f3f3f, pos=-1, ans=0;
    for(int i=0; i<n; i++){
        cin>>s>>t;
        s+=t;
        num[i]=s[0]-'0'+2*(s[1]-'0')+4*(s[2]-'0')+8*(s[3]-'0');
//        if(num[i]==15) num[i]=16;
        vis[num[i]]=true;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<17; j++){
            if(vis[j]&&g[j][now]<min){
                pos=j;
                min=g[j][now];
            }
        }
//        cout<<now<<" "<<pos<<" "<<g[pos][now]<<endl;
        now=pos, ans+=min;
        vis[pos]=false;
        min=0x3f3f3f3f3f3f3f3f;
    }
    cout<<ans<<endl;
}

signed main(){
    int t;
    cin>>t;
    cin>>single>>line>>col>>all;
    int s[]={1, 2, 4, 8};
    int a[]={15};
    int l[2]={3, 12};
    int c[2]={5, 10};
    for(int i=0; i<16; i++){
        for(int j=0; j<16; j++){
            g[i][j]=0x3f3f3f3f3f3f3f3f;
        }
        for(int j=0; j<4; j++){
            g[i][i^s[j]]=min(g[i][i^s[j]], single);
        }
        for(int j=0; j<2; j++){
            g[i][i^l[j]]=min(g[i][i^l[j]], line);
            g[i][i^c[j]]=min(g[i][i^c[j]], col);
        }
        g[i][i^a[0]]=min(g[i][i^a[0]], all);
    }
    for(int k=0; k<16; k++){
        for(int i=0; i<16; i++){
            for(int j=0; j<16; j++){
                g[i][j]=min(g[i][j], g[i][k]+g[k][j]);
            }
        }
    }
//    cout<<g[16][15]<<endl;
//    cout<<"here"<<endl;
    while(t--){
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

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: 0ms
memory: 3800kb

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: 0ms
memory: 3516kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: -100
Wrong Answer
time: 30ms
memory: 3520kb

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

result:

wrong answer 6th numbers differ - expected: '36', found: '38'