結果

問題 No.1765 While Shining
ユーザー kohei2019kohei2019
提出日時 2023-06-22 22:15:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 135,200 KB
最終ジャッジ日時 2023-09-12 16:33:26
合計ジャッジ時間 4,969 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,484 KB
testcase_01 AC 72 ms
71,192 KB
testcase_02 AC 71 ms
71,288 KB
testcase_03 AC 72 ms
71,388 KB
testcase_04 AC 72 ms
71,084 KB
testcase_05 AC 73 ms
71,172 KB
testcase_06 AC 73 ms
71,312 KB
testcase_07 AC 72 ms
71,160 KB
testcase_08 AC 73 ms
71,300 KB
testcase_09 AC 125 ms
111,448 KB
testcase_10 AC 146 ms
134,408 KB
testcase_11 AC 133 ms
122,152 KB
testcase_12 AC 140 ms
127,972 KB
testcase_13 AC 133 ms
121,752 KB
testcase_14 AC 145 ms
134,948 KB
testcase_15 AC 144 ms
134,972 KB
testcase_16 AC 144 ms
134,960 KB
testcase_17 AC 142 ms
135,108 KB
testcase_18 AC 145 ms
135,020 KB
testcase_19 AC 145 ms
135,156 KB
testcase_20 AC 145 ms
135,016 KB
testcase_21 AC 145 ms
135,024 KB
testcase_22 AC 144 ms
135,084 KB
testcase_23 AC 144 ms
135,012 KB
testcase_24 AC 141 ms
135,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
lsA = list(map(int,input().split()))
lsA1 = []
lsA2 = []
for i in range(N):
    if i%2==0:
        lsA1.append(lsA[i])
        lsA2.append(lsA[i]^1)
    else:
        lsA1.append(lsA[i]^1)
        lsA2.append(lsA[i])

lsA1.append(0)
lsA2.append(0)
lsA1G = [0]*(N+1)
lsA2G = [0]*(N+1)
max1 = N-1
max2 = N-1
for i in range(N-1,-1,-1):
    if lsA1[i]==0:
        max1 = i
    if lsA2[i]==0:
        max2 = i
    lsA1G[i] = max1
    lsA2G[i] = max2
ans = 0
for i in range(N-1):
    if i%2==0:
        ans += lsA1G[i]-i
    else:
        ans += lsA2G[i]-i
print(ans)
0