結果

問題 No.2673 A present from B
ユーザー hato336hato336
提出日時 2024-03-15 22:04:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,110 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 89,528 KB
最終ジャッジ日時 2024-03-15 22:04:37
合計ジャッジ時間 5,523 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
84,792 KB
testcase_01 AC 132 ms
84,792 KB
testcase_02 AC 165 ms
84,792 KB
testcase_03 AC 137 ms
84,792 KB
testcase_04 AC 144 ms
88,120 KB
testcase_05 AC 130 ms
84,792 KB
testcase_06 AC 179 ms
89,528 KB
testcase_07 AC 201 ms
89,528 KB
testcase_08 AC 180 ms
89,528 KB
testcase_09 AC 140 ms
88,120 KB
testcase_10 AC 146 ms
88,120 KB
testcase_11 AC 141 ms
88,120 KB
testcase_12 AC 161 ms
89,528 KB
testcase_13 AC 171 ms
89,528 KB
testcase_14 AC 194 ms
89,528 KB
testcase_15 AC 155 ms
89,144 KB
testcase_16 AC 157 ms
89,144 KB
testcase_17 AC 165 ms
89,528 KB
testcase_18 AC 154 ms
89,144 KB
testcase_19 AC 147 ms
88,888 KB
testcase_20 AC 162 ms
89,528 KB
testcase_21 AC 189 ms
89,528 KB
testcase_22 AC 129 ms
84,792 KB
testcase_23 AC 131 ms
84,792 KB
testcase_24 AC 126 ms
84,792 KB
testcase_25 AC 129 ms
84,792 KB
testcase_26 AC 130 ms
84,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = [10**18 for i in range(n)]

res = [list(range(n))]
for i in range(m):
    res.append(res[-1][:])
    res[-1][a[i]-1],res[-1][a[i]] = res[-1][a[i]], res[-1][a[i]-1]
#print(res)
dp = [[10**18 for i in range(n)] for j in range(m+1)]
x = res[-1][0]
for i in range(m+1):
    for j in range(n):
        if res[i][j] == x:
            dp[i][j] = 0
for i in reversed(range(m+1)):
    for j in range(n):
        if i != m:
            if j != 0 and res[i+1][j-1] == res[i][j]:
                dp[i][j] = min(dp[i][j],dp[i+1][j-1])
            if res[i+1][j] == res[i][j]:
                dp[i][j] = min(dp[i][j],dp[i+1][j])
            if j != n-1 and res[i+1][j+1] == res[i][j]:
                dp[i][j] = min(dp[i][j],dp[i+1][j+1])
        if j != 0:
            dp[i][j] = min(dp[i][j-1]+1,dp[i][j])
for i in range(1,n):
    print(dp[0][i],end=' ')
#print(dp)
0