Submission #1687093


Source Code Expand

def C_123sub(N, NG):
    """
    n:nから1,2,3のどれかを引いていき、0にできればOK
    ng:引いていく際にこのリストの要素と一致してはいけない
    """
    if N in NG:
        return 'NO'
    if N <= 3:
        # 動的計画法の中で、要素数が3未満だと境界エラーになるため
        return 'YES'

    # dpのk番目の要素は、数字kにたどり着くまでの最短手数
    dp = [float('inf') for _ in range(N + 1)]
    dp[N] = 0
    for i in range(N, -1, -1):
        if i in NG:
            continue
        for j in [1, 2, 3]:
            dp[i - j] = min(dp[i] + 1, dp[i - j])

    if dp[0] <= 100:
        return 'YES'
    else:
        return 'NO'

N = int(input())
NG = [int(input()) for i in range(3)]
print(C_123sub(N, NG))

Submission Info

Submission Time
Task C - 123引き算
User kenseiQ
Language Python (3.4.3)
Score 100
Code Size 824 Byte
Status AC
Exec Time 21 ms
Memory 3188 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 31
Set Name Test Cases
All sample_01.txt, sample_02.txt, sample_03.txt, test_143_142_141_140.txt, test_1_1_2_3.txt, test_1_2_3_4.txt, test_200_200_2_3.txt, test_231_77_78_80.txt, test_235_124_126_125.txt, test_253_45_47_48.txt, test_297_223_224_225.txt, test_297_294_292_290.txt, test_297_297_30_83.txt, test_297_3_43_72.txt, test_298_125_123_124.txt, test_298_293_295_291.txt, test_298_298_4_8.txt, test_298_36_72_98.txt, test_298_55_3_43.txt, test_298_92_91_295.txt, test_299_200_151_65.txt, test_299_240_35_154.txt, test_299_300_299_298.txt, test_299_33_242_151.txt, test_299_56_57_58.txt, test_299_66_132_198.txt, test_300_271_44_68.txt, test_300_299_298_296.txt, test_300_30_99_183.txt, test_300_4_5_6.txt, test_84_34_64_36.txt
Case Name Status Exec Time Memory
sample_01.txt AC 18 ms 3064 KB
sample_02.txt AC 18 ms 3064 KB
sample_03.txt AC 18 ms 3064 KB
test_143_142_141_140.txt AC 19 ms 3064 KB
test_1_1_2_3.txt AC 18 ms 3064 KB
test_1_2_3_4.txt AC 18 ms 3064 KB
test_200_200_2_3.txt AC 18 ms 3064 KB
test_231_77_78_80.txt AC 19 ms 3064 KB
test_235_124_126_125.txt AC 19 ms 3064 KB
test_253_45_47_48.txt AC 18 ms 3064 KB
test_297_223_224_225.txt AC 18 ms 3064 KB
test_297_294_292_290.txt AC 18 ms 3064 KB
test_297_297_30_83.txt AC 18 ms 3064 KB
test_297_3_43_72.txt AC 19 ms 3064 KB
test_298_125_123_124.txt AC 19 ms 3064 KB
test_298_293_295_291.txt AC 19 ms 3064 KB
test_298_298_4_8.txt AC 18 ms 3064 KB
test_298_36_72_98.txt AC 19 ms 3064 KB
test_298_55_3_43.txt AC 19 ms 3064 KB
test_298_92_91_295.txt AC 18 ms 3064 KB
test_299_200_151_65.txt AC 18 ms 3064 KB
test_299_240_35_154.txt AC 18 ms 3064 KB
test_299_300_299_298.txt AC 18 ms 3064 KB
test_299_33_242_151.txt AC 18 ms 3064 KB
test_299_56_57_58.txt AC 18 ms 3064 KB
test_299_66_132_198.txt AC 18 ms 3064 KB
test_300_271_44_68.txt AC 18 ms 3064 KB
test_300_299_298_296.txt AC 19 ms 3064 KB
test_300_30_99_183.txt AC 21 ms 3188 KB
test_300_4_5_6.txt AC 19 ms 3064 KB
test_84_34_64_36.txt AC 18 ms 3064 KB