結果

問題 No.2673 A present from B
ユーザー じなぺじなぺ
提出日時 2024-03-15 22:34:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,091 bytes
コンパイル時間 2,967 ms
コンパイル使用メモリ 251,860 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 22:34:08
合計ジャッジ時間 4,935 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;

//多倍長整数//
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;

const int INF = 1e9;
const int MOD = 998244353;
const long long LINF = 4e18;

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vvvvi = vector<vector<vector<vector<int>>>>;
using vvl = vector<vector<long long>>;
using vvvl = vector<vector<vector<long long>>>;
using vvvvl = vector<vector<vector<vector<long long>>>>;
using vvc = vector<vector<char>>;
using vvb = vector<vector<bool>>;
using vvvb = vector<vector<vector<bool>>>;
using vvvvb = vector<vector<vector<vector<bool>>>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ALL(obj) (obj).begin(),(obj).end()

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m;
	cin >> n >> m;
	vi a(m);
	rep(i,m) cin >> a[i];
	rep(i,m) a[i]--;
	vvi b(n,vi(m + 1));
	vi cur(n);
	iota(ALL(cur),0);
	rep(i,n) b[i][0] = i;
	rep(i,m){
		swap(cur[a[i]],cur[a[i] + 1]);
		rep(j,n) b[cur[j]][i + 1] = j;
	}
	rep(i,n){
		for(int j = m - 1;j >= 0;j--){
			b[i][j] = min(b[i][j],b[i][j + 1]);
		}
	}
	vi dp(n,INF);
	vi pos(n);
	iota(ALL(pos),0);
	for(int i = 1;i < n;i++){
		rep(j,n){
			dp[i] = min(dp[i],abs(pos[i] - pos[j]) + b[j][0]);
		}
	}
	//rep(i,n) cout << pos[i] + 1 << ' ';
	rep(i,m){
		int pos1 = -1;int pos2 = -1;
		rep(j,n){
			if(pos[j] == a[i]) pos1 = j;
			if(pos[j] == a[i] + 1) pos2 = j;
		}
		swap(pos[pos1],pos[pos2]);
		// rep(i,n) cout << pos[i] + 1 << ' ';
		// cout << endl;
		for(int j = 1;j < n;j++){
			rep(k,n){
				dp[j] = min(dp[j],abs(pos[j] - pos[k]) + b[k][i + 1]);
			}
		}
	}
	for(int i = 1;i < n;i++) cout << dp[i] << ' ';

	return 0;
}
0