結果

問題 No.1345 Beautiful BINGO
ユーザー さかぽんさかぽん
提出日時 2021-01-24 20:55:42
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,351 bytes
コンパイル時間 3,157 ms
コンパイル使用メモリ 108,172 KB
実行使用メモリ 29,880 KB
最終ジャッジ日時 2023-09-02 08:02:00
合計ジャッジ時間 37,319 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
21,676 KB
testcase_01 AC 66 ms
21,784 KB
testcase_02 AC 65 ms
21,860 KB
testcase_03 AC 65 ms
21,864 KB
testcase_04 AC 64 ms
21,676 KB
testcase_05 AC 66 ms
21,744 KB
testcase_06 AC 64 ms
21,668 KB
testcase_07 AC 71 ms
25,708 KB
testcase_08 AC 65 ms
21,820 KB
testcase_09 AC 66 ms
21,836 KB
testcase_10 AC 66 ms
19,784 KB
testcase_11 AC 67 ms
21,748 KB
testcase_12 AC 65 ms
21,820 KB
testcase_13 AC 70 ms
23,924 KB
testcase_14 AC 66 ms
23,652 KB
testcase_15 AC 65 ms
21,880 KB
testcase_16 AC 67 ms
21,820 KB
testcase_17 AC 66 ms
21,788 KB
testcase_18 AC 65 ms
21,712 KB
testcase_19 AC 66 ms
21,664 KB
testcase_20 AC 68 ms
21,876 KB
testcase_21 AC 66 ms
21,824 KB
testcase_22 AC 69 ms
21,860 KB
testcase_23 AC 112 ms
25,968 KB
testcase_24 AC 97 ms
25,844 KB
testcase_25 AC 113 ms
23,844 KB
testcase_26 AC 643 ms
27,836 KB
testcase_27 TLE -
testcase_28 AC 78 ms
23,932 KB
testcase_29 AC 628 ms
27,944 KB
testcase_30 AC 71 ms
23,788 KB
testcase_31 AC 81 ms
27,900 KB
testcase_32 AC 79 ms
27,884 KB
testcase_33 TLE -
testcase_34 AC 67 ms
23,776 KB
testcase_35 AC 69 ms
23,824 KB
testcase_36 AC 667 ms
25,920 KB
testcase_37 AC 66 ms
21,728 KB
testcase_38 AC 575 ms
27,932 KB
testcase_39 TLE -
testcase_40 AC 1,318 ms
25,880 KB
testcase_41 AC 651 ms
27,808 KB
testcase_42 AC 64 ms
21,844 KB
testcase_43 AC 66 ms
21,744 KB
testcase_44 AC 65 ms
21,744 KB
testcase_45 AC 65 ms
23,728 KB
testcase_46 AC 66 ms
21,888 KB
testcase_47 AC 66 ms
21,684 KB
testcase_48 AC 65 ms
23,784 KB
testcase_49 AC 64 ms
21,856 KB
testcase_50 AC 63 ms
21,724 KB
testcase_51 AC 66 ms
19,624 KB
testcase_52 AC 112 ms
25,968 KB
testcase_53 TLE -
testcase_54 AC 446 ms
25,644 KB
testcase_55 AC 1,165 ms
25,992 KB
testcase_56 AC 114 ms
23,652 KB
testcase_57 TLE -
testcase_58 TLE -
testcase_59 TLE -
testcase_60 AC 1,071 ms
27,940 KB
testcase_61 AC 1,778 ms
27,744 KB
testcase_62 AC 117 ms
25,960 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 + n < m || 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