結果

問題 No.1095 Smallest Kadomatsu Subsequence
ユーザー tonnnura172tonnnura172
提出日時 2020-06-27 20:15:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 2,738 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 31,848 KB
最終ジャッジ日時 2023-09-19 09:03:29
合計ジャッジ時間 28,100 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
9,588 KB
testcase_01 AC 32 ms
9,584 KB
testcase_02 AC 31 ms
9,608 KB
testcase_03 AC 32 ms
9,708 KB
testcase_04 WA -
testcase_05 AC 32 ms
9,556 KB
testcase_06 AC 32 ms
9,588 KB
testcase_07 AC 32 ms
9,616 KB
testcase_08 WA -
testcase_09 AC 32 ms
9,612 KB
testcase_10 WA -
testcase_11 AC 33 ms
9,516 KB
testcase_12 WA -
testcase_13 AC 126 ms
10,912 KB
testcase_14 AC 126 ms
10,908 KB
testcase_15 WA -
testcase_16 AC 126 ms
10,948 KB
testcase_17 WA -
testcase_18 AC 127 ms
10,920 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 126 ms
10,980 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul, add
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class SegmentTree:
    """Segment Tree (Point Update & Range Query)
    Query
        1. update(i, val): update i-th value(0-indexed) to val
        2. query(low, high): find f(value) in [low, high)
    Complexity
        time complexity: O(log n)
        space complexity: O(n)
    """
    def __init__(self, N, f, default):
        self.N = 1 << (N-1).bit_length()
        self.default = default
        self.f = f
        self.segtree = [self.default] * ((self.N << 1) - 1)
    @classmethod
    def create_from_array(cls, arr, f, default):
        N = len(arr)
        self = cls(N, f, default)
        for i in range(N):
            self.segtree[self.N - 1 + i] = arr[i]
        for i in reversed(range(self.N - 1)):
            self.segtree[i] = self.f(
                self.segtree[(i << 1) + 1], self.segtree[(i << 1) + 2])
        return self
    def update(self, i, val):  # update
        i += self.N - 1
        self.segtree[i] = val
        while i > 0:
            i = (i - 1) >> 1
            self.segtree[i] = self.f(
                self.segtree[(i << 1)+1], self.segtree[(i << 1)+2])
    def query(self, low, high):  # query
        # query [l, r)
        low, high = low + self.N, high + self.N
        ret = self.default
        while low < high:
            if low & 1:
                ret = self.f(ret, self.segtree[low-1])
                low += 1
            if high & 1:
                high -= 1
                ret = self.f(ret, self.segtree[high-1])
            low, high = low >> 1, high >> 1
        return ret
    def get(self, k):  # get k-th value(0-indexed)
        return self.segtree[k+self.N-1]
    def all(self):  # all range query
        return self.segtree[0]

N = INT()
A = LIST()

segtree = SegmentTree.create_from_array(A, min, 10**9)

ans = 10**10
for i in range(1, N-1):
    l = segtree.query(0, i)
    r = segtree.query(i, N)
    if l < A[i] > r or l > A[i] < r:
        ans = min(ans, A[i]+l+r)
    
print(ans if ans != 10**10 else -1)
0