結果
問題 | No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木 |
ユーザー | 👑 ygussany |
提出日時 | 2021-12-09 12:17:43 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 1,669 bytes |
コンパイル時間 | 205 ms |
コンパイル使用メモリ | 30,800 KB |
実行使用メモリ | 5,388 KB |
最終ジャッジ日時 | 2023-09-24 05:39:23 |
合計ジャッジ時間 | 2,915 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,288 KB |
testcase_01 | AC | 2 ms
5,144 KB |
testcase_02 | AC | 10 ms
5,356 KB |
testcase_03 | AC | 4 ms
5,312 KB |
testcase_04 | AC | 10 ms
5,220 KB |
testcase_05 | AC | 6 ms
5,164 KB |
testcase_06 | AC | 8 ms
5,316 KB |
testcase_07 | AC | 8 ms
5,300 KB |
testcase_08 | AC | 13 ms
5,324 KB |
testcase_09 | AC | 9 ms
5,176 KB |
testcase_10 | AC | 8 ms
5,316 KB |
testcase_11 | AC | 8 ms
5,192 KB |
testcase_12 | AC | 3 ms
5,200 KB |
testcase_13 | AC | 2 ms
5,188 KB |
testcase_14 | AC | 23 ms
5,192 KB |
testcase_15 | AC | 62 ms
5,256 KB |
testcase_16 | AC | 62 ms
5,204 KB |
testcase_17 | AC | 19 ms
5,380 KB |
testcase_18 | AC | 43 ms
5,256 KB |
testcase_19 | AC | 21 ms
5,196 KB |
testcase_20 | AC | 48 ms
5,388 KB |
testcase_21 | AC | 76 ms
5,384 KB |
testcase_22 | AC | 78 ms
5,236 KB |
testcase_23 | AC | 27 ms
5,320 KB |
testcase_24 | AC | 81 ms
5,304 KB |
testcase_25 | AC | 25 ms
5,240 KB |
testcase_26 | AC | 22 ms
5,300 KB |
testcase_27 | AC | 42 ms
5,372 KB |
testcase_28 | AC | 18 ms
5,288 KB |
testcase_29 | AC | 16 ms
5,292 KB |
testcase_30 | AC | 78 ms
5,300 KB |
testcase_31 | AC | 12 ms
5,208 KB |
testcase_32 | AC | 15 ms
5,368 KB |
testcase_33 | AC | 38 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,236 KB |
testcase_35 | AC | 3 ms
5,248 KB |
testcase_36 | AC | 2 ms
5,168 KB |
testcase_37 | AC | 2 ms
5,172 KB |
testcase_38 | AC | 6 ms
5,228 KB |
testcase_39 | AC | 7 ms
5,288 KB |
testcase_40 | AC | 6 ms
5,388 KB |
testcase_41 | AC | 7 ms
5,376 KB |
ソースコード
#include <stdio.h> void chmax(int* a, int b) { if (*a < b) *a = b; } void chmaxll(long long* a, long long b) { if (*a < b) *a = b; } int main() { const int inf = -(1 << 30); int i, j, k, l, u, w, C[26], K[26], N, A, B, E, adj[26][17][17]; char S[31]; for (i = 0; i < 26; i++) scanf("%d", &(C[i])); for (i = 0; i < 26; i++) scanf("%d", &(K[i])); for (i = 0; i < 26; i++) for (u = 1; u <= 16; u++) for (w = 1; w <= 16; w++) adj[i][u][w] = inf; scanf("%d", &N); for (i = 1; i <= N; i++) { scanf("%s %d %d %d", S, &A, &B, &E); for (j = 0; S[j] != 0; j++) { chmax(&(adj[S[j] - 'A'][A][B]), E); chmax(&(adj[S[j] - 'A'][B][A]), E); } } const long long infll = -(1LL << 60); long long ans = infll, dp[26][1001][17], tmp, sum; for (i = 0; i < 26; i++) { for (j = 0; j <= 1000; j++) { for (k = 1; k <= 16; k++) dp[i][j][k] = infll; } dp[i][0][C[i]] = 0; for (j = 0; j < 1000; j++) { for (k = 1; k <= 16; k++) { if (dp[i][j][k] == infll) continue; for (u = k, w = 1; w <= 16; w++) { if (adj[i][u][w] != inf) chmaxll(&(dp[i][j+1][w]), dp[i][j][u] + adj[i][u][w]); } } } } for (k = 1; k <= 16; k++) { for (i = 0, sum = 0; i < 26; i++) { for (j = 0, tmp = infll; j <= 1000 && j <= K[i]; j++) chmaxll(&tmp, dp[i][j][k]); if (K[i] > 1000) { j = 2; for (l = 900; l <= 1000; l++) if (dp[i][l][k] != infll && dp[i][l-j][k] != infll) chmaxll(&tmp, (dp[i][l][k] - dp[i][l-j][k]) * ((K[i] - l) / j) + dp[i][l][k]); } if (tmp == infll) break; sum += tmp; } if (i == 26) chmaxll(&ans, sum); } if (ans == infll) printf("Impossible\n"); else printf("%lld\n", ans); fflush(stdout); return 0; }