結果

問題 No.1765 While Shining
ユーザー brthyyjpbrthyyjp
提出日時 2021-12-14 17:57:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 373 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 120,052 KB
最終ジャッジ日時 2023-10-01 02:10:21
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,304 KB
testcase_01 AC 69 ms
71,132 KB
testcase_02 AC 74 ms
71,440 KB
testcase_03 AC 72 ms
71,372 KB
testcase_04 AC 71 ms
71,440 KB
testcase_05 AC 74 ms
71,464 KB
testcase_06 AC 74 ms
71,276 KB
testcase_07 AC 72 ms
71,172 KB
testcase_08 AC 72 ms
71,132 KB
testcase_09 AC 127 ms
102,504 KB
testcase_10 AC 134 ms
119,384 KB
testcase_11 AC 125 ms
110,184 KB
testcase_12 AC 128 ms
114,660 KB
testcase_13 AC 122 ms
110,276 KB
testcase_14 AC 133 ms
119,892 KB
testcase_15 AC 134 ms
119,792 KB
testcase_16 AC 135 ms
120,052 KB
testcase_17 AC 134 ms
119,928 KB
testcase_18 AC 134 ms
119,728 KB
testcase_19 AC 133 ms
119,932 KB
testcase_20 AC 135 ms
119,868 KB
testcase_21 AC 135 ms
119,796 KB
testcase_22 AC 132 ms
119,832 KB
testcase_23 AC 132 ms
119,832 KB
testcase_24 AC 126 ms
119,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

B = []
for i, a in enumerate(A):
    if i%2 == 1:
        B.append(1-a)
    else:
        B.append(a)

pre = n
cur = -1
C = [0]*n
for i in reversed(range(n)):
    if B[i] != cur:
        pre = i
        cur = B[i]
    C[i] = pre+1

ans = 0
for i, a in enumerate(A):
    if a:
        ans += min(C[i], n-1)-i
print(ans)
0