結果

問題 No.127 門松もどき
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-13 10:04:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 588 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 8,660 KB
最終ジャッジ日時 2023-08-25 14:07:36
合計ジャッジ時間 7,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,848 KB
testcase_01 AC 15 ms
7,824 KB
testcase_02 AC 16 ms
7,780 KB
testcase_03 AC 15 ms
7,780 KB
testcase_04 AC 552 ms
8,500 KB
testcase_05 AC 15 ms
7,824 KB
testcase_06 AC 56 ms
8,280 KB
testcase_07 AC 16 ms
7,908 KB
testcase_08 AC 15 ms
7,784 KB
testcase_09 AC 15 ms
7,784 KB
testcase_10 AC 16 ms
7,816 KB
testcase_11 AC 17 ms
7,844 KB
testcase_12 AC 320 ms
8,320 KB
testcase_13 AC 428 ms
8,476 KB
testcase_14 AC 376 ms
8,480 KB
testcase_15 AC 525 ms
8,444 KB
testcase_16 AC 366 ms
8,524 KB
testcase_17 AC 424 ms
8,548 KB
testcase_18 AC 352 ms
8,660 KB
testcase_19 AC 226 ms
8,168 KB
testcase_20 AC 225 ms
8,300 KB
testcase_21 AC 112 ms
8,300 KB
testcase_22 AC 588 ms
8,472 KB
testcase_23 AC 581 ms
8,448 KB
testcase_24 AC 430 ms
8,480 KB
testcase_25 AC 492 ms
8,528 KB
testcase_26 AC 256 ms
8,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N = int(input())
    As = list(map(int, input().split()))
    return N, As


def solve(N, As):
    dpL = [1] * N
    maxR = 1
    for i, ai in enumerate(As[1:], 1):
        maxR = update_dp(dpL, maxR, i, ai, As)
    return max(max(dpL), maxR)


def update_dp(dpL, maxR, i, ai, As):
    dptmp = [1] * i
    maxtmp = 1
    for j in range(i-1, -1, -1):
        aj = As[j]
        if aj > ai and dpL[j] >= maxtmp:
            maxtmp = dpL[j] + 1
        dptmp[j] = maxtmp
    if maxR < maxtmp:
        maxR = maxtmp
    for j, aj in enumerate(As[:i]):
        if aj < ai and dptmp[j] >= dpL[j]:
            dpL[j] = dptmp[j] + 1
    return maxR

N, As = read_data()
print(solve(N, As))
0