結果

問題 No.1345 Beautiful BINGO
ユーザー tkmst201tkmst201
提出日時 2021-02-02 23:03:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 205,500 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 11:27:53
合計ジャッジ時間 9,567 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 21 ms
4,376 KB
testcase_23 AC 421 ms
4,380 KB
testcase_24 AC 196 ms
4,376 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 86 ms
4,376 KB
testcase_27 AC 364 ms
4,380 KB
testcase_28 AC 10 ms
4,376 KB
testcase_29 AC 87 ms
4,376 KB
testcase_30 AC 43 ms
4,380 KB
testcase_31 AC 20 ms
4,376 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 363 ms
4,380 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 94 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 89 ms
4,376 KB
testcase_39 AC 371 ms
4,380 KB
testcase_40 AC 190 ms
4,384 KB
testcase_41 AC 89 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 6 ms
4,376 KB
testcase_53 AC 382 ms
4,380 KB
testcase_54 AC 425 ms
4,380 KB
testcase_55 AC 411 ms
4,380 KB
testcase_56 AC 7 ms
4,380 KB
testcase_57 AC 350 ms
4,376 KB
testcase_58 AC 406 ms
4,376 KB
testcase_59 AC 358 ms
4,376 KB
testcase_60 AC 153 ms
4,376 KB
testcase_61 AC 415 ms
4,376 KB
testcase_62 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	vector A(N, vector<int>(N));
	REP(i, N) REP(j, N) scanf("%d", &A[i][j]);
	vector<int> sum(N); // 行
	REP(i, N) REP(j, N) sum[i] += A[i][j];
	
	int ans = INF;
	REP(i, 1 << N) { // 列
		REP(j, 4) { // 1:右下(+1,+1), 2:左下(+1,-1)
			int res = M;
			REP(k, N) if (i >> k & 1) --res;
			if (j & 1) --res;
			if (j & 2) --res;
			if (res < 0) continue;
			priority_queue<int, vector<int>, greater<int>> pq;
			int cur = 0;
			REP(k, N) { // 行
				int cost = sum[k];
				REP(l, N) if ((i >> l & 1) || (j & 1) && k == l || (j & 2) && N - 1 - k == l) cur += A[k][l], cost -= A[k][l];
				pq.emplace(cost);
			}
			REP(k, res) cur += pq.top(), pq.pop();
			chmin(ans, cur);
		}
	}
	cout << ans << endl;
}
0