AtCoder Beginner Contest 001

Submission #4467379

Source codeソースコード

def d_precipitation(N, Precipitation_periods):
    import itertools

    # 降雨を5分刻みにする
    rainfall = []
    for period in Precipitation_periods:
        # period: 'hhmm-hhmm' (降り始め時刻-降り終わり時刻)
        # start/end: 開始/終了 時刻(0時0分から何分経ったか)
        start_hhmm, end_hhmm = map(int, period.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分単位に丸める
        rainfall.append((start, end))

    precipitation = [0] * (1440 + 1 + 1)  # 1日を1分単位で表す. 24時に+1, 番兵に+1
    for start, end in rainfall:
        precipitation[start] += 1
        precipitation[end + 1] -= 1
    precipitation = itertools.accumulate(precipitation)

    # 開始終了時刻を復元
    ans_tmp = []
    is_zero = True  # Falseなら1以上の値が現れた
    start, end = 0, 0
    for i, t in enumerate(precipitation):
        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)
            ans_tmp.append(string.format(*str_format))
    ans = '\n'.join(ans_tmp)
    return ans

N = int(input())
Precipitation_periods = [input() for _ in range(N)]
print(d_precipitation(N, Precipitation_periods))

Submission

Task問題 D - 感雨時刻の整理
User nameユーザ名 kenseiQ
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 AC
Score得点 100
Source lengthソースコード長 1753 Byte
File nameファイル名
Exec time実行時間 112 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 109 ms 8484 KB
chokudai_ga_cho.txt AC 107 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 20 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 20 ms 3064 KB
test_21.txt AC 110 ms 9220 KB
test_22.txt AC 111 ms 9280 KB
test_23.txt AC 111 ms 9284 KB
test_24.txt AC 108 ms 9400 KB
test_25.txt AC 110 ms 9288 KB
test_26.txt AC 110 ms 9000 KB
test_27.txt AC 112 ms 9432 KB
test_28.txt AC 109 ms 9152 KB
test_29.txt AC 18 ms 3064 KB
test_30.txt AC 18 ms 3064 KB
test_31.txt AC 33 ms 3948 KB
test_32.txt AC 18 ms 3064 KB
test_33.txt AC 78 ms 6864 KB
test_34.txt AC 18 ms 3064 KB
test_35.txt AC 19 ms 3064 KB
test_36.txt AC 107 ms 9392 KB
test_37.txt AC 107 ms 9028 KB
test_38.txt AC 110 ms 9040 KB
test_39.txt AC 108 ms 9432 KB
test_40.txt AC 108 ms 8740 KB
test_41.txt AC 108 ms 9036 KB
test_42.txt AC 109 ms 9036 KB
test_43.txt AC 106 ms 9036 KB