結果
問題 | No.2673 A present from B |
ユーザー |
![]() |
提出日時 | 2024-03-20 01:58:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 779 bytes |
コンパイル時間 | 1,922 ms |
コンパイル使用メモリ | 195,568 KB |
最終ジャッジ日時 | 2025-02-20 07:58:15 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);int N, M;cin >> N >> M;vector<int> A(M+2);for (int i=1; i<=M; i++) cin >> A[i];reverse(A.begin(), A.end());// dp(i) : 人iのプレゼントを得るために必要な操作回数(後ろから見ていく)vector<int> dp(N+1, 1e9);for (int i=1; i<=N; i++) dp[i] = i-1;for (int i=1; i<=M; i++){swap(dp[A[i]], dp[A[i]+1]); //人A[i]とA[i]+1が入れ替わるfor (int j=2; j<=N; j++) dp[j] = min(dp[j], dp[j-1]+1);for (int j=N-1; j>=1; j--) dp[j] = min(dp[j], dp[j+1]+1);}for (int i=2; i<=N; i++) cout << dp[i] << " ";cout << endl;return 0;}