結果
問題 | No.1284 Flip Game |
ユーザー |
👑 ![]() |
提出日時 | 2020-11-06 21:35:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 1,021 bytes |
コンパイル時間 | 1,759 ms |
コンパイル使用メモリ | 168,912 KB |
実行使用メモリ | 21,888 KB |
最終ジャッジ日時 | 2024-07-22 12:21:32 |
合計ジャッジ時間 | 3,443 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#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; LL C[9][9]; LL dp[1 << 18][9]; int whiten[9]; int flipped[9]; int allwhiten; int main() { cin >> N; rep(i, N) rep(j, N) cin >> C[i][j]; rep(i, 9) whiten[i] = 1 << (i * 2); rep(i, 9) flipped[i] = 1 << (i * 2 + 1); allwhiten = 0; rep(i, N) allwhiten |= whiten[i]; const int arrsz = 1 << (N * 2); rep(i, arrsz) rep(j, N) dp[i][j] = 1000000000000; rep(i, N) dp[1 << (i * 2)][i] = 0; LL ans = 1000000000000; rep(i, arrsz) rep(j, N) { LL d = dp[i][j]; bool ok = true; int newi = i; if (!(i & flipped[j])) { ok = false; newi &= ~whiten[j]; newi |= flipped[j]; } rep(to, N) { if (newi & whiten[to]) continue; if (to == j) continue; dp[newi | whiten[to]][to] = min(dp[newi | whiten[to]][to], d + C[j][to]); if (((newi | whiten[to]) & allwhiten) == allwhiten) ans = min(ans, dp[newi | whiten[to]][to]); } } cout << ans << endl; return 0; }