結果
| 問題 |
No.2673 A present from B
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-16 00:06:43 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 2,000 ms |
| コード長 | 1,702 bytes |
| コンパイル時間 | 3,119 ms |
| コンパイル使用メモリ | 265,516 KB |
| 実行使用メモリ | 25,856 KB |
| 最終ジャッジ日時 | 2024-09-30 03:33:44 |
| 合計ジャッジ時間 | 4,532 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct Edge{
int ton,tom,cost;
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin >> n >> m;
vector<int> A(m);
for (auto &a: A) cin >> a;
const int INF = 1e9;
vector<vector<vector<Edge>>> e(m+1,vector<vector<Edge>>(n));
for (int i = 0; i < m+1; i++){
int a = A[i];
a--;
for (int j = 0; j < n; j++){
if (i < m){
if (j == a ){
e[i+1][j].push_back({i,j+1,0});
} else if (j == a+1){
e[i+1][j].push_back({i,j-1,0});
}
else{
e[i+1][j].push_back({i,j,0});
}
}
if (j < n-1){
e[i][j].push_back({i,j+1,1});
e[i][j+1].push_back({i,j,1});
}
}
}
vector<vector<int>> dist(m+1,vector<int>(n,INF));
dist[m][0] = 0;
using pos = pair<int,pair<int,int>>;
priority_queue<pos,vector<pos>,greater<pos>> h;
h.push({0,{m,0}});
while (!h.empty()){
pos now = h.top(); h.pop();
int x = now.second.first;
int y = now.second.second;
int d = now.first;
if (dist[x][y] != d) continue;
for (auto& nex: e[x][y]){
int nx = nex.ton;
int ny = nex.tom;
int nd = d + nex.cost;
if (dist[nx][ny] > nd){
dist[nx][ny] = nd;
h.push({nd,{nx,ny}});
}
}
}
for (int i = 1; i < n; i++){
cout << dist[0][i] << " ";
}
cout << endl;
return 0;
}