結果
問題 | No.861 ケーキカット |
ユーザー | chocorusk |
提出日時 | 2019-08-10 00:31:42 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 490 ms / 1,000 ms |
コード長 | 1,409 bytes |
コンパイル時間 | 1,337 ms |
コンパイル使用メモリ | 98,020 KB |
実行使用メモリ | 19,044 KB |
最終ジャッジ日時 | 2023-09-22 02:17:39 |
合計ジャッジ時間 | 14,394 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 476 ms
18,904 KB |
testcase_01 | AC | 481 ms
18,760 KB |
testcase_02 | AC | 466 ms
18,824 KB |
testcase_03 | AC | 458 ms
18,848 KB |
testcase_04 | AC | 457 ms
18,760 KB |
testcase_05 | AC | 463 ms
18,780 KB |
testcase_06 | AC | 473 ms
18,772 KB |
testcase_07 | AC | 483 ms
18,920 KB |
testcase_08 | AC | 484 ms
18,768 KB |
testcase_09 | AC | 490 ms
19,044 KB |
testcase_10 | AC | 478 ms
18,844 KB |
testcase_11 | AC | 480 ms
18,764 KB |
testcase_12 | AC | 480 ms
18,768 KB |
testcase_13 | AC | 479 ms
18,808 KB |
testcase_14 | AC | 478 ms
18,840 KB |
testcase_15 | AC | 475 ms
18,764 KB |
testcase_16 | AC | 480 ms
18,776 KB |
testcase_17 | AC | 476 ms
18,776 KB |
testcase_18 | AC | 475 ms
18,760 KB |
testcase_19 | AC | 475 ms
18,764 KB |
testcase_20 | AC | 474 ms
18,780 KB |
testcase_21 | AC | 479 ms
19,044 KB |
testcase_22 | AC | 471 ms
18,924 KB |
testcase_23 | AC | 476 ms
18,768 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; ll c[25]; int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1}; bool used[1<<25]; void dfs(int b){ used[b]=1; for(int i=0; i<25; i++){ if((b&(1<<i))==0){ if(used[b^(1<<i)]) continue; int x=i/5, y=i%5; for(int k=0; k<4; k++){ int x1=x+dx[k], y1=y+dy[k], t=x1*5+y1; if(x1<0 || x1>=5 || y1<0 || y1>=5) continue; if(b&(1<<t)) dfs(b^(1<<i)); } } } } int main() { for(int i=0; i<5; i++) for(int j=0; j<5; j++) cin>>c[i*5+j]; for(int i=0; i<25; i++) dfs(1<<i); ll ans=1e18; for(int i=0; i<(1<<25); i++){ if(used[i] && used[(1<<25)-1-i]){ ll cnt0=0, cnt1=0; for(int j=0; j<25; j++){ if(i&(1<<j)) cnt1+=c[j]; else cnt0+=c[j]; } ans=min(ans, abs(cnt0-cnt1)); } } cout<<ans<<endl; return 0; }