結果

問題 No.1765 While Shining
ユーザー KudeKude
提出日時 2021-11-26 22:36:35
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 498 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 111,336 KB
最終ジャッジ日時 2023-09-12 05:14:39
合計ジャッジ時間 4,241 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,456 KB
testcase_01 AC 74 ms
71,248 KB
testcase_02 AC 71 ms
71,244 KB
testcase_03 AC 73 ms
71,524 KB
testcase_04 AC 72 ms
71,224 KB
testcase_05 AC 80 ms
75,620 KB
testcase_06 AC 75 ms
71,240 KB
testcase_07 AC 73 ms
71,228 KB
testcase_08 AC 78 ms
75,752 KB
testcase_09 AC 117 ms
97,324 KB
testcase_10 AC 132 ms
110,580 KB
testcase_11 AC 120 ms
103,440 KB
testcase_12 AC 127 ms
107,052 KB
testcase_13 AC 118 ms
103,256 KB
testcase_14 AC 130 ms
111,308 KB
testcase_15 AC 129 ms
111,180 KB
testcase_16 AC 129 ms
111,224 KB
testcase_17 AC 130 ms
111,336 KB
testcase_18 AC 130 ms
111,336 KB
testcase_19 AC 129 ms
111,292 KB
testcase_20 AC 130 ms
111,160 KB
testcase_21 AC 132 ms
111,152 KB
testcase_22 AC 130 ms
111,204 KB
testcase_23 AC 136 ms
111,320 KB
testcase_24 AC 123 ms
110,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

b0 = a[:]
b1 = a[:]

for i in range(n):
    if i % 2 == 0:
        b0[i] ^= 1
    else:
        b1[i] ^= 1

nxt0 = [n - 1] * n
nxt1 = [n - 1] * n
for b, nxt in ((b0, nxt0), (b1, nxt1)):
    x = n - 1
    for i in range(n)[::-1]:
        nxt[i] = x
        if b[i] == 1:
            x = i

ans = 0
for i in range(n):
    if a[i] == 0:
        continue
    if i % 2 == 0:
        ans += nxt0[i] - i
    else:
        ans += nxt1[i] - i
print(ans)
0