結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | tnakao0123 |
提出日時 | 2021-12-09 16:47:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 2,266 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 45,248 KB |
実行使用メモリ | 6,120 KB |
最終ジャッジ日時 | 2023-09-24 09:02:28 |
合計ジャッジ時間 | 3,540 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 4 ms
4,376 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 3 ms
4,376 KB |
testcase_06 | AC | 3 ms
4,380 KB |
testcase_07 | AC | 3 ms
4,376 KB |
testcase_08 | AC | 3 ms
4,376 KB |
testcase_09 | AC | 3 ms
4,376 KB |
testcase_10 | AC | 3 ms
4,376 KB |
testcase_11 | AC | 3 ms
4,376 KB |
testcase_12 | AC | 3 ms
4,380 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 21 ms
4,380 KB |
testcase_15 | AC | 84 ms
5,240 KB |
testcase_16 | AC | 83 ms
5,304 KB |
testcase_17 | AC | 15 ms
4,376 KB |
testcase_18 | AC | 53 ms
4,380 KB |
testcase_19 | AC | 19 ms
4,380 KB |
testcase_20 | AC | 61 ms
4,600 KB |
testcase_21 | AC | 105 ms
5,816 KB |
testcase_22 | AC | 108 ms
5,912 KB |
testcase_23 | AC | 28 ms
4,376 KB |
testcase_24 | AC | 112 ms
6,120 KB |
testcase_25 | AC | 26 ms
4,380 KB |
testcase_26 | AC | 20 ms
4,376 KB |
testcase_27 | AC | 54 ms
4,380 KB |
testcase_28 | AC | 13 ms
4,376 KB |
testcase_29 | AC | 10 ms
4,376 KB |
testcase_30 | AC | 102 ms
5,780 KB |
testcase_31 | AC | 6 ms
4,376 KB |
testcase_32 | AC | 10 ms
4,376 KB |
testcase_33 | AC | 46 ms
4,380 KB |
testcase_34 | AC | 1 ms
4,376 KB |
testcase_35 | AC | 5 ms
4,376 KB |
testcase_36 | AC | 2 ms
4,376 KB |
testcase_37 | AC | 5 ms
4,380 KB |
testcase_38 | AC | 5 ms
4,380 KB |
testcase_39 | AC | 5 ms
4,376 KB |
testcase_40 | AC | 5 ms
4,380 KB |
testcase_41 | AC | 6 ms
4,376 KB |
ソースコード
/* -*- coding: utf-8 -*- * * 1780.cc: No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 - yukicoder */ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 200000; const int M = 16; const int L = 26; const long long LINF = 1LL << 60; /* typedef */ typedef long long ll; typedef ll mat[M][M]; /* global variables */ int cs[L], ks[L]; int bits[MAX_N], as[MAX_N], bs[MAX_N], es[MAX_N]; mat ma, mb; ll mds[L][M]; /* subroutines */ inline void unitmat(mat a) { for (int i = 0; i < M; i++) { fill(a[i], a[i] + M, -LINF); a[i][i] = 0; } } inline void copymat(const mat a, mat b) { memcpy(b, a, sizeof(mat)); } inline void mulmat(const mat a, const mat b, mat c) { unitmat(c); for (int k = 0; k < M; k++) for (int i = 0; i < M; i++) for (int j = 0; j < M; j++) if (a[i][k] > -LINF && b[k][j] > -LINF) c[i][j] = max(c[i][j], a[i][k] + b[k][j]); } inline void powmat(const mat a, int b, mat c) { mat s, t; copymat(a, s); unitmat(c); while (b > 0) { if (b & 1) { mulmat(c, s, t); copymat(t, c); } mulmat(s, s, t); copymat(t, s); b >>= 1; } } /* main */ int main() { for (int i = 0; i < L; i++) scanf("%d", cs + i), cs[i]--; for (int i = 0; i < L; i++) scanf("%d", ks + i); int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char s[32]; scanf("%s%d%d%d", s, as + i, bs + i, es + i); as[i]--, bs[i]--; for (int j = 0; s[j]; j++) bits[i] |= (1 << (s[j] - 'A')); } for (int i = 0, bi = 1; i < L; i++, bi <<= 1) { unitmat(ma); for (int j = 0; j < n; j++) if ((bits[j] & bi) && ma[as[j]][bs[j]] < es[j]) ma[as[j]][bs[j]] = ma[bs[j]][as[j]] = es[j]; powmat(ma, ks[i], mb); for (int j = 0; j < M; j++) mds[i][j] = mb[cs[i]][j]; } ll maxsum = -LINF; for (int c = 0; c < M; c++) { //printf("c=%d\n", c); //for (int i = 0; i < L; i++) printf(" %lld", mds[i][c]); putchar('\n'); ll sum = 0; for (int i = 0; i < L; i++) { if (mds[i][c] <= -LINF) { sum = -LINF; break; } sum += mds[i][c]; } maxsum = max(maxsum, sum); } if (maxsum <= -LINF) puts("Impossible"); else printf("%lld\n", maxsum); return 0; }