結果

問題 No.2673 A present from B
ユーザー AerenAeren
提出日時 2024-03-15 21:51:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 734 ms / 2,000 ms
コード長 1,671 bytes
コンパイル時間 3,284 ms
コンパイル使用メモリ 253,156 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-15 21:51:56
合計ジャッジ時間 7,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 710 ms
6,676 KB
testcase_07 AC 734 ms
6,676 KB
testcase_08 AC 711 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 136 ms
6,676 KB
testcase_13 AC 66 ms
6,676 KB
testcase_14 AC 251 ms
6,676 KB
testcase_15 AC 52 ms
6,676 KB
testcase_16 AC 48 ms
6,676 KB
testcase_17 AC 10 ms
6,676 KB
testcase_18 AC 59 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 212 ms
6,676 KB
testcase_21 AC 474 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
template<class T> T &ctmin(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmin(T &x, const Head &h, const Tail &... t){ return ctmin(x = min<T>(x, h), t...); }
template<class T> T &ctmax(T &x){ return x; }
template<class T, class Head, class ...Tail> T &ctmax(T &x, const Head &h, const Tail &... t){ return ctmax(x = max<T>(x, h), t...); }



int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> gift(m + 1, vector<int>(n));
	vector<vector<int>> pos(m + 1, vector<int>(n));
	iota(gift[0].begin(), gift[0].end(), 0);
	iota(pos[0].begin(), pos[0].end(), 0);
	for(auto i = 0; i < m; ++ i){
		gift[i + 1] = gift[i];
		int x;
		cin >> x, -- x;
		swap(gift[i + 1][x], gift[i + 1][x + 1]);
		for(auto j = 0; j < n; ++ j){
			pos[i + 1][gift[i + 1][j]] = j;
		}
	}
	int obj = gift[m][0];
	for(auto x = 1; x < n; ++ x){
		int res = numeric_limits<int>::max();
		vector<int> dp(n);
		for(auto c = 0; c < n; ++ c){
			dp[c] = abs(pos[0][x] - pos[0][c]);
		}
		for(auto step = 1; step <= m; ++ step){
			static vector<int> dp_next(n);
			for(auto c = 0; c < n; ++ c){
				dp_next[c] = dp[c];
			}
			for(auto i = 1; i < n; ++ i){
				ctmin(dp_next[gift[step][i]], dp_next[gift[step][i - 1]] + 1);
			}
			for(auto i = n - 2; i >= 0; -- i){
				ctmin(dp_next[gift[step][i]], dp_next[gift[step][i + 1]] + 1);
			}
			swap(dp, dp_next);
		}
		cout << dp[obj] << " ";
	}
	cout << "\n";
	return 0;
}

/*

*/
0