QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800094#9802. Light Up the GridpemguimnWA 58ms19640kbC++142.1kb2024-12-05 21:36:302024-12-05 21:36:32

Judging History

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

  • [2024-12-05 21:36:32]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:19640kb
  • [2024-12-05 21:36:30]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int, int>

using namespace std;

const int INF = 1e9 + 7, M = 16, COMPLETE = 1 << 15;

vector<pii> edge;
vector<pii> adj[1 << M];

int d[1 << M];
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t, a1, a2, a3, a4; cin >> t >> a1 >> a2 >> a3 >> a4;


    for(int i = 0; i < 4; i++) edge.push_back({a1, (1 << i)});
    for(int i = 0; i < 4; i += 2) edge.push_back({a2, (1 << i) | (1 << (i + 1))});
    for(int i = 0; i < 2; i += 1) edge.push_back({a3, (1 << i) | (1 << (i + 2))});
    edge.push_back({a4, (1 << 4) - 1});

    vector<int> x;
    for(int mask = 0; mask < (1 << M); mask++){
        for(int i = 0; i < M; i++){
            if(mask & (1 << i)) x.push_back(i);
        }
        for(pii e : edge){
            int nmask = 0;
            for(int y : x){
                if((y ^ e.second) != 15) nmask |= (1 << (y ^ e.second));
            }
            adj[nmask].push_back({mask, e.first});
            adj[mask].push_back({nmask, e.first});
        }
        x.clear();
    }

    for(int i = 0; i < 1 << M; i++) d[i] = INF;
    d[COMPLETE] = 0; priority_queue<pii> pq;
    pq.push({-d[COMPLETE], COMPLETE});
    while(!pq.empty()){
        pii cur = pq.top(); pq.pop();
        if(-cur.first != d[cur.second]) continue;
        int mask = cur.second;
        for(pii e : adj[mask]){
            if(d[e.first] > d[mask] + e.second){
                d[e.first] = d[mask] + e.second;
                pq.push({-d[e.first], e.first});
            }
        }
    }
    for(int i = 1; i <= t; i++){
        int m; cin >> m;
        int mask = 0;
        while(m--){
            int bit = 0;
            for(int r = 0; r < 2; r++){
                for(int c = 0; c < 2; c++){
                    char ch; cin >> ch;
                    bit |= ((ch - '0') << (r * 2 + c));
                }
            }
            mask |= (1 << bit);
        }
        if(mask == COMPLETE) cout << d[1] * 2 << "\n";
        else cout << d[mask] << '\n';
    }
    return 0;
}

