結果

問題 No.2094 Symmetry
ユーザー laneguelanegue
提出日時 2022-10-07 22:35:17
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 2,384 ms
コンパイル使用メモリ 171,712 KB
実行使用メモリ 13,004 KB
最終ジャッジ日時 2023-09-04 18:31:18
合計ジャッジ時間 10,072 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 107 ms
12,304 KB
testcase_10 AC 106 ms
12,032 KB
testcase_11 AC 106 ms
11,272 KB
testcase_12 AC 106 ms
12,492 KB
testcase_13 AC 87 ms
12,008 KB
testcase_14 AC 106 ms
12,324 KB
testcase_15 AC 106 ms
12,056 KB
testcase_16 AC 106 ms
11,508 KB
testcase_17 AC 87 ms
11,212 KB
testcase_18 AC 88 ms
12,000 KB
testcase_19 AC 107 ms
12,264 KB
testcase_20 AC 107 ms
11,800 KB
testcase_21 AC 107 ms
12,032 KB
testcase_22 AC 106 ms
12,324 KB
testcase_23 AC 87 ms
10,460 KB
testcase_24 AC 87 ms
10,988 KB
testcase_25 AC 107 ms
11,992 KB
testcase_26 AC 106 ms
11,804 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 71 ms
12,324 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 73 ms
11,476 KB
testcase_31 AC 71 ms
11,472 KB
testcase_32 AC 74 ms
11,748 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 57 ms
13,004 KB
testcase_35 AC 47 ms
12,356 KB
testcase_36 AC 44 ms
10,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;
void main(){
	auto a = readln.split.to!(long[]);
	auto N = a[0];
	auto K = a[1];
	long black = 0;
	for(auto i = 0; i < 2 * N; i++){
		auto s = readln.chomp;
		black += s.count('#');
	}
	long[][] C;
	for(auto i = 0; i < 2 * N; i++){
		C ~= readln.split.to!(long[]);
	}
	//stderr.writeln(C);
	auto gr = greedy(C, black);
	//stderr.writeln(gr);
	auto sy = symmetry(C, black) + K;
	//stderr.writeln(sy);
	writeln(max(gr, sy));
}

long greedy(long[][] c, long black){
	auto a = c.join;
	a.sort!((x, y) => x > y);
	//stderr.writeln(a);
	return a[0 .. black].sum;
}

long symmetry(long[][] c, long black){
	if(black % 2) return long.min;
	long[] a;
	for(auto i = 0; i < c.length; i++){
		for(auto j = 0; j < c[i].length / 2; j++){
			a ~= c[i][j] + c[i][$ - 1 - j];
		}
	}
	a.sort!((x, y) => x > y);
	//stderr.writeln(a);
	return a[0 .. (black / 2)].sum;
}
0