提出 #65857943


ソースコード 拡げる

import heapq
import math
import os
import random
import sys
from types import GeneratorType
from typing import *
from collections import defaultdict, Counter, deque
from functools import cache, reduce
from itertools import combinations, permutations, groupby, accumulate
from bisect import bisect_left, bisect_right, insort_left, insort_right

input = sys.stdin.readline

rd = random.getrandbits(32)


def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrappedfunc


class SortedList:
    def __init__(self, iterable=None, _load=200):
        if iterable is None:
            iterable = []
        values = sorted(iterable)
        self._len = _len = len(values)
        self._load = _load
        self._lists = _lists = [values[i:i + _load]
                                for i in range(0, _len, _load)]
        self._list_lens = [len(_list) for _list in _lists]
        self._min_s = [_list[0] for _list in _lists]
        self._fen_tree = []
        self._rebuild = True

    def _fen_build(self):
        self._fen_tree[:] = self._list_lens
        _fen_tree = self._fen_tree
        for i in range(len(_fen_tree)):
            if i | i + 1 < len(_fen_tree):
                _fen_tree[i | i + 1] += _fen_tree[i]
        self._rebuild = False

    def _fen_update(self, index, value):
        if not self._rebuild:
            _fen_tree = self._fen_tree
            while index < len(_fen_tree):
                _fen_tree[index] += value
                index |= index + 1

    def _fen_query(self, end):
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        x = 0
        while end:
            x += _fen_tree[end - 1]
            end &= end - 1
        return x

    def _fen_findkth(self, k):
        _list_lens = self._list_lens
        if k < _list_lens[0]:
            return 0, k
        if k >= self._len - _list_lens[-1]:
            return len(_list_lens) - 1, k + _list_lens[-1] - self._len
        if self._rebuild:
            self._fen_build()

        _fen_tree = self._fen_tree
        idx = -1
        for d in reversed(range(len(_fen_tree).bit_length())):
            right_idx = idx + (1 << d)
            if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
                idx = right_idx
                k -= _fen_tree[idx]
        return idx + 1, k

    def _delete(self, pos, idx):
        _lists = self._lists
        _mins = self._min_s
        _list_lens = self._list_lens

        self._len -= 1
        self._fen_update(pos, -1)
        del _lists[pos][idx]
        _list_lens[pos] -= 1

        if _list_lens[pos]:
            _mins[pos] = _lists[pos][0]
        else:
            del _lists[pos]
            del _list_lens[pos]
            del _mins[pos]
            self._rebuild = True

    def _loc_left(self, value):
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._min_s

        lo, pos = -1, len(_lists) - 1
        while lo + 1 < pos:
            mi = (lo + pos) >> 1
            if value <= _mins[mi]:
                pos = mi
            else:
                lo = mi

        if pos and value <= _lists[pos - 1][-1]:
            pos -= 1

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value <= _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def _loc_right(self, value):
        if not self._len:
            return 0, 0

        _lists = self._lists
        _mins = self._min_s

        pos, hi = 0, len(_lists)
        while pos + 1 < hi:
            mi = (pos + hi) >> 1
            if value < _mins[mi]:
                hi = mi
            else:
                pos = mi

        _list = _lists[pos]
        lo, idx = -1, len(_list)
        while lo + 1 < idx:
            mi = (lo + idx) >> 1
            if value < _list[mi]:
                idx = mi
            else:
                lo = mi

        return pos, idx

    def add(self, value):
        _load = self._load
        _lists = self._lists
        _mins = self._min_s
        _list_lens = self._list_lens

        self._len += 1
        if _lists:
            pos, idx = self._loc_right(value)
            self._fen_update(pos, 1)
            _list = _lists[pos]
            _list.insert(idx, value)
            _list_lens[pos] += 1
            _mins[pos] = _list[0]
            if _load + _load < len(_list):
                _lists.insert(pos + 1, _list[_load:])
                _list_lens.insert(pos + 1, len(_list) - _load)
                _mins.insert(pos + 1, _list[_load])
                _list_lens[pos] = _load
                del _list[_load:]
                self._rebuild = True
        else:
            _lists.append([value])
            _mins.append(value)
            _list_lens.append(1)
            self._rebuild = True

    def discard(self, value):
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_right(value)
            if idx and _lists[pos][idx - 1] == value:
                self._delete(pos, idx - 1)

    def remove(self, value):
        _len = self._len
        self.discard(value)
        if _len == self._len:
            raise ValueError('{0!r} not in list'.format(value))

    def pop(self, index=-1):
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        value = self._lists[pos][idx]
        self._delete(pos, idx)
        return value

    def bisect_left(self, value):
        pos, idx = self._loc_left(value)
        return self._fen_query(pos) + idx

    def bisect_right(self, value):
        pos, idx = self._loc_right(value)
        return self._fen_query(pos) + idx

    def count(self, value):
        return self.bisect_right(value) - self.bisect_left(value)

    def __len__(self):
        return self._len

    def __getitem__(self, index):
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        return self._lists[pos][idx]

    def __delitem__(self, index):
        pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
        self._delete(pos, idx)

    def __contains__(self, value):
        _lists = self._lists
        if _lists:
            pos, idx = self._loc_left(value)
            return idx < len(_lists[pos]) and _lists[pos][idx] == value
        return False

    def __iter__(self):
        return (value for _list in self._lists for value in _list)

    def __reversed__(self):
        return (value for _list in reversed(self._lists)
                for value in reversed(_list))

    def __repr__(self):
        return f'SortedList({list(self)})'