/*
2 1000 100 10 1
4
10
00

01
00

00
10

00
01

1
11
11
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 49ms
memory: 19244kb

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: 39ms
memory: 19164kb

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: 19396kb

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: 0
Accepted
time: 50ms
memory: 19212kb

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
37
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:

ok 10000 numbers

Test #5:

score: 0
Accepted
time: 45ms
memory: 19108kb

input:

10000 73 78 73 17
11
01
10

01
11

10
00

11
11

00
00

11
01

10
11

11
10

00
11

10
01

01
00
6
00
00

10
11

11
10

01
01

11
01

11
00
7
01
11

01
00

10
00

10
11

10
10

00
00

01
01
10
10
01

10
10

00
10

10
11

10
00

01
01

01
10

11
11

11
00

00
01
10
11
11

01
11

10
10

01
01

00
01

...

output:

523
382
287
579
523
596
343
275
343
472
382
343
455
326
433
360
579
545
506
523
326
528
467
382
438
421
377
460
416
579
489
596
309
326
326
596
438
387
506
562
523
377
416
309
523
348
365
343
416
392
343
399
348
506
421
596
450
426
579
370
506
185
489
377
489
387
416
472
314
489
506
450
421
433
416
...

result:

ok 10000 numbers

Test #6:

score: 0
Accepted
time: 50ms
memory: 19336kb

input:

10000 701 328 455 703
7
10
11

00
01

00
11

00
10

01
00

11
11

11
00
7
00
01

01
00

00
11

11
11

00
00

11
10

11
01
6
01
10

01
01

00
01

00
11

10
01

11
00
8
00
11

10
11

00
10

00
01

11
10

01
01

10
10

11
00
5
00
11

10
11

11
00

01
10

01
00
7
00
01

10
10

11
01

00
10

10
00

11
11...

output:

3124
3124
2595
4153
2595
3177
3907
2796
4235
3833
3296
2595
4809
3579
3579
3050
3169
3907
3907
3251
3169
2714
2595
3050
3251
3542
2796
3251
4563
3251
3452
3907
3251
3251
4034
4034
1730
2140
3087
4153
3907
3907
4727
4809
2923
3497
3579
3431
3251
4235
2267
4354
2595
4153
3169
4727
3087
4235
3579
2595
...

result:

ok 10000 numbers

Test #7:

score: 0
Accepted
time: 58ms
memory: 19176kb

input:

10000 6459 225 8979 7226
16
00
11

11
01

10
01

10
10

00
01

01
11

11
00

11
11

00
10

11
10

01
01

01
00

01
10

10
00

00
00

10
11
16
10
00

11
10

01
10

11
11

00
01

00
00

01
00

01
11

01
01

10
01

00
10

10
10

00
11

11
01

10
11

11
00
16
10
11

01
11

10
00

10
10

01
00

11
11

01...

output:

22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
22302
...

result:

ok 10000 numbers

Test #8:

score: 0
Accepted
time: 46ms
memory: 19560kb

input:

10000 47809 35506 569 26740
5
00
01

10
10

11
01

11
11

00
11
8
11
01

10
10

11
00

01
00

10
01

01
10

10
00

00
10
6
01
10

11
00

00
11

11
11

10
01

01
01
8
00
10

10
01

01
10

10
11

00
00

00
11

01
01

11
10
6
01
11

10
01

00
10

00
00

10
00

01
10
8
00
01

01
10

01
11

00
00

10
10
...

output:

119959
122235
38351
122235
87298
122235
122804
122804
122804
85591
123373
123942
121097
86160
122235
123942
122235
85591
86729
124511
122804
122235
88436
123373
122804
122235
124511
85591
121666
49516
122235
122235
122235
121666
86160
121097
125649
123373
87867
121097
123373
123942
123373
120528
123...

result:

ok 10000 numbers

Test #9:

score: 0
Accepted
time: 52ms
memory: 19640kb

input:

10000 947705 1031 121092 212797
8
00
01

10
11

01
11

01
01

00
10

11
10

11
00

01
10
10
00
10

11
01

10
11

00
11

01
00

11
11

00
00

10
01

00
01

10
00
8
11
11

11
00

01
11

10
10

10
11

01
01

00
01

10
00
8
01
00

11
00

00
01

11
01

01
01

10
11

10
01

11
11
8
00
01

11
11

11
10

00...

output:

1195044
1200199
1197106
1196075
1074983
1199168
1197106
1198137
1201230
1197106
1199168
1197106
1195044
1198137
1197106
1197106
1199168
1198137
1198137
1198137
1076014
1196075
1199168
1197106
1197106
1197106
1197106
1195044
1198137
1198137
1200199
1196075
1202261
1198137
1198137
1199168
1196075
1196...

result:

ok 10000 numbers

Test #10:

score: 0
Accepted
time: 55ms
memory: 19432kb

input:

10000 9 3 5 10
16
01
11

10
11

11
00

00
10

01
01

01
10

10
10

00
11

11
10

00
01

01
00

11
01

10
01

10
00

00
00

11
11
16
11
11

00
10

01
01

01
00

10
10

10
01

11
10

11
01

11
00

10
11

01
10

01
11

10
00

00
00

00
11

00
01
16
00
00

11
00

00
10

10
11

11
10

01
11

01
00

10
00...

output:

58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
58
...

result:

ok 10000 numbers

Test #11:

score: 0
Accepted
time: 49ms
memory: 19216kb

input:

10000 366 23 191 94
10
10
10

11
11

10
01

11
01

00
10

10
00

01
11

11
10

00
11

10
11
9
00
00

00
01

11
00

11
10

01
10

11
11

10
11

01
11

00
10
12
11
01

01
00

00
11

00
00

11
10

01
11

11
11

00
10

00
01

10
10

01
01

01
10
9
11
01

01
01

00
10

10
11

11
10

01
10

11
00

11
11

...

output:

909
932
978
886
886
932
909
863
932
863
886
955
886
932
955
909
978
909
932
909
932
955
863
978
909
932
863
886
978
955
863
932
932
718
955
718
932
909
955
932
978
932
886
932
1024
932
932
932
1001
718
955
886
909
909
909
978
978
764
978
863
909
955
909
932
886
978
955
909
718
978
863
932
1001
1001
...

result:

ok 10000 numbers

Test #12:

score: -100
Wrong Answer
time: 47ms
memory: 19380kb

input:

10000 2191 1820 866 884
6
11
00

10
10

01
11

00
11

11
10

11
11
6
00
01

01
10

10
10

00
10

00
11

11
10
8
01
11

11
00

10
11

11
01

01
01

01
10

10
00

01
00
9
10
10

11
01

10
00

01
10

11
11

11
00

01
00

01
11

01
01
7
01
10

00
01

10
11

11
00

00
00

11
10

10
10
7
01
10

00
10

00
...

output:

9189
8447
10179
11027
8341
9331
11099
12282
13625
7068
10055
11027
8447
12759
9313
11045
11911
11063
8341
11929
9225
8359
11027
8818
10179
9666
6609
10903
12759
11063
9295
10957
12777
12795
13625
6132
8377
9189
11823
9331
10179
13625
6609
13661
6609
8447
9738
9295
10091
10197
9331
8818
8818
13148
74...

result:

wrong answer 6071st numbers differ - expected: '1732', found: '1768'