結果

問題 No.3044 よくあるカエルさん
ユーザー gew1fw
提出日時 2025-06-12 20:22:01
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,147 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 82,000 KB
実行使用メモリ 843,948 KB
最終ジャッジ日時 2025-06-12 20:22:23
合計ジャッジ時間 3,558 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 = [0] * (N + 1)
    for i in range(N):
        prefix[i+1] = prefix[i] + A[i]
    
    runs = []
    current_start = -1
    current_length = 0
    
    for i in range(N):
        if A[i] % 2 != 0:
            if current_length == 0:
                current_start = i
            current_length += 1
        else:
            if current_length > 0:
                runs.append((current_start, current_length))
                current_length = 0
    # Add the last run if any
    if current_length > 0:
        runs.append((current_start, current_length))
    
    # Collect all valid runs and compute their sums
    results = []
    for start, length in runs:
        if length >= M:
            end = start + length
            s = prefix[end] - prefix[start]
            results.append(s)
    
    # Output the results
    for res in results:
        print(res)

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