AtCoder Beginner Contest 054

Submission #1354004

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 j in range(N*10+1)] for i in range(N+1)]
price = inf
dp[0][0][0] = 0
s = set(((0,0),))

for i in range(1, N+1):
    ai, bi, ci = a[i-1]
    ns = s.copy()
    for _a, _b in s:
        _c = dp[i-1][_a][_b]
        na, nb = _a+ai, _b+bi
        dp[i][_a][_b] = _c if dp[i][_a][_b] is None else min(dp[i][_a][_b], _c)
        dp[i][na][nb] = ci+_c if dp[i][na][nb] is None else min(dp[i][na][nb], ci+_c)
        ns.add((na,nb))
        if (na)*B == (nb)*A:
            price = min(price, dp[i][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ソースコード長 716 Byte
File nameファイル名
Exec time実行時間 642 ms
Memory usageメモリ使用量 62928 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 3188 KB
subtask_1_02.txt AC 17 ms 3064 KB
subtask_1_03.txt AC 18 ms 3188 KB
subtask_1_04.txt AC 21 ms 3956 KB
subtask_1_05.txt AC 28 ms 5228 KB
subtask_1_06.txt AC 58 ms 8784 KB
subtask_1_07.txt AC 87 ms 12504 KB
subtask_1_08.txt AC 113 ms 14804 KB
subtask_1_09.txt AC 175 ms 24088 KB
subtask_1_10.txt AC 278 ms 36124 KB
subtask_1_11.txt AC 393 ms 52332 KB
subtask_1_12.txt AC 642 ms 62360 KB
subtask_1_13.txt AC 543 ms 62300 KB
subtask_1_14.txt AC 527 ms 61168 KB
subtask_1_15.txt AC 564 ms 61996 KB
subtask_1_16.txt AC 625 ms 62928 KB
subtask_1_17.txt AC 621 ms 62276 KB
subtask_1_18.txt AC 568 ms 62216 KB