結果

問題 No.1505 Zero-Product Ranges
ユーザー kichi2004_kichi2004_
提出日時 2021-04-01 23:17:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,211 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 14,352 KB
最終ジャッジ日時 2023-08-23 07:05:01
合計ジャッジ時間 6,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
9,732 KB
testcase_01 AC 30 ms
9,800 KB
testcase_02 AC 30 ms
9,784 KB
testcase_03 AC 124 ms
12,720 KB
testcase_04 AC 125 ms
12,864 KB
testcase_05 AC 69 ms
11,568 KB
testcase_06 AC 65 ms
10,936 KB
testcase_07 AC 57 ms
10,988 KB
testcase_08 AC 62 ms
11,400 KB
testcase_09 AC 60 ms
11,164 KB
testcase_10 AC 62 ms
11,108 KB
testcase_11 AC 68 ms
11,540 KB
testcase_12 AC 56 ms
10,996 KB
testcase_13 AC 88 ms
12,464 KB
testcase_14 AC 81 ms
12,152 KB
testcase_15 AC 122 ms
14,192 KB
testcase_16 AC 133 ms
12,724 KB
testcase_17 AC 135 ms
12,864 KB
testcase_18 AC 135 ms
12,856 KB
testcase_19 AC 30 ms
9,724 KB
testcase_20 AC 30 ms
9,728 KB
testcase_21 AC 30 ms
9,872 KB
testcase_22 AC 132 ms
12,780 KB
testcase_23 AC 130 ms
12,700 KB
testcase_24 AC 127 ms
14,240 KB
testcase_25 AC 123 ms
13,920 KB
testcase_26 AC 129 ms
14,344 KB
testcase_27 AC 125 ms
13,884 KB
testcase_28 AC 128 ms
14,352 KB
testcase_29 AC 130 ms
12,732 KB
testcase_30 AC 133 ms
12,768 KB
testcase_31 AC 129 ms
14,180 KB
testcase_32 AC 84 ms
12,148 KB
testcase_33 AC 79 ms
11,804 KB
testcase_34 AC 86 ms
11,552 KB
testcase_35 AC 73 ms
11,444 KB
testcase_36 AC 75 ms
11,848 KB
testcase_37 AC 82 ms
11,368 KB
testcase_38 AC 79 ms
11,920 KB
testcase_39 AC 80 ms
11,804 KB
testcase_40 AC 81 ms
11,348 KB
testcase_41 AC 89 ms
12,348 KB
testcase_42 AC 36 ms
10,104 KB
testcase_43 AC 39 ms
10,216 KB
testcase_44 AC 38 ms
10,060 KB
testcase_45 AC 39 ms
10,196 KB
testcase_46 AC 36 ms
10,012 KB
testcase_47 AC 41 ms
10,124 KB
testcase_48 AC 36 ms
10,140 KB
testcase_49 AC 33 ms
10,032 KB
testcase_50 AC 37 ms
9,980 KB
testcase_51 AC 38 ms
10,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from typing import Iterator, Deque, Callable, Tuple
from sys import stdin

import itertools


class Scanner:
    _tokens: Deque[str]

    def __init__(self):
        self._tokens = deque()

    def read(self) -> str:
        if len(self._tokens) == 0:
            self._tokens.extend(stdin.readline().split())
        return self._tokens.popleft()

    def read_int(self) -> int:
        return int(self.read())

    def read_ints(self, n: int) -> Iterator[int]:
        return [self.read_int() for _ in range(n)]

    @staticmethod
    def readline(func: Callable = str):
        return map(func, stdin.readline().split())


cin = Scanner()


def main():
    n = cin.read_int()
    a = [*map(lambda x: bool(x), cin.read_ints(n))]
    ans_all = n * (n + 1) // 2

    a_start = -1
    for i in range(n):
        if a[i]:
            if a_start == -1:
                a_start = i
        else:
            if a_start != -1:
                tmp = i - a_start
                ans_all -= tmp * (tmp + 1) // 2
                a_start = -1

    if a_start != -1:
        tmp = n - a_start
        ans_all -= tmp * (tmp + 1) // 2

    print(ans_all)

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