結果

問題 No.1188 レベルX門松列
ユーザー marroncastlemarroncastle
提出日時 2020-08-22 15:52:09
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 387 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 120,652 KB
最終ジャッジ日時 2023-08-05 12:55:01
合計ジャッジ時間 6,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
93,652 KB
testcase_01 AC 361 ms
110,128 KB
testcase_02 AC 316 ms
106,472 KB
testcase_03 AC 367 ms
111,980 KB
testcase_04 AC 288 ms
120,652 KB
testcase_05 AC 73 ms
71,264 KB
testcase_06 AC 196 ms
92,508 KB
testcase_07 AC 282 ms
110,320 KB
testcase_08 AC 278 ms
110,228 KB
testcase_09 AC 71 ms
71,172 KB
testcase_10 AC 73 ms
71,380 KB
testcase_11 AC 149 ms
78,800 KB
testcase_12 AC 157 ms
79,060 KB
testcase_13 AC 153 ms
79,012 KB
testcase_14 AC 279 ms
107,916 KB
testcase_15 AC 387 ms
109,556 KB
testcase_16 AC 120 ms
77,656 KB
testcase_17 AC 325 ms
114,980 KB
testcase_18 AC 71 ms
71,132 KB
testcase_19 AC 328 ms
116,544 KB
testcase_20 AC 74 ms
71,244 KB
testcase_21 AC 69 ms
71,256 KB
testcase_22 AC 71 ms
71,208 KB
testcase_23 AC 71 ms
71,196 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