結果

問題 No.2673 A present from B
ユーザー SoniSoni
提出日時 2024-03-17 14:38:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,842 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 72,516 KB
最終ジャッジ日時 2024-03-17 14:38:18
合計ジャッジ時間 3,009 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
57,660 KB
testcase_01 AC 42 ms
57,660 KB
testcase_02 AC 42 ms
57,660 KB
testcase_03 AC 42 ms
57,660 KB
testcase_04 AC 50 ms
57,660 KB
testcase_05 AC 42 ms
57,660 KB
testcase_06 AC 72 ms
72,516 KB
testcase_07 AC 70 ms
70,404 KB
testcase_08 AC 71 ms
72,516 KB
testcase_09 AC 54 ms
57,660 KB
testcase_10 AC 45 ms
57,660 KB
testcase_11 AC 44 ms
57,660 KB
testcase_12 AC 60 ms
68,312 KB
testcase_13 AC 72 ms
70,416 KB
testcase_14 AC 63 ms
70,404 KB
testcase_15 AC 55 ms
65,972 KB
testcase_16 AC 55 ms
65,972 KB
testcase_17 AC 59 ms
68,308 KB
testcase_18 AC 56 ms
65,972 KB
testcase_19 AC 51 ms
65,972 KB
testcase_20 AC 62 ms
68,312 KB
testcase_21 AC 69 ms
70,404 KB
testcase_22 AC 42 ms
57,660 KB
testcase_23 AC 42 ms
57,660 KB
testcase_24 AC 42 ms
57,660 KB
testcase_25 AC 42 ms
57,660 KB
testcase_26 AC 44 ms
57,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# import bisect #二分探索
# import math

from collections import deque
from collections import defaultdict


def I():
    return int(sys.stdin.readline().rstrip())


def MI():
    return map(int, sys.stdin.readline().rstrip().split())


def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))


def LI2():
    return list(map(int, sys.stdin.readline().rstrip()))


def S():
    return sys.stdin.readline().rstrip()


def LS():
    return list(sys.stdin.readline().rstrip().split())


def LS2():
    return list(sys.stdin.readline().rstrip())

# 1次元の配列
# list(map(int, input().split()))
# 2次元の配列
# [list(map(int, input().split())) for i in range()]
# wsl pypy3 ファイル名

input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [a-1 for a in A]
# プレゼントではなく当人が動くと考えてもよい
# dp[i][j]は、i番目までのプレゼント交換を行った後、Bobが座る椅子の番号がjであるときの最小操作回数
dp = [[10**9]*(505) for _ in range(505)]
for j in range(N):
    dp[M][j] = j

for i in range(M-1, -1, -1): # BobのプレゼントがAliceに向かうことを考える
    for j in range(0, N):
        # ボブの座る椅子が変わる場合
        if A[i] == j:
            # ボブが右に移る場合
            dp[i][j+1] = min(dp[i][j+1], dp[i+1][j])
        elif A[i] == j-1:
            # ボブが左に移る場合
            dp[i][j-1] = min(dp[i][j-1], dp[i+1][j])
        else:
            # プレゼント交換が行われてもボブの位置は変わらない
            dp[i][j] = min(dp[i][j], dp[i+1][j])

        dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
        dp[i][j-1] = min(dp[i][j-1], dp[i][j] + 1)

for j in range(1, N):
    print(dp[0][j], end=" ")
0