結果

問題 No.1188 レベルX門松列
ユーザー marroncastlemarroncastle
提出日時 2020-08-22 15:52:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 126,596 KB
最終ジャッジ日時 2024-04-23 10:07:56
合計ジャッジ時間 5,255 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
92,952 KB
testcase_01 AC 273 ms
109,184 KB
testcase_02 AC 256 ms
105,344 KB
testcase_03 AC 304 ms
114,048 KB
testcase_04 AC 226 ms
126,596 KB
testcase_05 AC 34 ms
52,352 KB
testcase_06 AC 147 ms
91,188 KB
testcase_07 AC 217 ms
109,312 KB
testcase_08 AC 217 ms
108,928 KB
testcase_09 AC 37 ms
51,968 KB
testcase_10 AC 36 ms
52,608 KB
testcase_11 AC 106 ms
78,324 KB
testcase_12 AC 113 ms
77,696 KB
testcase_13 AC 112 ms
78,208 KB
testcase_14 AC 233 ms
106,704 KB
testcase_15 AC 333 ms
122,624 KB
testcase_16 AC 83 ms
76,836 KB
testcase_17 AC 281 ms
116,480 KB
testcase_18 AC 37 ms
52,096 KB
testcase_19 AC 263 ms
115,584 KB
testcase_20 AC 33 ms
51,840 KB
testcase_21 AC 36 ms
52,352 KB
testcase_22 AC 37 ms
52,096 KB
testcase_23 AC 34 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Binary Indexed Tree (Fenwick Tree)
# Binary Indexed Tree (Fenwick Tree)
class BIT_max:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
        self.el = [0]*(n+1)
    def query(self, i):
        s = 0
        while i > 0:
            s = max(s,self.bit[i])
            i -= i & -i
        return s
    def update(self, i, x):
        # assert i > 0
        self.el[i] = max(self.el[i],x)
        while i <= self.n:
            self.bit[i] = max(self.bit[i],x)
            i += i & -i
N = int(input())
A = list(map(int, input().split()))
def compress(arr):
    *XS, = set(arr)
    XS.sort()
    return {e: i+1 for i, e in enumerate(XS)}
tra = compress(A)
for i in range(N):
    A[i] = tra[A[i]]
def calc(A,N):
    bit = BIT_max(N)
    lis1,lis2 = [0]*N,[0]*N
    for i in range(N):
        lis1[i] = bit.query(A[i]-1)
        bit.update(A[i],lis1[i]+1)
    bit = BIT_max(N)
    for i in range(N-1,-1,-1):
        lis2[i] = bit.query(A[i]-1)
        bit.update(A[i],lis2[i]+1)
    ans = 0
    for i in range(N):
        ans = max(ans, min(lis1[i],lis2[i]))
    return ans
a = calc(A,N)
b = calc(list(map(lambda x:-x+N+1,A)),N)
print(max(a,b))
0