結果

問題 No.2673 A present from B
ユーザー tour2sttour2st
提出日時 2024-03-16 00:18:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 96,112 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-16 00:18:14
合計ジャッジ時間 3,376 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 3 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 289 ms
6,548 KB
testcase_07 AC 287 ms
6,548 KB
testcase_08 AC 289 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 57 ms
6,548 KB
testcase_13 AC 29 ms
6,548 KB
testcase_14 AC 106 ms
6,548 KB
testcase_15 AC 23 ms
6,548 KB
testcase_16 AC 21 ms
6,548 KB
testcase_17 AC 6 ms
6,548 KB
testcase_18 AC 25 ms
6,548 KB
testcase_19 AC 5 ms
6,548 KB
testcase_20 AC 89 ms
6,548 KB
testcase_21 AC 184 ms
6,548 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <map>
using namespace std;

int n,m,a[500];
//i番目の荷物をj番目に送る際の最小コスト
int dp[500][500];

int main()
{
    //入力
    cin >> n >> m;
    for(int i = 0; i < m; i++){cin >> a[i];a[i]--;}
    
    //初期条件
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            dp[i][j] = abs(i-j);
        }
    }
    for(int i = 0; i < m; i++)
    {
        for(int j=0; j<n; j++)
        {
            //i個目のswapによって
            //荷物jをa[i]に送るコストとa[i]+1に送るコストが逆転
            swap(dp[j][a[i]],dp[j][a[i]+1]);
        }
        //swapで得られた新しいコスト表から
        //隣接する状態へへ配る
        for(int j = 0; j < n; j++)
        {
            int mcost = dp[j][0] - 1;
            for(int k = 0; k < n; k++)
            {
                mcost++;
                mcost = min(mcost, dp[j][k]);
                dp[j][k] = mcost;
            }
            mcost = dp[j][n-1] - 1;
            for(int k = n-1; k >= 0; k--)
            {
                mcost++;
                mcost = min(mcost, dp[j][k]);
                dp[j][k] = mcost;
            }
        }
    }

    for(int j = 1; j < n; j++) cout << dp[j][0] << " ";
    cout << endl;
}
0