結果

問題 No.1782 ManyCoins
ユーザー 👑 ygussanyygussany
提出日時 2021-12-11 23:08:36
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 29,668 KB
実行使用メモリ 27,720 KB
最終ジャッジ日時 2023-09-27 12:20:09
合計ジャッジ時間 3,960 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 22 ms
15,728 KB
testcase_14 AC 80 ms
24,792 KB
testcase_15 AC 48 ms
18,408 KB
testcase_16 AC 57 ms
23,420 KB
testcase_17 AC 85 ms
24,340 KB
testcase_18 AC 60 ms
24,952 KB
testcase_19 AC 1 ms
6,096 KB
testcase_20 AC 76 ms
23,392 KB
testcase_21 AC 79 ms
27,720 KB
testcase_22 AC 116 ms
24,204 KB
testcase_23 AC 95 ms
23,424 KB
testcase_24 AC 3 ms
13,116 KB
testcase_25 AC 89 ms
24,360 KB
testcase_26 AC 47 ms
17,492 KB
testcase_27 AC 96 ms
24,692 KB
testcase_28 AC 3 ms
11,732 KB
testcase_29 AC 25 ms
25,260 KB
testcase_30 AC 4 ms
12,428 KB
testcase_31 AC 19 ms
20,968 KB
testcase_32 AC 25 ms
22,136 KB
testcase_33 AC 44 ms
26,516 KB
testcase_34 AC 7 ms
12,112 KB
testcase_35 AC 5 ms
15,164 KB
testcase_36 AC 8 ms
11,332 KB
testcase_37 AC 3 ms
14,188 KB
testcase_38 AC 3 ms
12,340 KB
testcase_39 AC 1 ms
6,780 KB
testcase_40 AC 3 ms
11,920 KB
testcase_41 AC 2 ms
10,320 KB
testcase_42 AC 2 ms
10,984 KB
testcase_43 AC 2 ms
9,824 KB
testcase_44 AC 2 ms
12,616 KB
testcase_45 AC 3 ms
10,952 KB
testcase_46 AC 2 ms
4,892 KB
testcase_47 AC 1 ms
5,012 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 3 ms
12,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main()
{
	int i, N, W[21], max = 0;
	long long L;
	scanf("%d %lld", &N, &L);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(W[i]));
		if (max < W[i]) max = W[i];
	}
	
	const long long sup = 1LL << 40;
	int j, k, head, tail;
	long long ans = -1, dist[1000001], q[2000001][2], tmp;
	for (i = 1, dist[0] = 0, q[max][0] = 0, q[max][1] = 0; i < max; i++) dist[i] = sup;
	for (head = max, tail = max + 1; head < tail; head++) {
		i = q[head][0];
		if (q[head][1] != dist[i]) continue;
		if (L % max >= i) tmp = L / max * max + i;
		else tmp = (L / max - 1) * max + i;
		if (tmp < dist[i] * max + i) continue;
		ans += (tmp - (dist[i] * max + i)) / max + 1;
		
		for (j = 1; j <= N; j++) {
			if (W[j] == max) continue;
			if (i + W[j] < max) {
				k = i + W[j];
				if (dist[k] > dist[i]) {
					dist[k] = dist[i];
					q[head][0] = k;
					q[head--][1] = dist[k];
				}
			} else {
				k = i + W[j] - max;
				if (dist[k] > dist[i] + 1) {
					dist[k] = dist[i] + 1;
					q[tail][0] = k;
					q[tail++][1] = dist[k];
				}
			}
		}
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}
0