結果

問題 No.1345 Beautiful BINGO
ユーザー PCTprobability
提出日時 2021-01-14 00:30:52
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 2,211 bytes
コンパイル時間 2,492 ms
コンパイル使用メモリ 163,856 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 11:27:45
合計ジャッジ時間 8,371 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
int main() {
/* mod 1e9+7 */
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(10);
ll n,m;
cin>>n>>m;
vector<vector<ll>> s(n,vector<ll>(n));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>s[i][j];
}
}
ll ans=inf;
for(int a=0;a<2;a++){
for(int b=0;b<2;b++){
ll p=0;
ll c=m-a-b;
auto dp=s;
if(a){
for(int i=0;i<n;i++){
p+=dp[i][i];
dp[i][i]=0;
p+=dp[i][i];
}
}
if(b){
for(int i=0;i<n;i++){
p+=dp[i][n-i-1];
dp[i][n-i-1]=0;
p+=dp[i][n-i-1];
}
}
vector<ll> f(n);
for(int i=0;i<n;i++){
ll tmp=0;
for(int j=0;j<n;j++){
tmp+=dp[i][j];
}
f[i]=tmp;
}
for(int i=0;i<(1<<n);i++){
ll e=c;
ll tmp=0;
ll o=i;
for(int j=0;j<n;j++){
if(o%2==1){
tmp+=f[j];
e--;
}
o/=2;
}
ll z=tmp;
// cout<<tmp+p<<endl;
vector<ll> d(n);
for(int j=0;j<n;j++){
ll tmp2=0;
ll z=i;
for(int k=0;k<n;k++){
if(z%2==0){
tmp2+=dp[k][j];
}
z/=2;
}
d[j]=tmp2;
}
sor(d);
for(int j=0;j<e;j++){
tmp+=d[j];
}
chmin(ans,tmp+p);
}
}
}
cout<<ans<<endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0