結果

問題 No.2094 Symmetry
ユーザー lanegue
提出日時 2022-10-07 22:35:17
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 183,248 KB
実行使用メモリ 11,996 KB
最終ジャッジ日時 2024-06-22 16:20:48
合計ジャッジ時間 6,708 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

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