結果
問題 |
No.2094 Symmetry
|
ユーザー |
|
提出日時 | 2022-10-07 22:49:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,673 bytes |
コンパイル時間 | 2,560 ms |
コンパイル使用メモリ | 214,172 KB |
最終ジャッジ日時 | 2025-02-07 23:45:49 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 TLE * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef _RUTHEN #include <debug.hpp> #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template <class T> using V = vector<T>; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; ll K; cin >> K; int N2 = N * 2; V<string> S(N2); rep(i, N2) cin >> S[i]; V<V<ll>> C(N2, V<ll>(N2)); rep(i, N2) rep(j, N2) cin >> C[i][j]; V<ll> B; rep(i, N2) rep(j, N2) B.push_back(C[i][j]); sort(B.rbegin(), B.rend()); show(B); int cnt = 0; rep(i, N2) rep(j, N2) cnt += S[i][j] == '#'; ll ans = accumulate(B.begin(), B.begin() + cnt, 0LL); show(ans); map<int, ll> dp; dp[0] = 0; rep(i, N2) { rep(j, N) { map<int, ll> np; // # int c1 = 0, c2 = 0; if (S[i][j] == '.') c1++; if (S[i][N2 - 1 - j] == '.') c1++; // . if (S[i][j] == '#') c2--; if (S[i][N2 - 1 - j] == '#') c2--; for (auto &[k, v] : dp) { if (np.count(k + c1)) { np[k + c1] = max(np[k + c1], v + C[i][j] + C[i][N2 - 1 - j]); } else { np[k + c1] = v + C[i][j] + C[i][N2 - 1 - j]; } if (np.count(k + c2)) { np[k + c2] = max(np[k + c2], v); } else { np[k + c2] = v; } } swap(np, dp); show(dp); } } if (dp.count(0)) ans = max(ans, dp[0] + K); cout << ans << '\n'; return 0; }