結果
| 問題 |
No.1345 Beautiful BINGO
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-01-16 13:24:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 140 ms / 2,000 ms |
| コード長 | 964 bytes |
| コンパイル時間 | 2,370 ms |
| コンパイル使用メモリ | 195,272 KB |
| 最終ジャッジ日時 | 2025-01-17 21:56:22 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 61 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d%d",&N,&M);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:29:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | rep(i,N) rep(j,N) scanf("%d",&A[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int N,M;
int A[16][16];
int B[16][16];
int offset=0;
int ans=1000000000;
int solve(int m){
int ians=1000000000;
rep(R,1<<N){
int xm=m; rep(i,N) if(R&(1<<i)) xm--;
if(xm>N) continue;
int S=0; int C[16]={};
rep(i,N) rep(j,N) if(R&(1<<i)) S+=B[i][j]; else C[j]+=B[i][j];
sort(C,C+N);
rep(i,xm) S+=C[i];
ians=min(ians,S);
}
return ians;
}
int main(){
scanf("%d%d",&N,&M);
rep(i,N) rep(j,N) scanf("%d",&A[i][j]);
rep(i,N) rep(j,N) B[i][j]=A[i][j];
ans=min(ans,solve(M)+offset);
rep(i,N){ B[i][i]=0; offset+=A[i][i]; }
ans=min(ans,solve(M-1)+offset);
rep(i,N) if(i*2+1!=N) { B[i][N-1-i]=0; offset+=A[i][N-1-i]; }
ans=min(ans,solve(M-2)+offset);
rep(i,N) if(i*2+1!=N) { B[i][i]=A[i][i]; offset-=A[i][i]; }
ans=min(ans,solve(M-1)+offset);
printf("%d\n",ans);
return 0;
}
Nachia