結果

問題 No.2673 A present from B
ユーザー rlangevinrlangevin
提出日時 2024-03-15 22:42:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 728 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 105,804 KB
最終ジャッジ日時 2024-03-15 22:42:38
合計ジャッジ時間 5,969 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 58 ms
67,920 KB
testcase_05 AC 40 ms
53,460 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 740 ms
105,804 KB
testcase_09 AC 40 ms
53,460 KB
testcase_10 AC 40 ms
53,460 KB
testcase_11 AC 39 ms
53,460 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 63 ms
70,484 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 39 ms
53,460 KB
testcase_23 AC 38 ms
53,460 KB
testcase_24 AC 38 ms
53,460 KB
testcase_25 AC 38 ms
53,460 KB
testcase_26 AC 39 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(X, Y):
    N = len(X)
    M = len(Y)
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    for i in range(1, N + 1):
        for j in range(1, M + 1):
            if X[i - 1] == Y[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    return M - dp[-1][-1]
    

N, M = map(int, input().split())
A = list(map(int, input().split()))
ans = [0] * N
for i in range(N):
    L = list(range(1, i + 1))
    L.reverse()
    ans[i] = solve(A, L)
    
B = list(range(N))
for a in A[::-1]:
    B[a-1], B[a] = B[a], B[a-1]
    
ind = B.index(0)
for i in range(N):
    if ans[i] == 0:
        if i != ind:
            ans[i] = 1
            
print(*ans[1:])
0