結果

問題 No.2259 Gas Station
ユーザー Yuu EguciYuu Eguci
提出日時 2023-04-21 16:09:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-24 03:59:40
合計ジャッジ時間 1,809 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
11,520 KB
testcase_01 AC 31 ms
11,520 KB
testcase_02 AC 31 ms
11,520 KB
testcase_03 AC 31 ms
11,520 KB
testcase_04 AC 31 ms
11,648 KB
testcase_05 AC 31 ms
11,520 KB
testcase_06 AC 32 ms
11,520 KB
testcase_07 AC 31 ms
11,520 KB
testcase_08 AC 32 ms
11,520 KB
testcase_09 AC 32 ms
11,520 KB
testcase_10 AC 34 ms
11,520 KB
testcase_11 AC 32 ms
11,520 KB
testcase_12 AC 32 ms
11,520 KB
testcase_13 AC 30 ms
11,520 KB
testcase_14 AC 32 ms
11,520 KB
testcase_15 AC 31 ms
11,648 KB
testcase_16 AC 31 ms
11,520 KB
testcase_17 AC 31 ms
11,520 KB
testcase_18 AC 31 ms
11,520 KB
testcase_19 AC 30 ms
11,520 KB
testcase_20 AC 33 ms
11,648 KB
testcase_21 AC 32 ms
11,520 KB
testcase_22 AC 32 ms
11,520 KB
testcase_23 AC 32 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import Tuple


def validate_input(L: int, R: int, C: int) -> Tuple[int, int, int]:
    """
    引数のバリデーションを行う関数
    """
    assert 1 <= L <= R, f"Invalid L: {L}"
    assert L <= R <= 10**9, f"Invalid R: {R}"
    assert 1 <= C <= 10**9, f"Invalid C: {C}"
    return L, R, C


def min_change(L: int, R: int, C: int) -> int:
    """
    お釣りの最小値を求める関数
    """
    L, R, C = validate_input(L, R, C)
    min_change = 1000

    for x in range(L, R + 1):
        cost = x * C
        change = 1000 - cost % 1000
        if cost % 1000 == 0:
            return 0
        if change < min_change:
            min_change = change

    return min_change if min_change != 1000 else 0


L, R, C = map(int, input().split())
print(min_change(L, R, C))
0