QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#501543#2989. 一双木棋PPPxvchongyv100 ✓167ms15168kbC++141.0kb2024-08-02 20:33:462024-08-02 20:33:47

Judging History

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

  • [2024-08-02 20:33:47]
  • 评测
  • 测评结果:100
  • 用时:167ms
  • 内存:15168kb
  • [2024-08-02 20:33:46]
  • 提交

answer

#include <bits/stdc++.h>
int n, m, a[16][16], b[16][16];
std::map<long long, int> f;
int solve(long long t, bool g) {
	if(f.find(t) != f.end())
		return f[t];
	if(t == 0)
		return 0;
	int res = 0;
	if(g) {
		res = -998244353;
		for(int i = 0; i < n; i++) {
			long long	o = t >> (i << 2) & 15,
						p = t >> (i + 1 << 2) & 15;
			if(o > p)
				res = std::max(res, solve(t - (1LL << (i << 2)), !g) + a[i][o]);
		}
	} else {
		res = 998244353;
		for(int i = 0; i < n; i++) {
			long long	o = t >> (i << 2) & 15,
						p = t >> (i + 1 << 2) & 15;
			if(o > p)
				res = std::min(res, solve(t - (1LL << (i << 2)), !g) - b[i][o]);
		}
	}
	return f[t] = res;
}
int main() {
	std::cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 1; j <= m; j++)
			std::cin >> a[n - i - 1][m - j + 1];
	for(int i = 0; i < n; i++)
		for(int j = 1; j <= m; j++)
			std::cin >> b[n - i - 1][m - j + 1];
	long long y = 0;
	for(int i = 1; i <= n; i++)
		y = y << 4 | m;
	std::cout << solve(y, 1) << '\n';
	return 0;
}
/*
2 3
2 7 3
9 1 2
3 7 2
2 3 1
*/

详细


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 3608kb

input:

2 2
48316 18516
34352 3263
0 0
0 0

output:

66832

result:

ok single line: '66832'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3628kb

input:

2 2
75925 18128
38471 42651
53412 27561
35202 23268

output:

35583

result:

ok single line: '35583'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3628kb

input:

2 2
68736 95419
18197 87453
0 0
0 0

output:

86933

result:

ok single line: '86933'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

3 3
30347 75845 36131
48118 6205 51826
7486 40480 58445
89340 63578 42185
78864 73882 44618
53322 6677 35054

output:

-8228

result:

ok single line: '-8228'

Test #5:

score: 5
Accepted
time: 0ms
memory: 3612kb

input:

3 3
96942 46732 31592
65874 7883 73289
44414 59236 9197
0 0 0
0 0 0
0 0 0

output:

255434

result:

ok single line: '255434'

Test #6:

score: 5
Accepted
time: 0ms
memory: 3596kb

input:

3 3
28852 97109 77805
45967 58092 74930
95287 65144 94993
95970 74589 85144
18946 50383 94031
79115 82328 32425

output:

145621

result:

ok single line: '145621'

Test #7:

score: 5
Accepted
time: 0ms
memory: 3624kb

input:

5 5
55928 35560 62780 77747 93320
2289 92078 11794 37512 63980
31076 40385 93729 16608 84575
21616 36427 52988 35960 23350
70170 30827 6468 46707 74459
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

output:

783702

result:

ok single line: '783702'

Test #8:

score: 5
Accepted
time: 0ms
memory: 3620kb

input:

5 5
69957 90847 86904 93073 40245
28329 60126 87118 6014 47716
44211 82632 7048 25316 18026
35996 66957 93148 28942 76653
24567 48573 21080 27648 79677
39142 22319 55890 94565 5578
43866 63511 78176 77389 67802
3878 89158 53308 62879 79293
72274 15472 6456 52791 12740
79970 46577 95439 33488 75518

output:

32290

result:

ok single line: '32290'

Test #9:

score: 5
Accepted
time: 8ms
memory: 4424kb

input:

8 8
86108 81572 62938 40758 11532 21392 3581 2504
21005 70268 95734 70594 56220 90574 91914 5991
38371 69652 23397 46886 40865 53758 18445 39947
2301 13696 50188 33660 76692 5028 28616 79962
5316 54006 78086 86163 74562 7894 6618 13992
57283 96786 75838 91328 24732 66214 68383 61101
83739 36224 7365...

output:

1488231

result:

ok single line: '1488231'

Test #10:

score: 5
Accepted
time: 8ms
memory: 4336kb

input:

