Submission #214360


Source Code Expand

#!/usr/bin/env python2.7

import sys
from collections import namedtuple

from cStringIO import StringIO
import unittest
import cProfile

def main():
    N, H = (int(x) for x in sys.stdin.readline().split())
    A, B, C, D, E = (int(x) for x in sys.stdin.readline().split())
    print solve(N, H, A, B, C, D, E)

def solve(N, H, A, B, C, D, E):
    assert N <= 10

    if N == 1:
        if H > E:
            return 0
        else:
            return C
    else:
        a = solve(N-1, H+B, A, B, C, D, E) + A
        b = solve(N-1, H+D, A, B, C, D, E) + C

        if H > E:
            c = solve(N-1, H-E, A, B, C, D, E)
            return min([a, b, c])
        else:
            return min([a, b])

    
class Test(unittest.TestCase):

    @staticmethod
    def tryone(indata):
        sys.stdin = StringIO(indata)
        out = sys.stdout = StringIO()
        main()
        return out.getvalue()

    def test51(self):
        self.assertEqual(solve(4, 5, 100, 4, 60, 1, 4), 160)

    def test52(self):
        self.assertEqual(solve(10, 1, 5000, 2, 2000, 1, 300), 20000)

    def test53(self):
        self.assertEqual(solve(9, 23, 170, 8, 120, 5, 12), 650)

    def test54(self):
        self.assertEqual(solve(653, 314159, 6728, 123456, 5141, 41928, 222222), 2818162)

    def test90(self):
        self.assertEqual(self.tryone("""\
4 5
100 4 60 1 4
"""), """\
160
""")

if __name__ == '__main__':
    if len(sys.argv) > 1:
        print "_/" * 30 + str(sys.argv)
        if sys.argv[1] == '-p':
            sys.argv.pop(1)
            cProfile.run("unittest.main(exit=False, failfast=True)", sort='time')
        else:
            unittest.main()
    else:
        main()

Submission Info

Submission Time
Task C - 節制
User over80
Language Python (2.7.3)
Score 10
Code Size 1752 Byte
Status RE
Exec Time 136 ms
Memory 8960 KB

Judge Result

