結果
問題 | No.861 ケーキカット |
ユーザー |
|
提出日時 | 2021-05-28 08:13:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,269 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 207,508 KB |
実行使用メモリ | 134,400 KB |
最終ジャッジ日時 | 2024-11-06 23:53:14 |
合計ジャッジ時間 | 20,461 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 690 ms
134,144 KB |
testcase_01 | AC | 684 ms
134,272 KB |
testcase_02 | AC | 689 ms
134,272 KB |
testcase_03 | AC | 684 ms
134,272 KB |
testcase_04 | AC | 686 ms
134,272 KB |
testcase_05 | AC | 702 ms
134,272 KB |
testcase_06 | AC | 698 ms
134,272 KB |
testcase_07 | AC | 693 ms
134,400 KB |
testcase_08 | AC | 687 ms
134,400 KB |
testcase_09 | AC | 691 ms
134,144 KB |
testcase_10 | AC | 684 ms
134,272 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
ソースコード
/** * author: ivanzuki * created: Thu May 27 2021 **/ #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); const int n = 5; vector<vector<int>> c(n, vector<int>(n)); long long total = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> c[i][j]; total += c[i][j]; } } long long ans = (long long) 1e18; const vector<int> dx = {-1, 0, 1, 0}; const vector<int> dy = {0, -1, 0, 1}; vector<int> was(1 << (n * n)); function<bool(int, int, int)> On = [&](int mask, int x, int y) { return (mask >> (x * n + y)) & 1; }; function<void(int, long long)> DFS = [&](int mask, long long sum) { was[mask] = 1; ans = min(ans, abs(sum - (total - sum))); for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { if (On(mask, x, y)) { continue; } for (int k = 0; k < 4; k++) { int xk = x + dx[k]; int yk = y + dy[k]; if (0 <= xk && xk < n && 0 <= yk && yk < n && On(mask, xk, yk) && !was[mask | (1 << (x * n + y))]) { DFS(mask | (1 << (x * n + y)), sum + c[x][y]); } } } } }; DFS(1, c[0][0]); cout << ans << '\n'; return 0; }