結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | SSRS |
提出日時 | 2021-12-09 00:15:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,161 bytes |
コンパイル時間 | 2,259 ms |
コンパイル使用メモリ | 187,160 KB |
実行使用メモリ | 17,316 KB |
最終ジャッジ日時 | 2024-07-16 11:18:57 |
合計ジャッジ時間 | 5,543 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,812 KB |
testcase_01 | AC | 5 ms
6,944 KB |
testcase_02 | AC | 5 ms
6,944 KB |
testcase_03 | AC | 5 ms
6,940 KB |
testcase_04 | AC | 5 ms
6,940 KB |
testcase_05 | AC | 5 ms
6,940 KB |
testcase_06 | AC | 5 ms
6,940 KB |
testcase_07 | AC | 6 ms
6,940 KB |
testcase_08 | AC | 6 ms
6,944 KB |
testcase_09 | AC | 5 ms
6,944 KB |
testcase_10 | AC | 5 ms
6,944 KB |
testcase_11 | AC | 5 ms
6,940 KB |
testcase_12 | AC | 6 ms
6,940 KB |
testcase_13 | AC | 5 ms
6,944 KB |
testcase_14 | AC | 44 ms
6,944 KB |
testcase_15 | AC | 195 ms
13,584 KB |
testcase_16 | AC | 189 ms
13,456 KB |
testcase_17 | AC | 28 ms
6,940 KB |
testcase_18 | AC | 116 ms
9,676 KB |
testcase_19 | AC | 39 ms
6,944 KB |
testcase_20 | AC | 140 ms
10,740 KB |
testcase_21 | AC | 243 ms
16,304 KB |
testcase_22 | AC | 255 ms
16,728 KB |
testcase_23 | AC | 59 ms
6,940 KB |
testcase_24 | AC | 257 ms
17,316 KB |
testcase_25 | AC | 54 ms
6,940 KB |
testcase_26 | AC | 40 ms
6,944 KB |
testcase_27 | AC | 117 ms
9,644 KB |
testcase_28 | AC | 24 ms
6,944 KB |
testcase_29 | AC | 17 ms
6,940 KB |
testcase_30 | AC | 234 ms
15,836 KB |
testcase_31 | AC | 7 ms
6,940 KB |
testcase_32 | AC | 18 ms
6,944 KB |
testcase_33 | AC | 101 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 | 5 ms
6,944 KB |
testcase_39 | WA | - |
testcase_40 | AC | 5 ms
6,940 KB |
testcase_41 | AC | 5 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const int LOG = 24; const long long INF = 100000000000000000; 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); 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++){ sum[j] += c[C[i]][j]; } } long long mx = -INF; for (int i = 0; i < 16; i++){ mx = max(mx, sum[i]); } if (mx < 0){ cout << "Impossible" << endl; } else { cout << mx << endl; } }