結果

問題 No.127 門松もどき
ユーザー cologne
提出日時 2022-03-02 16:45:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 578 ms / 5,000 ms
コード長 582 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 81,908 KB
実行使用メモリ 146,940 KB
最終ジャッジ日時 2024-07-16 08:55:31
合計ジャッジ時間 7,934 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())
    *A, = map(int, input().split())
    DP = [[0]*N for i in range(N)]
    order = sorted(range(N), key=lambda x: A[x], reverse=True)

    for i in order:
        DP[i][i] = 1
        for j in range(i-1, -1, -1):
            DP[i][j] = DP[i][j+1]
            if A[i] < A[j]:
                DP[i][j] = max(DP[i][j], DP[j][i-1]+1)
        for j in range(i+1, N):
            DP[i][j] = DP[i][j-1]
            if A[i] < A[j]:
                DP[i][j] = max(DP[i][j], DP[j][i+1]+1)

    print(max(map(max, DP)))


if __name__ == '__main__':
    main()
0