結果
| 問題 |
No.2673 A present from B
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-13 21:07:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,892 bytes |
| コンパイル時間 | 1,991 ms |
| コンパイル使用メモリ | 199,892 KB |
| 最終ジャッジ日時 | 2025-02-20 04:15:55 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 7 WA * 17 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = (ll)1e18 + 7;
template <class T>
bool chmin(T& a, const T& b) {
if (b < a) {
a = b;
return true;
}
return false;
}
int main() {
ll n, m;
cin >> n >> m;
vector<ll> a(m);
for (ll i = 0; i < m; i++) {
cin >> a[i];
a[i]--;
}
// present[i][j] := i回目のプレゼントのswapの後で椅子jにあるプレゼントの番号、0-indexed
vector present(m + 1, vector<ll>(n));
// 初期状態
for (ll i = 0; i < n; i++) {
present[0][i] = i;
}
// プレイリストのswap
for (ll i = 0; i < m; i++) {
present[i + 1] = present[i];
swap(present[i + 1][a[i]], present[i + 1][a[i] + 1]);
}
// s[i] := 初期状態のあみだくじで、最終的に椅子iに渡るプレゼントの番号、0-indexed
vector<ll> s = present[m];
// min_swap_to_s0[i] := s[0]とs[i]とを一気にスワップする最短回数
vector<ll> min_swap_to_s0(n, LINF);
min_swap_to_s0[s[0]] = 0;
// i回目のswap後に、各 0 < j < n に対して、s[0]とs[j]とを一気にスワップする最短回数を求める
for (ll i = 0; i <= m; i++) {
ll present_s0 = 0;
// s[0]の位置を探す
for (ll j = 0; j < n; j++) {
if (present[i][j] == s[0]) {
present_s0 = j;
}
}
// s[0]とs[j]の最短swap回数を求める
for (ll j = 0; j < n; j++) {
ll present_num = present[i][j];
if (present_s0 == present_num) continue;
chmin(min_swap_to_s0[present_num], abs(present_s0 - present_num));
}
}
for (ll i = 1; i < (ll)min_swap_to_s0.size(); i++) {
cout << min_swap_to_s0[i] << (i == (ll)min_swap_to_s0.size() - 1 ? "\n" : " ");
}
}