結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | SSRS |
提出日時 | 2021-12-09 00:21:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 259 ms / 2,000 ms |
コード長 | 2,301 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 187,208 KB |
実行使用メモリ | 17,244 KB |
最終ジャッジ日時 | 2024-07-16 11:23:14 |
合計ジャッジ時間 | 6,145 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,812 KB |
testcase_01 | AC | 5 ms
6,940 KB |
testcase_02 | AC | 5 ms
6,940 KB |
testcase_03 | AC | 6 ms
6,940 KB |
testcase_04 | AC | 6 ms
6,940 KB |
testcase_05 | AC | 5 ms
6,940 KB |
testcase_06 | AC | 5 ms
6,940 KB |
testcase_07 | AC | 5 ms
6,940 KB |
testcase_08 | AC | 5 ms
6,944 KB |
testcase_09 | AC | 6 ms
6,944 KB |
testcase_10 | AC | 6 ms
6,944 KB |
testcase_11 | AC | 6 ms
6,940 KB |
testcase_12 | AC | 5 ms
6,940 KB |
testcase_13 | AC | 6 ms
6,940 KB |
testcase_14 | AC | 43 ms
6,940 KB |
testcase_15 | AC | 194 ms
13,472 KB |
testcase_16 | AC | 193 ms
13,444 KB |
testcase_17 | AC | 27 ms
6,940 KB |
testcase_18 | AC | 118 ms
9,404 KB |
testcase_19 | AC | 40 ms
6,944 KB |
testcase_20 | AC | 142 ms
10,540 KB |
testcase_21 | AC | 240 ms
16,452 KB |
testcase_22 | AC | 248 ms
16,632 KB |
testcase_23 | AC | 60 ms
6,940 KB |
testcase_24 | AC | 259 ms
17,244 KB |
testcase_25 | AC | 54 ms
6,944 KB |
testcase_26 | AC | 40 ms
6,940 KB |
testcase_27 | AC | 123 ms
9,600 KB |
testcase_28 | AC | 25 ms
6,940 KB |
testcase_29 | AC | 18 ms
6,940 KB |
testcase_30 | AC | 234 ms
15,912 KB |
testcase_31 | AC | 8 ms
6,944 KB |
testcase_32 | AC | 17 ms
6,944 KB |
testcase_33 | AC | 100 ms
8,704 KB |
testcase_34 | AC | 5 ms
6,944 KB |
testcase_35 | AC | 6 ms
6,940 KB |
testcase_36 | AC | 5 ms
6,940 KB |
testcase_37 | AC | 6 ms
6,944 KB |
testcase_38 | AC | 7 ms
6,944 KB |
testcase_39 | AC | 6 ms
6,940 KB |
testcase_40 | AC | 6 ms
6,940 KB |
testcase_41 | AC | 6 ms
6,948 KB |
ソースコード
#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, true); 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] < -INF / 2){ ok[j] = false; } else { 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 == -INF){ cout << "Impossible" << endl; } else { cout << mx << endl; } }