結果

問題 No.1188 レベルX門松列
ユーザー marroncastle
提出日時 2020-08-22 15:42:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,185 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 81,896 KB
実行使用メモリ 101,752 KB
最終ジャッジ日時 2024-10-15 09:54:06
合計ジャッジ時間 7,023 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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