結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | SSRS |
提出日時 | 2021-12-09 00:17:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,280 bytes |
コンパイル時間 | 2,235 ms |
コンパイル使用メモリ | 187,464 KB |
実行使用メモリ | 17,220 KB |
最終ジャッジ日時 | 2024-07-16 11:20:03 |
合計ジャッジ時間 | 6,314 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,812 KB |
testcase_01 | AC | 5 ms
6,940 KB |
testcase_02 | AC | 6 ms
6,944 KB |
testcase_03 | AC | 6 ms
6,944 KB |
testcase_04 | AC | 6 ms
6,940 KB |
testcase_05 | AC | 6 ms
6,944 KB |
testcase_06 | AC | 6 ms
6,940 KB |
testcase_07 | AC | 6 ms
6,944 KB |
testcase_08 | AC | 6 ms
6,940 KB |
testcase_09 | AC | 6 ms
6,944 KB |
testcase_10 | AC | 6 ms
6,940 KB |
testcase_11 | AC | 6 ms
6,940 KB |
testcase_12 | AC | 6 ms
6,944 KB |
testcase_13 | AC | 6 ms
6,940 KB |
testcase_14 | AC | 48 ms
6,940 KB |
testcase_15 | AC | 205 ms
13,600 KB |
testcase_16 | AC | 202 ms
13,456 KB |
testcase_17 | AC | 31 ms
6,940 KB |
testcase_18 | AC | 127 ms
9,472 KB |
testcase_19 | AC | 42 ms
6,940 KB |
testcase_20 | AC | 149 ms
10,732 KB |
testcase_21 | AC | 257 ms
16,300 KB |
testcase_22 | AC | 264 ms
16,656 KB |
testcase_23 | AC | 63 ms
6,944 KB |
testcase_24 | AC | 276 ms
17,220 KB |
testcase_25 | AC | 59 ms
6,944 KB |
testcase_26 | AC | 45 ms
6,944 KB |
testcase_27 | AC | 128 ms
9,472 KB |
testcase_28 | AC | 26 ms
6,944 KB |
testcase_29 | AC | 18 ms
6,940 KB |
testcase_30 | AC | 254 ms
15,832 KB |
testcase_31 | AC | 9 ms
6,940 KB |
testcase_32 | AC | 19 ms
6,940 KB |
testcase_33 | AC | 111 ms
8,704 KB |
testcase_34 | AC | 6 ms
6,944 KB |
testcase_35 | AC | 7 ms
6,940 KB |
testcase_36 | AC | 6 ms
6,944 KB |
testcase_37 | AC | 7 ms
6,940 KB |
testcase_38 | AC | 7 ms
6,940 KB |
testcase_39 | WA | - |
testcase_40 | AC | 6 ms
6,944 KB |
testcase_41 | AC | 6 ms
6,940 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; } 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; } }