結果
問題 |
No.2913 二次元距離空間
|
ユーザー |
![]() |
提出日時 | 2024-10-04 22:00:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 1,321 bytes |
コンパイル時間 | 2,364 ms |
コンパイル使用メモリ | 206,328 KB |
最終ジャッジ日時 | 2025-02-24 15:16:18 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(v) v.begin(),v.end() #define dbg(x) cerr << #x << ": " << (x) << endl; int h,w; vector<string> s; int main() { cin >> h >> w; s.resize(h); for (int i = 0; i < h; ++i) cin >> s[i]; using pii = pair<int,int>; int inf = 1e9; vector dp(h, vector<pii>(w, pii(inf,inf))); priority_queue<array<int,4>> pq; dp[0][0] = pii(0,0); pq.push({ 0,0,0,0 }); int dx[] = {-1, 0, 1, 0, -1}; while (pq.size()) { auto [cx, cy, x, y] = pq.top(); pq.pop(); cx = -cx; cy = -cy; if (pii(cx,cy) > dp[y][x]) continue; for (int i = 0; i < 4; ++i) { int nx = x + dx[i]; int ny = y + dx[i+1]; if (!(0 <= nx && nx < w && 0 <= ny && ny < h)) continue; if (s[ny][nx]=='#') continue; int a = abs(dx[i]); int b = abs(dx[i+1]); if (pii(cx+a, cy+b) < dp[ny][nx]) { dp[ny][nx] = pii(cx+a,cy+b); pq.push({-dp[ny][nx].first, -dp[ny][nx].second, nx, ny}); } } } if (dp[h-1][w-1] == pii(inf,inf)) { cout << "No\n"; } else { cout << "Yes\n"; cout << dp[h-1][w-1].first << " " << dp[h-1][w-1].second << '\n'; } }