結果

問題 No.1345 Beautiful BINGO
ユーザー Example0911Example0911
提出日時 2021-01-16 14:30:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,633 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 218,264 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 16:53:11
合計ジャッジ時間 11,917 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 14 ms
5,376 KB
testcase_23 AC 317 ms
5,376 KB
testcase_24 WA -
testcase_25 AC 12 ms
5,376 KB
testcase_26 AC 123 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 150 ms
5,376 KB
testcase_30 AC 33 ms
5,376 KB
testcase_31 WA -
testcase_32 AC 4 ms
5,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 4 ms
5,376 KB
testcase_38 WA -
testcase_39 AC 598 ms
5,376 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 3 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = (ll)1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N, M; cin >> N >> M;
	vector<vector<ll>>A(N, vector<ll>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A[i][j];
		}
	}
	ll ans = INF;
	for (int i = 0; i < 4; i++) {
		vector<vector<bool>>now(N, vector<bool>(N));
		ll tmp = 0;
		ll tmp2 = 0;
		for (int j = 0; j < 2; j++) {
			if (i & (1 << j)) {
				if (j == 0) {
					for (int k = 0; k < N; k++) {
						if (!now[k][k]) {
							now[k][k] = true;
							tmp += A[k][k];
						}
					}
					tmp2++;
				}
				else {
					for (int k = 0; k < N; k++) {
						if (!now[k][N - k - 1]) {
							now[k][N - k - 1] = true;
							tmp += A[k][N - k - 1];
						}
					}
					tmp2++;
				}
			}
		}
		
		for (int bit = 0; bit < (1 << N); bit++) {
			vector<vector<bool>>b = now;
			ll a = tmp;
			ll cnt = tmp2;
			for (int j = 0; j < N; j++) {
				if (bit & (1 << j)) {
					for (int k = 0; k < N; k++) {
						if (!now[j][k]) {
							now[j][k] = true;
							tmp += A[j][k];
						}
					}
					cnt++;
				}
			}
			ll need = M - cnt;
			if (need <= 0) {
				ans = min(ans, tmp);
				continue;
			}
			if (need > N)continue;
			vector<ll>s(N);
			for (int k = 0; k < N; k++) {
				for (int j = 0; j < N; j++) {
					if (!now[j][k]) {
						s[k] += A[j][k];
					}
				}
			}
			sort(s.begin(), s.end());
			for (int j = 0; j < need; j++) {
				tmp += s[j];
			}
			ans = min(ans, tmp);
			tmp = a;
			now = b;
		}
	}
	cout << ans << endl;
	return 0;
}
0