Set Name Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 10 / 10 0 / 30 0 / 60 0 / 1
Status
AC × 25
AC × 5
RE × 20
AC × 27
RE × 59
AC × 24
RE × 75
Set Name Test Cases
Subtask1 sample_1.txt, sample_2.txt, sample_3.txt, 01_010.txt, 01_011.txt, 01_020.txt, 01_021.txt, 01_100.txt, 01_101.txt, 01_110.txt, 01_111.txt, 01_200.txt, 01_201.txt, 01_220.txt, 01_221.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt, 01_random08.txt, 01_random09.txt, 01_random10.txt
Subtask2 sample_1.txt, sample_2.txt, sample_3.txt, 02_010.txt, 02_011.txt, 02_020.txt, 02_021.txt, 02_100.txt, 02_101.txt, 02_110.txt, 02_111.txt, 02_200.txt, 02_201.txt, 02_220.txt, 02_221.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_random09.txt, 02_random10.txt
Subtask3 sample_1.txt, sample_2.txt, sample_3.txt, sample_4.txt, 01_010.txt, 01_011.txt, 01_020.txt, 01_021.txt, 01_100.txt, 01_101.txt, 01_110.txt, 01_111.txt, 01_200.txt, 01_201.txt, 01_220.txt, 01_221.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt, 01_random08.txt, 01_random09.txt, 01_random10.txt, 02_010.txt, 02_011.txt, 02_020.txt, 02_021.txt, 02_100.txt, 02_101.txt, 02_110.txt, 02_111.txt, 02_200.txt, 02_201.txt, 02_220.txt, 02_221.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_random09.txt, 02_random10.txt, 03_010.txt, 03_011.txt, 03_012.txt, 03_020.txt, 03_021.txt, 03_022.txt, 03_100.txt, 03_101.txt, 03_102.txt, 03_110.txt, 03_111.txt, 03_112.txt, 03_200.txt, 03_201.txt, 03_202.txt, 03_220.txt, 03_221.txt, 03_222.txt, 03_random01.txt, 03_random02.txt, 03_random03.txt, 03_random04.txt, 03_random05.txt, 03_random06.txt, 03_random07.txt, 03_random08.txt, 03_random09.txt, 03_random10.txt, 03_random11.txt, 03_random12.txt, 03_random13.txt, 03_random14.txt, 03_random15.txt, 03_random16.txt, 03_random17.txt, 03_random18.txt, 03_random19.txt, 03_random20.txt
Subtask4 01_010.txt, 01_011.txt, 01_020.txt, 01_021.txt, 01_100.txt, 01_101.txt, 01_110.txt, 01_111.txt, 01_200.txt, 01_201.txt, 01_220.txt, 01_221.txt, 01_random01.txt, 01_random02.txt, 01_random03.txt, 01_random04.txt, 01_random05.txt, 01_random06.txt, 01_random07.txt, 01_random08.txt, 01_random09.txt, 01_random10.txt, 02_010.txt, 02_011.txt, 02_020.txt, 02_021.txt, 02_100.txt, 02_101.txt, 02_110.txt, 02_111.txt, 02_200.txt, 02_201.txt, 02_220.txt, 02_221.txt, 02_random01.txt, 02_random02.txt, 02_random03.txt, 02_random04.txt, 02_random05.txt, 02_random06.txt, 02_random07.txt, 02_random08.txt, 02_random09.txt, 02_random10.txt, 03_010.txt, 03_011.txt, 03_012.txt, 03_020.txt, 03_021.txt, 03_022.txt, 03_100.txt, 03_101.txt, 03_102.txt, 03_110.txt, 03_111.txt, 03_112.txt, 03_200.txt, 03_201.txt, 03_202.txt, 03_220.txt, 03_221.txt, 03_222.txt, 03_random01.txt, 03_random02.txt, 03_random03.txt, 03_random04.txt, 03_random05.txt, 03_random06.txt, 03_random07.txt, 03_random08.txt, 03_random09.txt, 03_random10.txt, 03_random11.txt, 03_random12.txt, 03_random13.txt, 03_random14.txt, 03_random15.txt, 03_random16.txt, 03_random17.txt, 03_random18.txt, 03_random19.txt, 03_random20.txt, 04_010.txt, 04_011.txt, 04_020.txt, 04_021.txt, 04_100.txt, 04_101.txt, 04_110.txt, 04_111.txt, 04_200.txt, 04_201.txt, 04_220.txt, 04_221.txt, 04_random01.txt, 04_random02.txt, 04_random03.txt, 04_random04.txt, 04_random05.txt
Case Name Status Exec Time Memory
01_010.txt AC 76 ms 4268 KB
01_011.txt AC 71 ms 4432 KB
01_020.txt AC 72 ms 4432 KB
01_021.txt AC 70 ms 4440 KB
01_100.txt AC 71 ms 4428 KB
01_101.txt AC 73 ms 4264 KB
01_110.txt AC 70 ms 4428 KB
01_111.txt AC 71 ms 4432 KB
01_200.txt AC 71 ms 4244 KB
01_201.txt AC 72 ms 4432 KB
01_220.txt AC 77 ms 4444 KB
01_221.txt AC 74 ms 4440 KB
01_random01.txt AC 74 ms 4432 KB
01_random02.txt AC 78 ms 4440 KB
01_random03.txt AC 69 ms 4268 KB
01_random04.txt AC 74 ms 4440 KB
01_random05.txt AC 70 ms 4372 KB
01_random06.txt AC 72 ms 4376 KB
01_random07.txt AC 70 ms 4372 KB
01_random08.txt AC 77 ms 4440 KB
01_random09.txt AC 84 ms 4248 KB
01_random10.txt AC 73 ms 4440 KB
02_010.txt RE 133 ms 8824 KB
02_011.txt RE 129 ms 8900 KB
02_020.txt RE 130 ms 8824 KB
02_021.txt RE 128 ms 8948 KB
02_100.txt RE 135 ms 8952 KB
02_101.txt RE 130 ms 8956 KB
02_110.txt AC 69 ms 4440 KB
02_111.txt RE 128 ms 8948 KB
02_200.txt RE 131 ms 8952 KB
02_201.txt RE 131 ms 8820 KB
02_220.txt RE 134 ms 8828 KB
02_221.txt RE 126 ms 8952 KB
02_random01.txt RE 130 ms 8756 KB
02_random02.txt RE 129 ms 8752 KB
02_random03.txt RE 125 ms 8948 KB
02_random04.txt RE 131 ms 8756 KB
02_random05.txt RE 128 ms 8956 KB
02_random06.txt AC 71 ms 4372 KB
02_random07.txt RE 130 ms 8948 KB
02_random08.txt RE 133 ms 8956 KB
02_random09.txt RE 131 ms 8752 KB
02_random10.txt RE 129 ms 8752 KB
03_010.txt RE 132 ms 8956 KB
03_011.txt RE 127 ms 8884 KB
03_012.txt RE 130 ms 8752 KB
03_020.txt RE 131 ms 8820 KB
03_021.txt RE 127 ms 8752 KB
03_022.txt RE 127 ms 8940 KB
03_100.txt RE 136 ms 8952 KB
03_101.txt RE 129 ms 8764 KB
03_102.txt RE 130 ms 8892 KB
03_110.txt RE 132 ms 8776 KB
03_111.txt RE 131 ms 8952 KB
03_112.txt RE 135 ms 8952 KB
03_200.txt RE 130 ms 8956 KB
03_201.txt RE 131 ms 8752 KB
03_202.txt RE 127 ms 8776 KB
03_220.txt RE 130 ms 8756 KB
03_221.txt RE 131 ms 8956 KB
03_222.txt RE 130 ms 8960 KB
03_random01.txt RE 131 ms 8824 KB
03_random02.txt RE 130 ms 8820 KB
03_random03.txt RE 134 ms 8960 KB
03_random04.txt RE 128 ms 8880 KB
03_random05.txt RE 132 ms 8960 KB
03_random06.txt RE 129 ms 8952 KB
03_random07.txt RE 128 ms 8752 KB
03_random08.txt RE 131 ms 8952 KB
03_random09.txt RE 129 ms 8816 KB
03_random10.txt RE 129 ms 8952 KB
03_random11.txt RE 130 ms 8884 KB
03_random12.txt RE 131 ms 8940 KB
03_random13.txt RE 130 ms 8752 KB
03_random14.txt RE 129 ms 8928 KB
03_random15.txt RE 130 ms 8776 KB
03_random16.txt RE 132 ms 8756 KB
03_random17.txt RE 129 ms 8956 KB
03_random18.txt RE 130 ms 8776 KB
03_random19.txt RE 134 ms 8952 KB
03_random20.txt RE 133 ms 8956 KB
04_010.txt RE 130 ms 8952 KB
04_011.txt RE 134 ms 8952 KB
04_020.txt RE 130 ms 8952 KB
04_021.txt RE 130 ms 8776 KB
04_100.txt RE 131 ms 8956 KB
04_101.txt RE 128 ms 8948 KB
04_110.txt RE 130 ms 8956 KB
04_111.txt RE 129 ms 8880 KB
04_200.txt RE 129 ms 8948 KB
04_201.txt RE 132 ms 8948 KB
04_220.txt RE 126 ms 8948 KB
04_221.txt RE 128 ms 8884 KB
04_random01.txt RE 128 ms 8904 KB
04_random02.txt RE 127 ms 8948 KB
04_random03.txt RE 128 ms 8756 KB
04_random04.txt RE 130 ms 8892 KB
04_random05.txt RE 133 ms 8948 KB
sample_1.txt AC 68 ms 4436 KB
sample_2.txt AC 70 ms 4432 KB
sample_3.txt AC 73 ms 4432 KB
sample_4.txt RE 129 ms 8948 KB