8 8
72263 8419 55507 20324 91755 52440 23833 40787
43896 76816 36755 55447 37493 25197 28806 8158
25187 67254 96533 11633 87146 19947 60933 61777
93331 60407 66650 81711 67421 75937 3204 31741
45644 25632 25607 79091 31101 58533 33858 39864
83305 9970 19125 98016 8962 25312 80555 98895
18430 43522 1...

output:

-459277

result:

ok single line: '-459277'

Test #11:

score: 5
Accepted
time: 0ms
memory: 3692kb

input:

10 1
26741
44875
46290
5961
14706
99723
79560
57538
8382
9583
0
0
0
0
0
0
0
0
0
0

output:

175679

result:

ok single line: '175679'

Test #12:

score: 5
Accepted
time: 0ms
memory: 3492kb

input:

10 1
8919
95688
93267
67099
7408
10592
47300
98255
90780
39444
25459
53053
67109
26951
85889
45189
75775
50663
66822
60054

output:

11764

result:

ok single line: '11764'

Test #13:

score: 5
Accepted
time: 0ms
memory: 3500kb

input:

10 2
66632 75577
25326 3304
12313 50122
45692 8004
43057 30880
27358 24369
19875 28212
13557 85685
49418 78047
261 93322
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

output:

303489

result:

ok single line: '303489'

Test #14:

score: 5
Accepted
time: 0ms
memory: 3576kb

input:

10 2
25734 42462
8713 55503
20831 23987
70428 5903
83351 5980
83772 5612
42644 46237
43480 78535
19670 62712
53134 10822
39935 37169
12368 43173
12082 70592
94150 57635
92408 66732
34779 36045
36700 99138
18012 10524
94630 67847
53753 67290

output:

-147563

result:

ok single line: '-147563'

Test #15:

score: 5
Accepted
time: 0ms
memory: 3556kb

input:

10 3
54823 79443 61975
38396 80442 36722
39245 81935 39586
29086 91631 43723
10958 41722 76983
24586 36385 93874
55653 63080 84968
34760 64396 3608
30891 84631 40934
82340 61893 46524
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0

output:

795554

result:

ok single line: '795554'

Test #16:

score: 5
Accepted
time: 0ms
memory: 3616kb

input:

10 3
15434 56518 19173
63657 66591 25524
52687 46377 21073
25206 53123 66671
38596 34739 72614
96706 6021 85095
4124 89829 48403
38150 15093 18712
51382 24338 30286
47130 39038 3832
21965 29454 79841
14161 76084 5510
66024 38502 96571
85937 55212 56427
25329 62587 88640
41121 73634 66947
21217 32703...

output:

-290764

result:

ok single line: '-290764'

Test #17:

score: 5
Accepted
time: 167ms
memory: 15044kb

input:

10 10
43160 45942 25141 50836 26666 78029 12721 4060 47766 38519
28905 65543 95241 88277 30507 45604 22707 25934 46518 13090
98505 23934 17519 85400 67853 49111 19614 75664 84998 98627
58475 42511 85657 39342 35060 66998 41228 16873 88181 36244
33724 98601 65211 64329 12231 25041 57657 33323 32086 9...

output:

2314220

result:

ok single line: '2314220'

Test #18:

score: 5
Accepted
time: 163ms
memory: 15040kb

input:

10 10
70388 78095 16286 35188 72693 40763 98905 1023 65024 81842
53222 18629 20665 77097 41261 75861 40355 56217 80207 40759
77986 26227 84790 23663 93662 20282 61248 48145 68547 41170
64745 34107 19239 33868 8082 12212 50633 22908 30293 5248
33110 94868 72727 62632 96809 25113 85890 62667 43510 811...

output:

-633988

result:

ok single line: '-633988'

Test #19:

score: 5
Accepted
time: 163ms
memory: 15040kb

input:

10 10
73014 81755 69006 80227 53814 27348 35895 72225 44812 88805
46580 26594 98521 91734 45006 95725 83991 93222 31280 42881
1930 4436 14909 30601 47389 69949 95259 44800 40302 49192
7321 87219 55625 68368 74472 97075 84918 24964 75871 34301
25844 4678 18311 10928 22967 77535 89398 18506 95071 6706...

output:

2365561

result:

ok single line: '2365561'

Test #20:

score: 5
Accepted
time: 158ms
memory: 15168kb

input:

10 10
27529 95558 10391 83912 84199 11266 31322 29230 3717 17653
99818 93168 68278 68079 2991 59925 54348 68141 65949 46561
64979 83072 67821 31192 27141 9762 57620 88326 86972 90315
8756 61729 66442 11671 42697 15428 81717 40639 97733 75316
47835 12306 76669 33750 16018 7878 4065 57240 94357 18110
...

output:

-654047

result:

ok single line: '-654047'