AtCoder Beginner Contest 054

Submission #1355632

Source codeソースコード

N, A, B = map(int, input().split())
a = [(a, b, c) for i in range(N) for a, b, c in [map(int, input().split())]]
inf = 10 ** 5
dp = [[None] * (N * 10 + 1) for i in range(N * 10 + 1)]
price = inf
dp[0][0] = 0
s = set(((0, 0),))

for i in range(1, N + 1):
    ai, bi, ci = a[i - 1]
    ns = s.copy()
    s = sorted(s, reverse=1)
    for _a, _b in s:
        _c = dp[_a][_b]
        na, nb = _a + ai, _b + bi
        dp[_a][_b] = _c if dp[_a][_b] is None else min(dp[_a][_b], _c)
        dp[na][nb] = ci + _c if dp[na][nb] is None else min(dp[na][nb], ci + _c)
        ns.add((na, nb))
        if (na) * B == (nb) * A:
            price = min(price, dp[na][nb])
    s = ns

print(price if price != inf else -1)

Submission

Task問題 D - Mixing Experiment
User nameユーザ名 htkb
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 AC
Score得点 400
Source lengthソースコード長 729 Byte
File nameファイル名
Exec time実行時間 604 ms
Memory usageメモリ使用量 8476 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt
All 400 / 400 sample_01.txt,sample_02.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 17 ms 3064 KB
sample_02.txt AC 17 ms 3064 KB
subtask_1_01.txt AC 18 ms 3064 KB
subtask_1_02.txt AC 17 ms 3064 KB
subtask_1_03.txt AC 18 ms 3064 KB
subtask_1_04.txt AC 19 ms 3188 KB
subtask_1_05.txt AC 25 ms 3316 KB
subtask_1_06.txt AC 53 ms 3892 KB
subtask_1_07.txt AC 82 ms 4360 KB
subtask_1_08.txt AC 100 ms 4484 KB
subtask_1_09.txt AC 151 ms 5496 KB
subtask_1_10.txt AC 241 ms 5972 KB
subtask_1_11.txt AC 339 ms 6540 KB
subtask_1_12.txt AC 604 ms 8460 KB
subtask_1_13.txt AC 498 ms 8240 KB
subtask_1_14.txt AC 475 ms 6984 KB
subtask_1_15.txt AC 533 ms 8428 KB
subtask_1_16.txt AC 563 ms 8476 KB
subtask_1_17.txt AC 590 ms 8384 KB
subtask_1_18.txt AC 547 ms 8400 KB