結果

問題 No.1505 Zero-Product Ranges
ユーザー kichi2004_kichi2004_
提出日時 2021-04-01 23:17:26
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,211 bytes
コンパイル時間 249 ms
使用メモリ 13,676 KB
最終ジャッジ日時 2023-01-10 06:37:35
合計ジャッジ時間 7,804 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 29 ms
8,932 KB
testcase_01 AC 29 ms
8,936 KB
testcase_02 AC 28 ms
8,788 KB
testcase_03 AC 178 ms
13,508 KB
testcase_04 AC 178 ms
13,504 KB
testcase_05 AC 89 ms
10,740 KB
testcase_06 AC 87 ms
10,588 KB
testcase_07 AC 72 ms
10,348 KB
testcase_08 AC 82 ms
10,576 KB
testcase_09 AC 76 ms
10,284 KB
testcase_10 AC 77 ms
10,268 KB
testcase_11 AC 89 ms
10,808 KB
testcase_12 AC 70 ms
10,304 KB
testcase_13 AC 119 ms
11,564 KB
testcase_14 AC 108 ms
11,500 KB
testcase_15 AC 170 ms
13,500 KB
testcase_16 AC 191 ms
13,648 KB
testcase_17 AC 189 ms
13,580 KB
testcase_18 AC 187 ms
13,676 KB
testcase_19 AC 30 ms
8,792 KB
testcase_20 AC 28 ms
8,888 KB
testcase_21 AC 29 ms
9,084 KB
testcase_22 AC 193 ms
12,008 KB
testcase_23 AC 183 ms
11,932 KB
testcase_24 AC 179 ms
13,444 KB
testcase_25 AC 173 ms
13,076 KB
testcase_26 AC 189 ms
13,548 KB
testcase_27 AC 183 ms
13,188 KB
testcase_28 AC 180 ms
13,388 KB
testcase_29 AC 184 ms
13,540 KB
testcase_30 AC 192 ms
13,644 KB
testcase_31 AC 180 ms
13,560 KB
testcase_32 AC 110 ms
11,564 KB
testcase_33 AC 104 ms
11,012 KB
testcase_34 AC 115 ms
10,784 KB
testcase_35 AC 93 ms
10,660 KB
testcase_36 AC 97 ms
11,036 KB
testcase_37 AC 108 ms
10,304 KB
testcase_38 AC 102 ms
11,156 KB
testcase_39 AC 105 ms
11,116 KB
testcase_40 AC 109 ms
10,492 KB
testcase_41 AC 119 ms
11,432 KB
testcase_42 AC 39 ms
9,188 KB
testcase_43 AC 43 ms
9,492 KB
testcase_44 AC 41 ms
9,436 KB
testcase_45 AC 42 ms
9,312 KB
testcase_46 AC 38 ms
9,192 KB
testcase_47 AC 45 ms
9,480 KB
testcase_48 AC 39 ms
9,332 KB
testcase_49 AC 33 ms
9,012 KB
testcase_50 AC 39 ms
9,396 KB
testcase_51 AC 42 ms
9,428 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