結果
| 問題 |
No.2673 A present from B
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-19 00:20:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,338 bytes |
| コンパイル時間 | 1,921 ms |
| コンパイル使用メモリ | 196,952 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-19 00:20:17 |
| 合計ジャッジ時間 | 3,295 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(Ostream& os, const Cont& v){
os << "[ ";
for(auto &x : v)
os << x << ' ';
return os << "]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator << (Ostream &os, const pair<Ts...> &p){
return os << "{" << p.first << ", " << p.second << "}";
}
void dbg_cerr() { cerr << "\e[0m\n"; }
template<typename Head, typename... Tail> void dbg_cerr(Head H, Tail... T) { cerr << ' ' << H; dbg_cerr(T...); }
#ifdef LTF
#define DEBUG(...) cerr << "\e[1;31m[" #__VA_ARGS__ "]:", dbg_cerr(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
void Solve() {
int N, M; cin >> N >> M;
vector<int> a(M);
for (auto &x : a) cin >> x;
vector<int> dp(N + 1);
for (int i = 2; i <= N; i++) dp[i] = i - 1;
reverse(a.begin(), a.end());
for (auto &idx : a) {
// swap idx and idx + 1
swap(dp[idx], dp[idx + 1]);
for (int i = 2; i <= N; i++) dp[i] = min(dp[i], dp[i - 1] + 1);
for (int i = N - 1; i >= 2; i--) dp[i] = min(dp[i], dp[i + 1] + 1);
}
for (int i = 2; i <= N; i++) cout << dp[i] << " \n"[i == N];
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
Solve();
}
return 0;
}