結果

問題 No.1765 While Shining
ユーザー koba-e964koba-e964
提出日時 2021-11-26 23:18:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 433 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 105,408 KB
最終ジャッジ日時 2023-09-12 05:34:55
合計ジャッジ時間 4,328 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,304 KB
testcase_01 AC 76 ms
71,356 KB
testcase_02 AC 76 ms
71,340 KB
testcase_03 AC 77 ms
71,308 KB
testcase_04 AC 77 ms
71,376 KB
testcase_05 AC 78 ms
71,216 KB
testcase_06 AC 76 ms
71,516 KB
testcase_07 AC 76 ms
71,304 KB
testcase_08 AC 78 ms
71,260 KB
testcase_09 AC 107 ms
93,796 KB
testcase_10 AC 119 ms
105,308 KB
testcase_11 AC 112 ms
98,820 KB
testcase_12 AC 116 ms
102,056 KB
testcase_13 AC 113 ms
99,112 KB
testcase_14 AC 120 ms
105,292 KB
testcase_15 AC 119 ms
105,220 KB
testcase_16 AC 118 ms
105,220 KB
testcase_17 AC 120 ms
105,400 KB
testcase_18 AC 117 ms
105,220 KB
testcase_19 AC 119 ms
105,408 KB
testcase_20 AC 119 ms
105,400 KB
testcase_21 AC 119 ms
105,340 KB
testcase_22 AC 120 ms
105,308 KB
testcase_23 AC 119 ms
105,300 KB
testcase_24 AC 115 ms
105,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

n = int(readline())
a = list(map(int, readline().split()))

ans = 0
b = [0] * (n + 2)
for i in range(n - 1, -1, -1):
    if a[i] == 1:
        if i < n - 1 and a[i + 1] == 0:
            b[i] = b[i + 2] + 2
        else:
            b[i] = 1
    else:
        b[i] = 0
    b[i] = min(b[i], n - i - 1)
    ans += b[i]

print(ans)
0