Submission #22512784


Source Code Expand

import sys

input = sys.stdin.readline


def extgcd(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extgcd(b, a % b)
    y -= a // b * x
    return g, x, y


def main():
    n = int(input())
    a, b, c = reversed(sorted(map(int, input().split())))
    lim = 10000
    ans = lim
    g, x, y = extgcd(b, c)
    for i in range(lim):
        rem = n - a * i
        if rem >= 0 and rem % g == 0:
            j = x * (rem // g)
            k = y * (rem // g)
            tk = k % (b // g)
            j -= (tk - k) // (b // g) * (c // g)
            k = tk
            if j >= 0:
                ans = min(ans, i + j + k)

    print(ans)


if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task 016 - Minimum Coins(★3)
User riantkb
Language Python (3.8.2)
Score 3
Code Size 685 Byte
Status AC
Exec Time 32 ms
Memory 9032 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 3 / 3
Status
AC × 4
AC × 21
Set Name Test Cases
Sample sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt
All rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt, rand_05.txt, rand_06.txt, rand_07.txt, rand_08.txt, rand_09.txt, rand_10.txt, rand_large_abc_1.txt, rand_large_abc_2.txt, rand_large_abc_3.txt, sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, small_1.txt, small_2.txt, small_3.txt, small_4.txt
Case Name Status Exec Time Memory
rand_01.txt AC 32 ms 9028 KiB
rand_02.txt AC 22 ms 8888 KiB
rand_03.txt AC 23 ms 8868 KiB
rand_04.txt AC 25 ms 8944 KiB
rand_05.txt AC 24 ms 9028 KiB
rand_06.txt AC 27 ms 8904 KiB
rand_07.txt AC 30 ms 8964 KiB
rand_08.txt AC 24 ms 8940 KiB
rand_09.txt AC 24 ms 8904 KiB
rand_10.txt AC 30 ms 8836 KiB
rand_large_abc_1.txt AC 25 ms 8944 KiB
rand_large_abc_2.txt AC 22 ms 9020 KiB
rand_large_abc_3.txt AC 26 ms 8892 KiB
sample_1.txt AC 19 ms 8860 KiB
sample_2.txt AC 25 ms 8888 KiB
sample_3.txt AC 19 ms 8948 KiB
sample_4.txt AC 23 ms 8876 KiB
small_1.txt AC 24 ms 8872 KiB
small_2.txt AC 22 ms 8908 KiB
small_3.txt AC 20 ms 9032 KiB
small_4.txt AC 31 ms 8956 KiB