結果
問題 | No.1095 Smallest Kadomatsu Subsequence |
ユーザー | mkawa2 |
提出日時 | 2021-06-11 10:38:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 872 ms / 2,000 ms |
コード長 | 1,801 bytes |
コンパイル時間 | 451 ms |
コンパイル使用メモリ | 82,380 KB |
実行使用メモリ | 134,684 KB |
最終ジャッジ日時 | 2024-12-14 04:24:33 |
合計ジャッジ時間 | 9,407 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
53,004 KB |
testcase_01 | AC | 39 ms
53,416 KB |
testcase_02 | AC | 38 ms
54,156 KB |
testcase_03 | AC | 40 ms
54,440 KB |
testcase_04 | AC | 40 ms
53,704 KB |
testcase_05 | AC | 39 ms
53,276 KB |
testcase_06 | AC | 39 ms
53,856 KB |
testcase_07 | AC | 40 ms
52,952 KB |
testcase_08 | AC | 40 ms
54,324 KB |
testcase_09 | AC | 41 ms
53,812 KB |
testcase_10 | AC | 40 ms
53,964 KB |
testcase_11 | AC | 41 ms
53,136 KB |
testcase_12 | AC | 40 ms
53,620 KB |
testcase_13 | AC | 93 ms
77,712 KB |
testcase_14 | AC | 90 ms
77,500 KB |
testcase_15 | AC | 93 ms
77,680 KB |
testcase_16 | AC | 95 ms
77,880 KB |
testcase_17 | AC | 94 ms
77,760 KB |
testcase_18 | AC | 92 ms
77,248 KB |
testcase_19 | AC | 93 ms
77,476 KB |
testcase_20 | AC | 91 ms
77,340 KB |
testcase_21 | AC | 92 ms
77,576 KB |
testcase_22 | AC | 90 ms
77,276 KB |
testcase_23 | AC | 833 ms
134,548 KB |
testcase_24 | AC | 844 ms
134,548 KB |
testcase_25 | AC | 842 ms
134,680 KB |
testcase_26 | AC | 834 ms
134,684 KB |
testcase_27 | AC | 872 ms
134,480 KB |
testcase_28 | AC | 284 ms
134,616 KB |
testcase_29 | AC | 281 ms
134,480 KB |
testcase_30 | AC | 501 ms
128,540 KB |
testcase_31 | AC | 498 ms
128,396 KB |
testcase_32 | AC | 500 ms
128,520 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 # md = 10**9+7 class BIT: def __init__(self, n): self.inf = 10**16 self.n = n+3 self.table = [self.inf]*(self.n+1) def update(self, i, x): i += 1 while i <= self.n: if x < self.table[i]: self.table[i] = x i += i & -i def min(self, i): i += 1 res = self.inf while i > 0: if self.table[i] < res: res = self.table[i] i -= i & -i return res n = II() aa = LI() def make_mn(aa): res = [] mn = inf for a in aa: if mn < a: res.append(mn) else: res.append(inf) mn = min(mn, a) return res ll = make_mn(aa) rr = make_mn(aa[::-1])[::-1] ans = inf for a, l, r in zip(aa, ll, rr): ans = min(ans, a+l+r) def make_mx(aa): bit = BIT(n) res = [inf]*n for i, a in sorted(enumerate(aa), key=lambda x: -x[1]): mn = bit.min(i-1) res[i] = mn bit.update(i, a) return res ll = make_mx(aa) rr = make_mx(aa[::-1])[::-1] for a, l, r in zip(aa, ll, rr): ans = min(ans, a+l+r) if ans == inf: ans = -1 print(ans)