結果

問題 No.1765 While Shining
ユーザー tamatotamato
提出日時 2021-11-26 22:29:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 87,672 KB
実行使用メモリ 111,124 KB
最終ジャッジ日時 2023-09-12 05:09:38
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,736 KB
testcase_01 AC 77 ms
71,688 KB
testcase_02 AC 77 ms
71,540 KB
testcase_03 AC 76 ms
71,464 KB
testcase_04 AC 75 ms
71,420 KB
testcase_05 AC 78 ms
71,888 KB
testcase_06 AC 75 ms
71,412 KB
testcase_07 AC 76 ms
71,520 KB
testcase_08 AC 78 ms
71,384 KB
testcase_09 AC 117 ms
97,120 KB
testcase_10 AC 136 ms
110,376 KB
testcase_11 AC 128 ms
103,664 KB
testcase_12 AC 131 ms
106,756 KB
testcase_13 AC 128 ms
103,328 KB
testcase_14 AC 135 ms
110,804 KB
testcase_15 AC 138 ms
110,960 KB
testcase_16 AC 138 ms
111,060 KB
testcase_17 AC 139 ms
110,956 KB
testcase_18 AC 136 ms
111,124 KB
testcase_19 AC 138 ms
111,012 KB
testcase_20 AC 138 ms
110,852 KB
testcase_21 AC 143 ms
110,904 KB
testcase_22 AC 137 ms
110,880 KB
testcase_23 AC 136 ms
110,896 KB
testcase_24 AC 134 ms
111,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    AA = A[:]
    ans = 0
    for i in range(N):
        if i & 1:
            AA[i] ^= 1
    cnt = [0] * N
    for i in range(N-2, -1, -1):
        if AA[i] == 1:
            cnt[i] = cnt[i+1] + 1
        else:
            cnt[i] = 0
    for i in range(N):
        if i & 1 == 0:
            ans += cnt[i]

    AA = A[:]
    for i in range(N):
        if i & 1 == 0:
            AA[i] ^= 1
    cnt = [0] * N
    for i in range(N - 2, -1, -1):
        if AA[i] == 1:
            cnt[i] = cnt[i + 1] + 1
        else:
            cnt[i] = 0
    for i in range(N):
        if i & 1:
            ans += cnt[i]

    print(ans)


if __name__ == '__main__':
    main()
0