結果
問題 | No.1095 Smallest Kadomatsu Subsequence |
ユーザー | mkawa2 |
提出日時 | 2021-06-11 10:38:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 877 ms / 2,000 ms |
コード長 | 1,801 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 134,912 KB |
最終ジャッジ日時 | 2024-05-08 04:06:49 |
合計ジャッジ時間 | 9,668 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,480 KB |
testcase_01 | AC | 39 ms
52,096 KB |
testcase_02 | AC | 39 ms
52,224 KB |
testcase_03 | AC | 40 ms
53,376 KB |
testcase_04 | AC | 41 ms
52,736 KB |
testcase_05 | AC | 41 ms
52,608 KB |
testcase_06 | AC | 41 ms
53,248 KB |
testcase_07 | AC | 41 ms
53,248 KB |
testcase_08 | AC | 42 ms
53,120 KB |
testcase_09 | AC | 39 ms
52,992 KB |
testcase_10 | AC | 40 ms
53,120 KB |
testcase_11 | AC | 40 ms
53,376 KB |
testcase_12 | AC | 40 ms
52,864 KB |
testcase_13 | AC | 96 ms
77,568 KB |
testcase_14 | AC | 93 ms
77,696 KB |
testcase_15 | AC | 94 ms
77,460 KB |
testcase_16 | AC | 95 ms
77,824 KB |
testcase_17 | AC | 94 ms
77,880 KB |
testcase_18 | AC | 94 ms
77,440 KB |
testcase_19 | AC | 94 ms
77,580 KB |
testcase_20 | AC | 94 ms
77,608 KB |
testcase_21 | AC | 95 ms
78,080 KB |
testcase_22 | AC | 95 ms
77,920 KB |
testcase_23 | AC | 869 ms
134,656 KB |
testcase_24 | AC | 868 ms
134,528 KB |
testcase_25 | AC | 857 ms
134,784 KB |
testcase_26 | AC | 877 ms
134,672 KB |
testcase_27 | AC | 857 ms
134,656 KB |
testcase_28 | AC | 283 ms
134,912 KB |
testcase_29 | AC | 284 ms
134,656 KB |
testcase_30 | AC | 522 ms
128,256 KB |
testcase_31 | AC | 532 ms
128,256 KB |
testcase_32 | AC | 525 ms
128,384 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)