結果

問題 No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木
ユーザー SSRSSSRS
提出日時 2021-12-09 00:16:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,270 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 185,616 KB
実行使用メモリ 17,024 KB
最終ジャッジ日時 2023-09-23 11:45:08
合計ジャッジ時間 6,491 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 5 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
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 -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 6 ms
4,376 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int LOG = 24;
const long long INF = 1000000000000000000;
int main(){
  vector<int> C(26);
  for (int i = 0; i < 26; i++){
    cin >> C[i];
    C[i]--;
  }
  vector<int> K(26);
  for (int i = 0; i < 26; i++){
    cin >> K[i];
  }
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> A(N), B(N), E(N);
  for (int i = 0; i < N; i++){
    cin >> S[i] >> A[i] >> B[i] >> E[i];
    A[i]--;
    B[i]--;
  }
  vector<int> s(N, 0);
  for (int i = 0; i < N; i++){
    int L = S[i].size();
    for (int j = 0; j < L; j++){
      s[i] |= 1 << (S[i][j] - 'A');
    }
  }
  vector<long long> sum(16, 0);
  vector<bool> ok(16, 0);
  for (int i = 0; i < 26; i++){
    vector<vector<long long>> P(16, vector<long long>(16, -INF));
    for (int j = 0; j < N; j++){
      if ((s[j] >> i & 1) == 1){
        P[A[j]][B[j]] = max(P[A[j]][B[j]], (long long) E[j]);
        P[B[j]][A[j]] = max(P[B[j]][A[j]], (long long) E[j]);
      }
    }
    for (int j = 0; j < 16; j++){
      P[j][j] = 0;
    }
    vector<vector<vector<long long>>> dp(LOG, vector<vector<long long>>(16, vector<long long>(16, -INF)));
    dp[0] = P;
    for (int j = 0; j < LOG - 1; j++){
      for (int k = 0; k < 16; k++){
        for (int m = 0; m < 16; m++){
          for (int n = 0; n < 16; n++){
            dp[j + 1][k][n] = max(dp[j + 1][k][n], dp[j][k][m] + dp[j][m][n]);
          }
        }
      }
    }
    vector<vector<long long>> c(16, vector<long long>(16, -INF));
    for (int j = 0; j < 16; j++){
      c[j][j] = 0;
    }
    for (int j = 0; j < LOG; j++){
      if ((K[i] >> j & 1) == 1){
        vector<vector<long long>> c2(16, vector<long long>(16, -INF));
        for (int k = 0; k < 16; k++){
          for (int m = 0; m < 16; m++){
            for (int n = 0; n < 16; n++){
              c2[k][n] = max(c2[k][n], c[k][m] + dp[j][m][n]);
            }
          }
        }
        swap(c, c2);
      }
    }
    for (int j = 0; j < 16; j++){
      if (c[C[i]][j] < 0){
        ok[j] = false;
      }
      sum[j] += c[C[i]][j];
    }
  }
  long long mx = -INF;
  for (int i = 0; i < 16; i++){
    if (ok[i]){
      mx = max(mx, sum[i]);
    }
  }
  if (mx < 0){
    cout << "Impossible" << endl;
  } else {
    cout << mx << endl;
  }
}
0