QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#473557#2989. 一双木棋Idtwtei80 2ms8376kbC++201.1kb2024-07-12 09:55:302024-07-12 09:55:30

Judging History

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

  • [2024-07-12 09:55:30]
  • 评测
  • 测评结果:80
  • 用时:2ms
  • 内存:8376kb
  • [2024-07-12 09:55:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=10,M=1024+100,INF=1e9;
int in(int S,int x){ return (S>>x)&1; }

int n,m,mp[2][N][N];

int f[M][M];
int dfs(int X,int Y,int peo){
	int &res=f[X][Y];
	if(res!=INF+1) return res; res=-INF;
	int mpx[N],mpy[N];
	int cnt=0; for(int i=0;i<n;i++) if(in(X,i)) mpx[++cnt]=i;
	cnt=0; for(int i=m-1;i>=0;i--) if(in(Y,i)) mpy[++cnt]=i;
	for(int i=1;i<=cnt;i++){
		int NX=X^(1<<mpx[i]),NY=Y^(1<<mpy[i]);
		if(mpx[i]+1<n&&!in(NX,mpx[i]+1)) NX^=(1<<(mpx[i]+1)),NY^=(1<<mpy[i]);
		if(mpy[i]+1<m&&!in(NY,mpy[i]+1)) NY^=(1<<(mpy[i]+1)),NX^=(1<<mpx[i]);
		dfs(NX,NY,peo^1);
		res=max(res,mp[peo][mpx[i]][mpy[i]]-f[NX][NY]);
	}
	return res;
}

int main(){
	
//	freopen("data.out","r",stdin);
//	freopen("Elaina.out","w",stdout);

	scanf("%d %d", &n, &m);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d", &mp[1][i][j]);
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d", &mp[0][i][j]);
	
	for(int i=0;i<(1<<n);i++) for(int j=0;j<(1<<m);j++) f[i][j]=INF+1;
	f[0][0]=0;
	
	printf("%d\n", dfs(1,1,1));
	
	return 0;
}

详细

Test #1:

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

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

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

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

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

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

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

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

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: 2ms
memory: 5080kb

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: 2ms
memory: 6208kb

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: 1ms
memory: 8284kb

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: 2ms
memory: 8188kb

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

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

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: 1ms
memory: 8204kb

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: 1ms
memory: 8376kb

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: 0
Runtime Error

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:


result:


Test #18:

score: 0
Runtime Error

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:


result:


Test #19:

score: 0
Runtime Error

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:


result:


Test #20:

score: 0
Runtime Error

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:


result: