AtCoder Beginner Contest 001

Submission #2907632

Source codeソースコード

def d_precipitation(N, TIME):
    import itertools
    # 時刻を5分刻みにする
    time = []
    for rain in TIME:
        # rain:'降り始め時刻(hh時mm分)-降り終わり時刻(hh時mm分)'
        # start/end : 開始/終了 時刻(0時0分からの経過時間(分))
        start_hhmm, end_hhmm = [int(i) for i in rain.split('-')]
        start = (start_hhmm // 100) * 60 + (start_hhmm % 100)
        end = (end_hhmm // 100) * 60 + (end_hhmm % 100)
        start -= start % 5  # 直前の5分単位に丸める
        end += (5 - (end % 5)) % 5  # 直後の5分単位に丸める
        time.append((start, end))

    time_part = [0] * 1442  # 1440分(1日)に分ける.0分のため+1,番兵に+1
    for start, end in time:
        time_part[start] += 1
        time_part[end + 1] -= 1
    time_part = itertools.accumulate(time_part)

    # 開始終了時刻を復元
    tmp = []
    is_zero = True  # Trueなら0が,Falseなら1以上の値が現れた
    start, end = 0, 0
    for i, t in enumerate(time_part):
        if t > 0 and is_zero:  # 0でない値が現れたので開始時刻とする
            start = i
            is_zero = False
        if t == 0 and not is_zero:  # 0が現れたのでその1つ前を終了時刻とする
            end = i - 1
            is_zero = True
            string = '{0:02d}{1:02d}-{2:02d}{3:02d}'
            str_format = [start // 60, start % 60, end // 60, end % 60]
            tmp.append(string.format(*str_format))
    ans = '\n'.join(tmp)
    return ans

N = int(input())
TIME = [input() for i in range(N)]
print(d_precipitation(N, TIME))

Submission

Task問題 D - 感雨時刻の整理
User nameユーザ名 kenseiQ
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 AC
Score得点 100
Source lengthソースコード長 1658 Byte
File nameファイル名
Exec time実行時間 119 ms
Memory usageメモリ使用量 9432 KB

Test case

Set

Set name Score得点 / Max score Cases
all 100 / 100 00_sample_01.txt,00_sample_02.txt,00_sample_03.txt,cho_cho_chokudai.txt,chokudai_ga_cho.txt,test_01.txt,test_02.txt,test_03.txt,test_04.txt,test_05.txt,test_06.txt,test_07.txt,test_08.txt,test_09.txt,test_10.txt,test_11.txt,test_12.txt,test_13.txt,test_14.txt,test_15.txt,test_16.txt,test_17.txt,test_18.txt,test_19.txt,test_20.txt,test_21.txt,test_22.txt,test_23.txt,test_24.txt,test_25.txt,test_26.txt,test_27.txt,test_28.txt,test_29.txt,test_30.txt,test_31.txt,test_32.txt,test_33.txt,test_34.txt,test_35.txt,test_36.txt,test_37.txt,test_38.txt,test_39.txt,test_40.txt,test_41.txt,test_42.txt,test_43.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_sample_01.txt AC 18 ms 3064 KB
00_sample_02.txt AC 18 ms 3064 KB
00_sample_03.txt AC 18 ms 3064 KB
cho_cho_chokudai.txt AC 110 ms 8488 KB
chokudai_ga_cho.txt AC 114 ms 9036 KB
test_01.txt AC 18 ms 3064 KB
test_02.txt AC 18 ms 3064 KB
test_03.txt AC 18 ms 3064 KB
test_04.txt AC 18 ms 3064 KB
test_05.txt AC 18 ms 3064 KB
test_06.txt AC 18 ms 3064 KB
test_07.txt AC 18 ms 3064 KB
test_08.txt AC 18 ms 3064 KB
test_09.txt AC 20 ms 3188 KB
test_10.txt AC 20 ms 3188 KB
test_11.txt AC 19 ms 3064 KB
test_12.txt AC 19 ms 3064 KB
test_13.txt AC 18 ms 3064 KB
test_14.txt AC 19 ms 3188 KB
test_15.txt AC 20 ms 3188 KB
test_16.txt AC 18 ms 3064 KB
test_17.txt AC 19 ms 3188 KB
test_18.txt AC 18 ms 3064 KB
test_19.txt AC 19 ms 3064 KB
test_20.txt AC 19 ms 3188 KB
test_21.txt AC 113 ms 9120 KB
test_22.txt AC 117 ms 9396 KB
test_23.txt AC 116 ms 9288 KB
test_24.txt AC 113 ms 9292 KB
test_25.txt AC 113 ms 9276 KB
test_26.txt AC 116 ms 8992 KB
test_27.txt AC 113 ms 9432 KB
test_28.txt AC 119 ms 9156 KB
test_29.txt AC 18 ms 3064 KB
test_30.txt AC 18 ms 3064 KB
test_31.txt AC 32 ms 3948 KB
test_32.txt AC 18 ms 3064 KB
test_33.txt AC 81 ms 6856 KB
test_34.txt AC 18 ms 3064 KB
test_35.txt AC 18 ms 3064 KB
test_36.txt AC 115 ms 9392 KB
test_37.txt AC 112 ms 9020 KB
test_38.txt AC 112 ms 9036 KB
test_39.txt AC 115 ms 9324 KB
test_40.txt AC 116 ms 8732 KB
test_41.txt AC 115 ms 9036 KB
test_42.txt AC 115 ms 9016 KB
test_43.txt AC 113 ms 9036 KB