結果
問題 | No.2673 A present from B |
ユーザー |
|
提出日時 | 2024-03-15 23:49:25 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,712 bytes |
コンパイル時間 | 2,928 ms |
コンパイル使用メモリ | 266,600 KB |
実行使用メモリ | 32,664 KB |
最終ジャッジ日時 | 2024-09-30 03:22:03 |
合計ジャッジ時間 | 6,530 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 TLE * 1 -- * 20 |
ソースコード
#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][j].push_back({i+1,j+1,0}); e[i][j+1].push_back({i+1,j,0}); } else{ e[i][j].push_back({i+1,j,0}); } } if (j < n-1){ e[i][j].push_back({i,j+1,1}); e[i][j+1].push_back({i,j,1}); } } } for (int i = 1; i < n; i++){ vector<vector<int>> dist(m+1,vector<int>(n,INF)); dist[0][i] = 0; using pos = pair<int,pair<int,int>>; priority_queue<pos,vector<pos>,greater<pos>> h; h.push({0,{0,i}}); 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}}); } } } cout << dist[m][0] << " "; } cout << endl; return 0; }