結果
| 問題 |
No.2673 A present from B
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2024-03-15 22:58:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 181 ms / 2,000 ms |
| コード長 | 1,363 bytes |
| コンパイル時間 | 2,250 ms |
| コンパイル使用メモリ | 197,008 KB |
| 最終ジャッジ日時 | 2025-02-20 05:51:34 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=505,INF=1<<30;
int dp[MAX][MAX];
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N,M;cin>>N>>M;
vector<int> A(M);
for(int i=0;i<M;i++){
int x;cin>>x;x--;
A[i]=x;
}
reverse(all(A));
for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) dp[i][j]=INF;
dp[0][0]=0;
for(int i=0;i<=M;i++){
for(int a=0;a<N;a++){
for(int b=0;b<N;b++){
chmin(dp[i][a],dp[i][b]+abs(a-b));
}
}
if(i==M) break;
for(int a=0;a<N;a++){
if(a==A[i]){
dp[i+1][a]=dp[i][a+1];
}else if(a==A[i]+1){
dp[i+1][a]=dp[i][a-1];
}else{
dp[i+1][a]=dp[i][a];
}
}
}
for(int i=1;i<N;i++){
if(i>1) cout<<" ";
cout<<dp[M][i];
}
cout<<endl;
}
Rubikun