結果

問題 No.3044 よくあるカエルさん
ユーザー gew1fw
提出日時 2025-06-12 15:19:28
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,128 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 844,464 KB
最終ジャッジ日時 2025-06-12 15:19:34
合計ジャッジ時間 2,544 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other MLE * 1 -- * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    M = int(input[idx])
    idx += 1
    A = list(map(int, input[idx:idx+N]))
    idx += N

    # Compute prefix sums
    prefix_sum = [0] * (N + 1)
    for i in range(N):
        prefix_sum[i+1] = prefix_sum[i] + A[i]

    result = []
    in_run = False
    start = 0

    for i in range(N):
        if A[i] % 2 == 1:
            if not in_run:
                start = i
                in_run = True
        else:
            if in_run:
                end = i - 1
                run_length = end - start + 1
                if run_length >= M:
                    s = prefix_sum[end + 1] - prefix_sum[start]
                    result.append(s)
                in_run = False

    # Check if the last run is still active
    if in_run:
        end = N - 1
        run_length = end - start + 1
        if run_length >= M:
            s = prefix_sum[end + 1] - prefix_sum[start]
            result.append(s)

    # Print the results
    for num in result:
        print(num)

if __name__ == "__main__":
    main()
0