結果

問題 No.2673 A present from B
ユーザー tour2sttour2st
提出日時 2024-03-15 23:49:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,461 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 97,264 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 23:51:25
合計ジャッジ時間 3,345 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_07 WA -
testcase_08 WA -
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 59 ms
6,548 KB
testcase_13 WA -
testcase_14 AC 106 ms
6,548 KB
testcase_15 AC 24 ms
6,548 KB
testcase_16 AC 22 ms
6,548 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 4 ms
6,548 KB
testcase_20 AC 90 ms
6,548 KB
testcase_21 WA -
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 WA -
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 < n; 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]);
            dp[j][a[i]] = min({dp[j][a[i]],dp[j][a[i]+1]+1});
            dp[j][a[i]+1] = min({dp[j][a[i]]+1,dp[j][a[i]+1]});
            dp[j][a[i]] = min({dp[j][a[i]],dp[j][a[i]+1]+1});
            dp[j][a[i]+1] = min({dp[j][a[i]]+1,dp[j][a[i]+1]});
        }
        
        //swapで得られた新しいコスト表から
        //隣接する状態へへ配る
        for(int j = 0; j < n; j++)
        {
            for(int k = 0; k < n; k++)
            {
                dp[j][k] = min({dp[j][k],dp[j][a[i]]+abs(k-a[i]),dp[j][a[i]+1]+abs(k-(a[i]+1))});
            }
        }
    }

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