結果

問題 No.1345 Beautiful BINGO
ユーザー さかぽんさかぽん
提出日時 2021-01-24 21:01:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,222 ms / 2,000 ms
コード長 1,419 bytes
コンパイル時間 4,616 ms
コンパイル使用メモリ 106,980 KB
実行使用メモリ 28,028 KB
最終ジャッジ日時 2023-09-02 08:08:13
合計ジャッジ時間 22,378 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
21,724 KB
testcase_01 AC 66 ms
21,720 KB
testcase_02 AC 66 ms
21,884 KB
testcase_03 AC 66 ms
23,860 KB
testcase_04 AC 66 ms
21,760 KB
testcase_05 AC 66 ms
21,696 KB
testcase_06 AC 66 ms
23,760 KB
testcase_07 AC 67 ms
21,716 KB
testcase_08 AC 66 ms
21,768 KB
testcase_09 AC 66 ms
21,716 KB
testcase_10 AC 66 ms
23,884 KB
testcase_11 AC 67 ms
23,764 KB
testcase_12 AC 67 ms
23,684 KB
testcase_13 AC 68 ms
19,684 KB
testcase_14 AC 67 ms
23,772 KB
testcase_15 AC 65 ms
21,588 KB
testcase_16 AC 66 ms
21,724 KB
testcase_17 AC 65 ms
23,760 KB
testcase_18 AC 65 ms
21,776 KB
testcase_19 AC 67 ms
23,752 KB
testcase_20 AC 66 ms
21,716 KB
testcase_21 AC 65 ms
23,748 KB
testcase_22 AC 66 ms
21,756 KB
testcase_23 AC 92 ms
25,812 KB
testcase_24 AC 83 ms
25,924 KB
testcase_25 AC 88 ms
25,928 KB
testcase_26 AC 303 ms
23,876 KB
testcase_27 AC 1,167 ms
27,864 KB
testcase_28 AC 70 ms
23,692 KB
testcase_29 AC 308 ms
27,872 KB
testcase_30 AC 70 ms
21,772 KB
testcase_31 AC 72 ms
21,692 KB
testcase_32 AC 70 ms
21,788 KB
testcase_33 AC 1,150 ms
25,928 KB
testcase_34 AC 67 ms
23,804 KB
testcase_35 AC 67 ms
23,712 KB
testcase_36 AC 300 ms
25,816 KB
testcase_37 AC 67 ms
21,708 KB
testcase_38 AC 284 ms
27,884 KB
testcase_39 AC 1,169 ms
25,824 KB
testcase_40 AC 591 ms
23,884 KB
testcase_41 AC 286 ms
23,916 KB
testcase_42 AC 66 ms
21,748 KB
testcase_43 AC 66 ms
21,712 KB
testcase_44 AC 65 ms
19,656 KB
testcase_45 AC 65 ms
21,744 KB
testcase_46 AC 66 ms
21,720 KB
testcase_47 AC 65 ms
19,660 KB
testcase_48 AC 66 ms
21,844 KB
testcase_49 AC 65 ms
21,844 KB
testcase_50 AC 66 ms
23,752 KB
testcase_51 AC 66 ms
23,776 KB
testcase_52 AC 94 ms
28,028 KB
testcase_53 AC 1,222 ms
27,952 KB
testcase_54 AC 234 ms
27,852 KB
testcase_55 AC 571 ms
27,788 KB
testcase_56 AC 93 ms
27,856 KB
testcase_57 AC 1,124 ms
27,868 KB
testcase_58 AC 1,164 ms
25,924 KB
testcase_59 AC 1,141 ms
25,844 KB
testcase_60 AC 461 ms
27,932 KB
testcase_61 AC 791 ms
27,844 KB
testcase_62 AC 94 ms
25,936 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++)
		{
			var count = FlagCount(x);
			if (count + n < m || count > m) continue;

			Array.Clear(b, 0, n * n);
			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 =>
			{
				var s = 0;
				for (int j = 0; j < n; j++)
					if (b[i, j]) s += a[i][j];
				return s;
			});
			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