結果

問題 No.1765 While Shining
ユーザー roarisroaris
提出日時 2021-12-09 16:45:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 472 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 104,896 KB
最終ジャッジ日時 2023-09-24 09:01:41
合計ジャッジ時間 4,945 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,132 KB
testcase_01 AC 73 ms
71,208 KB
testcase_02 AC 74 ms
71,192 KB
testcase_03 AC 71 ms
71,260 KB
testcase_04 AC 73 ms
71,256 KB
testcase_05 AC 74 ms
71,252 KB
testcase_06 AC 72 ms
71,332 KB
testcase_07 AC 73 ms
71,136 KB
testcase_08 AC 76 ms
71,392 KB
testcase_09 AC 115 ms
93,380 KB
testcase_10 AC 128 ms
104,236 KB
testcase_11 AC 121 ms
98,172 KB
testcase_12 AC 128 ms
101,100 KB
testcase_13 AC 121 ms
98,260 KB
testcase_14 AC 131 ms
104,196 KB
testcase_15 AC 133 ms
104,704 KB
testcase_16 AC 130 ms
104,452 KB
testcase_17 AC 130 ms
104,896 KB
testcase_18 AC 130 ms
104,672 KB
testcase_19 AC 131 ms
104,196 KB
testcase_20 AC 133 ms
104,416 KB
testcase_21 AC 130 ms
104,524 KB
testcase_22 AC 130 ms
104,756 KB
testcase_23 AC 132 ms
104,280 KB
testcase_24 AC 112 ms
104,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
i = 0
ans = 0

while i<N:
    if A[i]==0:
        i += 1
    else:
        j = i
        
        while j<N:
            if ((j-i)%2==0 and A[j]==0) or ((j-i)%2==1 and A[j]==1):
                break
            j += 1
        
        l = j-i
        
        if j==N:
            l -= 1
        
        for k in range(l, -1, -2):
            ans += k

        i = j

print(ans)
0