結果
問題 | No.1345 Beautiful BINGO |
ユーザー | LayCurse |
提出日時 | 2021-01-16 13:10:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 4,403 bytes |
コンパイル時間 | 2,555 ms |
コンパイル使用メモリ | 217,596 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-06 06:39:03 |
合計ジャッジ時間 | 6,117 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 1 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 | 7 ms
5,376 KB |
testcase_23 | AC | 114 ms
5,376 KB |
testcase_24 | AC | 51 ms
5,376 KB |
testcase_25 | AC | 5 ms
5,376 KB |
testcase_26 | AC | 25 ms
5,376 KB |
testcase_27 | AC | 106 ms
5,376 KB |
testcase_28 | AC | 4 ms
5,376 KB |
testcase_29 | AC | 26 ms
5,376 KB |
testcase_30 | AC | 12 ms
5,376 KB |
testcase_31 | AC | 7 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 105 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 3 ms
5,376 KB |
testcase_36 | AC | 103 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 24 ms
5,376 KB |
testcase_39 | AC | 106 ms
5,376 KB |
testcase_40 | AC | 52 ms
5,376 KB |
testcase_41 | AC | 49 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 2 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 | 1 ms
5,376 KB |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 1 ms
5,376 KB |
testcase_51 | AC | 1 ms
5,376 KB |
testcase_52 | AC | 100 ms
5,376 KB |
testcase_53 | AC | 103 ms
5,376 KB |
testcase_54 | AC | 108 ms
5,376 KB |
testcase_55 | AC | 101 ms
5,376 KB |
testcase_56 | AC | 99 ms
5,376 KB |
testcase_57 | AC | 104 ms
5,376 KB |
testcase_58 | AC | 106 ms
5,376 KB |
testcase_59 | AC | 109 ms
5,376 KB |
testcase_60 | AC | 104 ms
5,376 KB |
testcase_61 | AC | 105 ms
5,376 KB |
testcase_62 | AC | 106 ms
5,376 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void*wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){ sort(a, a+N); } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template<class S, class T> inline S chmin(S &a, T b){ if(a>b){ a=b; } return a; } int N; int M; int A[16][16]; int b[16][16]; int c[16]; int main(){ int mask; wmem = memarr; int res = 1073709056; int tmp; int ok; rd(N); rd(M); { int Lj4PdHRW; int KL2GvlyY; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ for(KL2GvlyY=(0);KL2GvlyY<(N);KL2GvlyY++){ rd(A[Lj4PdHRW][KL2GvlyY]); } } } for(mask=(0);mask<(1<<(N+2));mask++){ int i; tmp = 0; ok = 0; for(i=(0);i<(N+2);i++){ if(((mask) &(1<<(i)))){ ok++; } } for(i=(0);i<(N);i++){ int j; for(j=(0);j<(N);j++){ b[i][j] = A[i][j]; } } for(i=(0);i<(N);i++){ if(((mask) &(1<<(i)))){ int j; for(j=(0);j<(N);j++){ tmp += b[i][j]; b[i][j] = 0; } } } if(((mask) &(1<<(N)))){ for(i=(0);i<(N);i++){ tmp += b[i][i]; b[i][i] = 0; } } if(((mask) &(1<<(N+1)))){ for(i=(0);i<(N);i++){ tmp += b[N-1-i][i]; b[N-1-i][i] = 0; } } for(i=(0);i<(N);i++){ { int jPV_0s1p; remove_reference<decltype(b[jPV_0s1p][i])>::type BUotOFBp; int Q5rsz4fz = 0; if((0) > ((N)-1)){ BUotOFBp = 0; } else{ for(jPV_0s1p = 0; jPV_0s1p <= (N)-1; jPV_0s1p++){ if(Q5rsz4fz == 0){ BUotOFBp = b[jPV_0s1p][i]; Q5rsz4fz = 1; continue; } BUotOFBp += b[jPV_0s1p][i]; } } c[i] =BUotOFBp; } } sortA_L(N, c); for(i=(0);i<(M-ok);i++){ tmp += c[i]; } chmin(res, tmp); } wt_L(res); wt_L('\n'); return 0; } // cLay version 20210103-1 [bug fixed 1] // --- original code --- // int N, M, A[16][16], b[16][16], c[16]; // { // int res = int_inf, tmp, ok; // rd(N,M,A(N,N)); // rep(mask,1<<(N+2)){ // tmp = 0; // ok = 0; // rep(i,N+2) if(BIT_ith(mask,i)) ok++; // rep(i,N) rep(j,N) b[i][j] = A[i][j]; // rep(i,N) if(BIT_ith(mask,i)) rep(j,N) tmp += b[i][j], b[i][j] = 0; // if(BIT_ith(mask,N)) rep(i,N) tmp += b[i][i], b[i][i] = 0; // if(BIT_ith(mask,N+1)) rep(i,N) tmp += b[N-1-i][i], b[N-1-i][i] = 0; // rep(i,N) c[i] = sum[j,0,N](b[j][i]); // sortA(N, c); // rep(i, M-ok) tmp += c[i]; // res <?= tmp; // } // wt(res); // }