結果

問題 No.1780 [Cherry Anniversary] 真冬に咲く26の櫻の木
ユーザー 👑 ygussanyygussany
提出日時 2021-12-09 12:16:51
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,671 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 30,376 KB
実行使用メモリ 5,316 KB
最終ジャッジ日時 2023-09-24 05:38:21
合計ジャッジ時間 4,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 52 ms
4,376 KB
testcase_16 AC 51 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 36 ms
4,376 KB
testcase_21 AC 64 ms
4,380 KB
testcase_22 AC 67 ms
4,376 KB
testcase_23 AC 16 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 15 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 31 ms
4,376 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 62 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 28 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 0 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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][101][17], tmp, sum;
	for (i = 0; i < 26; i++) {
		for (j = 0; j <= 100; j++) {
			for (k = 1; k <= 16; k++) dp[i][j][k] = infll;
		}
		dp[i][0][C[i]] = 0;
		for (j = 0; j < 100; 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 <= 100 && j <= K[i]; j++) chmaxll(&tmp, dp[i][j][k]);
			if (K[i] > 100) {
				j = 2;
				for (l = 100 - j + 1; l <= 100; 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;
}
0