結果

問題 No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木
ユーザー 👑 emthrmemthrm
提出日時 2021-12-09 00:43:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 2,443 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 206,632 KB
実行使用メモリ 16,168 KB
最終ジャッジ日時 2023-09-23 12:03:41
合計ジャッジ時間 6,437 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 7 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 8 ms
4,380 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 7 ms
4,380 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 37 ms
5,144 KB
testcase_15 AC 161 ms
12,748 KB
testcase_16 AC 156 ms
12,736 KB
testcase_17 AC 25 ms
4,380 KB
testcase_18 AC 100 ms
8,916 KB
testcase_19 AC 34 ms
5,048 KB
testcase_20 AC 116 ms
9,920 KB
testcase_21 AC 203 ms
15,304 KB
testcase_22 AC 207 ms
15,580 KB
testcase_23 AC 48 ms
5,952 KB
testcase_24 AC 218 ms
16,168 KB
testcase_25 AC 47 ms
5,688 KB
testcase_26 AC 36 ms
5,132 KB
testcase_27 AC 100 ms
8,848 KB
testcase_28 AC 22 ms
4,380 KB
testcase_29 AC 16 ms
4,376 KB
testcase_30 AC 197 ms
14,864 KB
testcase_31 AC 9 ms
4,380 KB
testcase_32 AC 17 ms
4,376 KB
testcase_33 AC 87 ms
8,064 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 5 ms
4,376 KB
testcase_37 AC 5 ms
4,380 KB
testcase_38 AC 7 ms
4,376 KB
testcase_39 AC 7 ms
4,376 KB
testcase_40 AC 7 ms
4,380 KB
testcase_41 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY[]{1, 0, -1, 0}, DX[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}, DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int CHERRY = 26, C = 16, B = 24;
  int c[CHERRY]{}, k[CHERRY]{};
  REP(i, CHERRY) cin >> c[i], --c[i];
  REP(i, CHERRY) cin >> k[i];
  int n; cin >> n;
  vector<string> s(n);
  vector<int> a(n), b(n), e(n);
  REP(i, n) cin >> s[i] >> a[i] >> b[i] >> e[i], --a[i], --b[i];
  ll ans[C]{};
  REP(cherry, CHERRY) {
    ll dp1[B][C][C]{};
    REP(bit, B) REP(i, C) {
      fill(dp1[bit][i], dp1[bit][i] + C, -LINF);
      dp1[bit][i][i] = 0;
    }
    REP(i, n) {
      if (count(ALL(s[i]), 'A' + cherry) > 0) {
        chmax(dp1[0][a[i]][b[i]], e[i]);
        chmax(dp1[0][b[i]][a[i]], e[i]);
      }
    }
    REP(bit, B - 1) REP(i, C) REP(j, C) {
      REP(k, C) {
        if (dp1[bit][i][k] != -LINF && dp1[bit][k][j] != -LINF) {
          chmax(dp1[bit + 1][i][j], dp1[bit][i][k] + dp1[bit][k][j]);
        }
      }
    }
    ll dp2[C]{};
    fill(dp2, dp2 + C, -LINF);
    dp2[c[cherry]] = 0;
    REP(bit, B) {
      if (k[cherry] >> bit & 1) {
        ll nxt[C]{};
        fill(nxt, nxt + C, -LINF);
        REP(i, C) {
          if (dp2[i] == -LINF) continue;
          REP(j, C) {
            if (dp1[bit][i][j] != -LINF) chmax(nxt[j], dp2[i] + dp1[bit][i][j]);
          }
        }
        swap(dp2, nxt);
      }
    }
    REP(i, C) {
      if (dp2[i] == -LINF) {
        ans[i] = -LINF;
      } else if (ans[i] != -LINF) {
        ans[i] += dp2[i];
      }
    }
  }
  const ll energy = *max_element(ans, ans + C);
  if (energy == -LINF) {
    cout << "Impossible\n";
  } else {
    cout << energy << '\n';
  }
  return 0;
}
0