結果

問題 No.1345 Beautiful BINGO
ユーザー さかぽんさかぽん
提出日時 2021-01-24 19:28:36
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,334 bytes
コンパイル時間 4,589 ms
コンパイル使用メモリ 107,532 KB
実行使用メモリ 29,872 KB
最終ジャッジ日時 2023-09-01 23:15:12
合計ジャッジ時間 47,484 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
21,676 KB
testcase_01 AC 65 ms
21,740 KB
testcase_02 AC 65 ms
21,676 KB
testcase_03 AC 66 ms
21,716 KB
testcase_04 AC 65 ms
23,716 KB
testcase_05 AC 65 ms
21,684 KB
testcase_06 AC 64 ms
21,648 KB
testcase_07 AC 69 ms
23,668 KB
testcase_08 AC 67 ms
21,844 KB
testcase_09 AC 66 ms
19,676 KB
testcase_10 AC 66 ms
21,600 KB
testcase_11 AC 68 ms
23,728 KB
testcase_12 AC 66 ms
21,736 KB
testcase_13 AC 69 ms
23,736 KB
testcase_14 AC 66 ms
23,636 KB
testcase_15 AC 65 ms
21,656 KB
testcase_16 AC 66 ms
21,724 KB
testcase_17 AC 67 ms
19,752 KB
testcase_18 AC 67 ms
21,808 KB
testcase_19 AC 66 ms
21,676 KB
testcase_20 AC 66 ms
21,584 KB
testcase_21 AC 67 ms
23,612 KB
testcase_22 AC 180 ms
27,816 KB
testcase_23 TLE -
testcase_24 AC 1,311 ms
27,804 KB
testcase_25 AC 116 ms
25,776 KB
testcase_26 AC 624 ms
27,832 KB
testcase_27 TLE -
testcase_28 AC 119 ms
25,756 KB
testcase_29 AC 623 ms
25,776 KB
testcase_30 AC 319 ms
29,824 KB
testcase_31 AC 181 ms
27,752 KB
testcase_32 AC 76 ms
27,756 KB
testcase_33 TLE -
testcase_34 AC 87 ms
23,812 KB
testcase_35 AC 86 ms
27,760 KB
testcase_36 AC 669 ms
25,800 KB
testcase_37 AC 67 ms
21,672 KB
testcase_38 AC 627 ms
23,792 KB
testcase_39 TLE -
testcase_40 AC 1,316 ms
27,768 KB
testcase_41 AC 658 ms
25,968 KB
testcase_42 AC 66 ms
21,684 KB
testcase_43 AC 66 ms
21,576 KB
testcase_44 AC 65 ms
21,596 KB
testcase_45 AC 66 ms
21,768 KB
testcase_46 AC 66 ms
23,856 KB
testcase_47 AC 66 ms
21,652 KB
testcase_48 AC 67 ms
23,768 KB
testcase_49 AC 67 ms
21,848 KB
testcase_50 AC 66 ms
21,820 KB
testcase_51 AC 65 ms
21,692 KB
testcase_52 AC 113 ms
27,864 KB
testcase_53 TLE -
testcase_54 TLE -
testcase_55 TLE -
testcase_56 AC 111 ms
27,820 KB
testcase_57 TLE -
testcase_58 TLE -
testcase_59 TLE -
testcase_60 AC 1,061 ms
25,808 KB
testcase_61 TLE -
testcase_62 AC 113 ms
25,796 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Linq;

class D
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main()
	{
		var (n, m) = Read2();
		var a = Array.ConvertAll(new bool[n], _ => Read());
		var rowSums = a.Select(v => v.Sum()).ToArray();

		var min = 1 << 30;
		var b = new bool[n, n];
		var rn = Enumerable.Range(0, n).ToArray();

		for (int x = 0; x < 1 << n + 2; x++)
		{
			Array.Clear(b, 0, n * n);
			var count = FlagCount(x);
			if (count > m) continue;

			for (int j = 0; j < n; j++)
			{
				if ((x & (1 << j)) == 0) continue;
				for (int i = 0; i < n; i++) b[i, j] = true;
			}
			if ((x & (1 << n)) != 0)
			{
				for (int i = 0; i < n; i++) b[i, i] = true;
			}
			if ((x & (1 << n + 1)) != 0)
			{
				for (int i = 0; i < n; i++) b[i, n - 1 - i] = true;
			}

			var rows = Array.ConvertAll(rn, i => rn.Sum(j => b[i, j] ? a[i][j] : 0));
			var sum = rows.Sum();
			if (count == m) { min = Math.Min(min, sum); continue; }

			var diffs = Array.ConvertAll(rn, i => rowSums[i] - rows[i]);
			Array.Sort(diffs);
			min = Math.Min(min, sum + diffs.Take(m - count).Sum());
		}

		Console.WriteLine(min);
	}

	static int FlagCount(int x)
	{
		var r = 0;
		for (; x != 0; x >>= 1) if ((x & 1) != 0) ++r;
		return r;
	}
}
0