結果

問題 No.1345 Beautiful BINGO
ユーザー kotatsugamekotatsugame
提出日時 2021-01-17 10:55:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 71,232 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-19 16:20:41
合計ジャッジ時間 7,861 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 7 ms
4,380 KB
testcase_26 AC 65 ms
4,380 KB
testcase_27 AC 301 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 66 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 304 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 302 ms
4,376 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 59 ms
4,376 KB
testcase_39 AC 307 ms
4,376 KB
testcase_40 AC 141 ms
4,376 KB
testcase_41 AC 142 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,388 KB
testcase_49 AC 1 ms
4,384 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 302 ms
4,380 KB
testcase_53 AC 300 ms
4,380 KB
testcase_54 AC 39 ms
4,380 KB
testcase_55 AC 127 ms
4,380 KB
testcase_56 AC 299 ms
4,384 KB
testcase_57 AC 307 ms
4,376 KB
testcase_58 AC 291 ms
4,380 KB
testcase_59 AC 309 ms
4,376 KB
testcase_60 AC 302 ms
4,380 KB
testcase_61 AC 185 ms
4,380 KB
testcase_62 AC 303 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,M;
int A[16][16];
int vis[16][16];
int t[16];
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>A[i][j];
	int ans=1e9;
	for(int b=0;b<1<<N+2;b++)
	{
		int k=__builtin_popcount(b);
		if(k+N<M)continue;
		int now=0;
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)vis[i][j]=0;
		for(int i=0;i<N;i++)if(b>>i&1)
		{
			for(int j=0;j<N;j++)now+=A[i][j],vis[i][j]=1;
		}
		if(b>>N&1)
		{
			for(int i=0;i<N;i++)if(!vis[i][i])now+=A[i][i],vis[i][i]=1;
		}
		if(b>>N+1&1)
		{
			for(int i=0;i<N;i++)if(!vis[i][N-i-1])now+=A[i][N-i-1],vis[i][N-i-1]=1;
		}
		for(int j=0;j<N;j++)t[j]=0;
		for(int j=0;j<N;j++)for(int i=0;i<N;i++)if(!vis[i][j])t[j]+=A[i][j];
		sort(t,t+N);
		for(int j=0;k+j<M;j++)now+=t[j];
		if(ans>now)ans=now;
	}
	cout<<ans<<endl;
}
0