QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#794102#9802. Light Up the GridxiaoyilangWA 35ms16316kbC++201.5kb2024-11-30 11:04:022024-11-30 11:04:05

Judging History

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

  • [2024-11-30 11:04:05]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:16316kb
  • [2024-11-30 11:04:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=16;
int T,m;
int a0,a1,a2,a3,h[N][N];
int dp[N][200005];
void init(){
	memset(h,0x3f,sizeof(h));
	int v1=min(a0,a1);
	int v2=min(a2,a3);
	for(int i=0;i<16;i++){
		for(int j=0;j<4;j++){
			int v=(i^(1<<j));
			h[i][v]=min(h[i][v],a0);
		}
		for(int j=0;j<4;j+=2){
			int v=(i^(1<<j));
			v=(v^(1<<(j+1)));
			h[i][v]=min(h[i][v],a1);
		}
		for(int j=0;j<2;j++){
			int v=(i^(1<<j));
			v=(v^(1<<(j+2)));
			h[i][v]=min(h[i][v],a2);
		}
		h[i][i^15]=min(h[i][i^15],a3);
	}
	for(int k=0;k<16;k++){
		for(int i=0;i<16;i++){
			for(int j=0;j<16;j++)
				h[i][j]=min(h[i][j],h[i][k]+h[k][j]);
		}
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	for(int j=0;j<(1<<16);j++){
		for(int i=0;i<16;i++){
			for(int k=0;k<16;k++){
				if((j>>k)&1)	continue;
				int v=15-(k^i);
				dp[i^v][j|(1<<k)]=min(dp[i^v][j|(1<<k)],dp[i][j]+h[i][i^v]);
			}
		}
	}
	return ;
}
void solve(){
	cin>>m;
	int sum=0;
	while(m--){
		string a,b;
		cin>>a>>b;
		int v=0;
		for(int i=0;i<2;i++){
			v=v*2+a[i]-'0'; 
		}
		for(int i=0;i<2;i++){
			v=v*2+b[i]-'0';
		}
		sum|=(1<<v);
	}
	int ans=1e9;
	for(int i=0;i<16;i++)	ans=min(ans,dp[i][sum]);
	ans=max(ans,2*min({a0,a1,a2,a3}));
	cout<<ans<<'\n';
	return ; 
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	int T;
	cin>>T>>a0>>a1>>a2>>a3;
	init();
	while(T--) solve();
	return 0;
} 
/*
1 8 2 7 8
8
00
01

00
11

00
10

11
11

10
10

01
10

01
00

10
11
*/

詳細信息

Test #1:

score: 100
Accepted
time: 29ms
memory: 16316kb

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

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

input:

1 1000000 1000000 1000000 1000000
1
11
11

output:

2000000

result:

ok 1 number(s): "2000000"

Test #4:

score: 0
Accepted
time: 30ms
memory: 16116kb

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: 34ms
memory: 16032kb

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: 34ms
memory: 16088kb

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: 34ms
memory: 16036kb

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

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: 34ms
memory: 16048kb

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: 33ms
memory: 16120kb

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

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: 0
Accepted
time: 31ms
memory: 16096kb

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:

ok 10000 numbers

Test #13:

score: 0
Accepted
time: 35ms
memory: 15988kb

input:

10000 28320 11478 7950 9407
11
00
10

11
00

01
01

11
11

10
11

11
10

00
01

01
10

01
11

00
11

10
00
8
00
11

11
10

00
00

00
01

10
01

11
11

01
01

01
00
8
01
10

10
11

11
10

01
00

00
01

10
00

01
01

00
10
11
01
01

11
11

10
11

00
11

00
01

10
10

11
01

00
10

10
00

11
10

01
10
...

output:

116333
88955
91026
114876
108383
91026
98976
116333
87498
117790
92483
94554
92483
92483
116333
108383
95397
108383
100433
109840
108383
108383
92483
106926
125740
116333
100433
109840
122826
92483
100433
108383
109840
93940
95448
93940
106926
109840
106926
108383
100433
103347
87498
106926
101890
1...

result:

ok 10000 numbers

Test #14:

score: 0
Accepted
time: 35ms
memory: 16288kb

input:

10000 117597 92204 151077 56217
11
00
01

10
11

11
10

10
01

01
10

10
10

00
11

01
00

11
00

00
00

00
10
10
11
11

01
11

10
10

00
11

01
00

11
10

11
00

01
01

11
01

01
10
12
11
01

11
00

01
10

10
11

11
10

01
11

00
11

11
11

10
00

00
01

01
01

10
01
9
11
10

00
00

10
10

00
10

1...

output:

910488
926245
1038679
798054
879664
798054
777824
762067
705850
946475
762067
859434
890258
854271
795547
705850
946475
777824
741837
741837
951638
926245
705850
798054
966705
762067
1002692
1115126
890258
736674
834041
798054
762067
762067
741837
767230
854271
910488
890258
762067
741837
762067
910...

result:

ok 10000 numbers

Test #15:

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

input:

10000 18 3 22 7
9
11
11

00
10

00
11

01
00

10
00

10
10

01
01

00
00

10
01
9
10
11

01
01

10
01

11
00

11
10

00
01

00
10

10
10

01
00
9
11
00

11
01

01
11

10
01

10
10

11
10

01
01

00
00

01
00
6
01
10

11
10

10
11

00
10

00
11

00
00
8
10
10

11
11

11
01

10
01

01
11

00
00

11
10...

output:

75
75
72
66
78
69
61
78
49
69
66
72
72
58
72
69
69
75
72
48
78
72
72
81
78
66
64
54
81
75
69
78
54
69
69
75
51
51
52
75
81
69
69
42
72
69
75
72
57
72
78
66
69
81
75
69
75
66
72
75
72
69
48
75
78
78
75
72
54
63
54
78
78
52
72
72
72
81
78
69
72
75
75
69
84
69
55
75
49
69
72
58
66
54
72
54
52
52
78
72
...

result:

wrong answer 3408th numbers differ - expected: '3', found: '6'