結果
| 問題 |
No.2673 A present from B
|
| コンテスト | |
| ユーザー |
tour2st
|
| 提出日時 | 2024-03-15 23:44:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,245 bytes |
| コンパイル時間 | 963 ms |
| コンパイル使用メモリ | 96,132 KB |
| 実行使用メモリ | 11,168 KB |
| 最終ジャッジ日時 | 2024-09-30 03:14:35 |
| 合計ジャッジ時間 | 4,624 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 TLE * 1 -- * 20 |
ソースコード
#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]);
}
//swapで得られた新しいコスト表から
//隣接する状態へへ配る
for(int j = 0; j < n; j++)
{
for(int k = 0; k < n; k++)
{
for(int l = 0; l < n; l++)
{
dp[j][k] = min(dp[j][k],dp[j][l]+abs(k-l));
}
}
}
}
for(int j = 1; j < n; j++) cout << dp[j][0] << " ";
cout << endl;
}
tour2st