結果

問題 No.2094 Symmetry
ユーザー KudeKude
提出日時 2022-10-07 21:59:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,866 bytes
コンパイル時間 2,967 ms
コンパイル使用メモリ 231,236 KB
実行使用メモリ 9,204 KB
最終ジャッジ日時 2023-09-03 05:13:25
合計ジャッジ時間 7,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,888 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  int cnt = 0;
  rep(_, 2 * n) {
    string s;
    cin >> s;
    for(char c: s) cnt += c == '#';
  }
  constexpr long long INF = 1002003004005006007;
  VL dp[2];
  rep(i, 2) dp[i].assign(cnt + 1, -INF);
  dp[0][0] = 0;
  rep(_, 2 * n) {
    VL cs(2 * n);
    rep(i, 2 * n) cin >> cs[i];
    VL cs_sym(n);
    rep(i, n) cs_sym[i] = cs[i] + cs[2 * n - 1 - i];
    sort(rall(cs_sym));
    rep(i, n - 1) cs_sym[i+1] += cs_sym[i];
    VL cs_sorted = cs;
    sort(rall(cs_sorted));
    rep(i, 2 * n - 1) cs_sorted[i+1] += cs_sorted[i];
    rrep(i, cnt) {
      ll v = max(dp[0][i], dp[1][i]);
      if (v != -INF) {
        rep(idx, 2 * n) {
          int j = i + idx + 1;
          if (j > cnt) break;
          chmax(dp[1][j], v + cs_sorted[idx]);
        }
      }
      v = dp[0][i];
      if (v != -INF) {
        rep(idx, n) {
          int j = i + 2 * (idx + 1);
          if (j > cnt) break;
          chmax(dp[0][j], v + cs_sym[idx]);
        }
      }
    }
  }
  ll ans = max(dp[0][cnt] + k, dp[1][cnt]);
  cout << ans << '\n';
}
0