結果

問題 No.1188 レベルX門松列
ユーザー marroncastlemarroncastle
提出日時 2020-08-22 15:42:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,185 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 102,564 KB
最終ジャッジ日時 2024-04-23 10:00:22
合計ジャッジ時間 7,570 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 310 ms
101,056 KB
testcase_01 AC 507 ms
97,704 KB
testcase_02 AC 453 ms
95,024 KB
testcase_03 WA -
testcase_04 AC 317 ms
101,016 KB
testcase_05 AC 39 ms
52,528 KB
testcase_06 AC 244 ms
101,152 KB
testcase_07 AC 285 ms
101,596 KB
testcase_08 AC 294 ms
101,316 KB
testcase_09 AC 39 ms
52,816 KB
testcase_10 AC 39 ms
53,348 KB
testcase_11 AC 129 ms
77,708 KB
testcase_12 AC 136 ms
77,576 KB
testcase_13 AC 141 ms
77,228 KB
testcase_14 AC 367 ms
91,248 KB
testcase_15 AC 620 ms
102,100 KB
testcase_16 AC 95 ms
76,276 KB
testcase_17 AC 483 ms
95,948 KB
testcase_18 AC 40 ms
54,660 KB
testcase_19 AC 446 ms
95,140 KB
testcase_20 AC 38 ms
53,512 KB
testcase_21 AC 41 ms
52,532 KB
testcase_22 AC 39 ms
54,440 KB
testcase_23 AC 39 ms
53,076 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(H):
    for i in range(N):
        H[i] = [H[i],i]
    H.sort()
    A = [0]*N
    for i,(a,b) in enumerate(H):
        A[b] = i+1
    return A
A = compress(A)
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