Submission #4467331


Source Code Expand

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 // 5, end // 5))  # 5分単位に変換

    precipitation = [0] * (288 + 1 + 1)  # 1日を5分単位で表す. 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 * 5 // 60, start * 5 % 60, end * 5 // 60, end * 5 % 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 Info

Submission Time
Task D - 感雨時刻の整理
User kenseiQ
Language Python (3.4.3)
Score 0
Code Size 1801 Byte
Status WA
Exec Time 113 ms
Memory 8488 KB

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
AC × 35
WA × 13
Set Name Test Cases
all 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
Case Name Status Exec Time Memory
00_sample_01.txt AC 18 ms 3064 KB
00_sample_02.txt AC 17 ms 3064 KB
00_sample_03.txt WA 17 ms 3064 KB
cho_cho_chokudai.txt AC 103 ms 8488 KB
chokudai_ga_cho.txt AC 112 ms 7720 KB
test_01.txt WA 18 ms 3064 KB
test_02.txt WA 18 ms 3064 KB
test_03.txt WA 18 ms 3064 KB
test_04.txt WA 18 ms 3064 KB
test_05.txt WA 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 3064 KB
test_10.txt AC 20 ms 3188 KB
test_11.txt AC 20 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 3064 KB
test_15.txt AC 20 ms 3188 KB
test_16.txt AC 18 ms 3064 KB
test_17.txt AC 19 ms 3064 KB
test_18.txt AC 18 ms 3064 KB
test_19.txt AC 19 ms 3064 KB
test_20.txt AC 19 ms 3064 KB
test_21.txt AC 112 ms 7796 KB
test_22.txt AC 113 ms 8092 KB
test_23.txt AC 112 ms 7944 KB
test_24.txt AC 113 ms 8112 KB
test_25.txt AC 113 ms 7992 KB
test_26.txt AC 110 ms 7744 KB
test_27.txt AC 111 ms 7452 KB
test_28.txt WA 112 ms 7692 KB
test_29.txt AC 18 ms 3064 KB
test_30.txt WA 18 ms 3064 KB
test_31.txt WA 32 ms 3700 KB
test_32.txt WA 18 ms 3064 KB
test_33.txt WA 79 ms 6004 KB
test_34.txt AC 17 ms 3064 KB
test_35.txt AC 18 ms 3064 KB
test_36.txt AC 110 ms 7432 KB
test_37.txt WA 110 ms 7744 KB
test_38.txt WA 110 ms 7744 KB
test_39.txt AC 112 ms 7744 KB
test_40.txt AC 110 ms 7652 KB
test_41.txt AC 111 ms 7784 KB
test_42.txt AC 108 ms 7672 KB
test_43.txt AC 109 ms 7680 KB