# 不要用Counter, set,!!!!!!!!!!!!!!!!!!!!!!!!!
# 用default-dict(int)时要^rd !!!!!!!!!!!!!!!!!!!
def sol():
    n, k = map(int, input().split())
    arr = list(map(int, input().split()))
    s = 1
    for x in arr:
        s *= x
        if len(str(s)) > k:
            s = 1
    print(s)


T = 1


def main():
    for _ in range(T):
        sol()


main()

提出情報

提出日時
問題 B - Product Calculator
ユーザ wyzl
言語 Python (PyPy 3.10-v7.3.12)
得点 200
コード長 7799 Byte
結果 AC
実行時間 146 ms
メモリ 91344 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 200 / 200
結果
AC × 2
AC × 32
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 139 ms 91104 KiB
example_01.txt AC 140 ms 91144 KiB
hand_00.txt AC 141 ms 90852 KiB
hand_01.txt AC 141 ms 91176 KiB
hand_02.txt AC 140 ms 91176 KiB
hand_03.txt AC 139 ms 91024 KiB
hand_04.txt AC 140 ms 91136 KiB
random_00.txt AC 140 ms 91020 KiB
random_01.txt AC 140 ms 91088 KiB
random_02.txt AC 140 ms 91148 KiB
random_03.txt AC 146 ms 91112 KiB
random_04.txt AC 144 ms 91020 KiB
random_05.txt AC 140 ms 91096 KiB
random_06.txt AC 140 ms 90920 KiB
random_07.txt AC 139 ms 91024 KiB
random_08.txt AC 143 ms 91128 KiB
random_09.txt AC 142 ms 91344 KiB
random_10.txt AC 141 ms 91124 KiB
random_11.txt AC 140 ms 91192 KiB
random_12.txt AC 141 ms 91232 KiB
random_13.txt AC 139 ms 90920 KiB
random_14.txt AC 139 ms 91052 KiB
random_15.txt AC 139 ms 91192 KiB
random_16.txt AC 139 ms 91008 KiB
random_17.txt AC 141 ms 91172 KiB
random_18.txt AC 140 ms 91148 KiB
random_19.txt AC 140 ms 91240 KiB
random_20.txt AC 140 ms 91144 KiB
random_21.txt AC 139 ms 91032 KiB
random_22.txt AC 140 ms 91156 KiB
random_23.txt AC 140 ms 91148 KiB
random_24.txt AC 139 ms 91156 KiB