結果
| 問題 |
No.2913 二次元距離空間
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-04 23:19:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,284 bytes |
| コンパイル時間 | 2,235 ms |
| コンパイル使用メモリ | 206,616 KB |
| 最終ジャッジ日時 | 2025-02-24 15:38:32 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 -- * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll INF = 1e18, DI[4] = {0, 1, 0, -1}, DJ[4] = {1, 0, -1, 0};
void solve() {
ll h, w;
cin >> h >> w;
vector<string> s(h);
rep(i, h) cin >> s[i];
vector dist(h, vector<pair<ll, ll>>(w, {INF, INF}));
dist[0][0] = {0, 0};
priority_queue<pair<pair<ll, ll>, pair<ll, ll>>> que;
que.push({{0, 0}, {0, 0}});
while (!que.empty()) {
auto dxy = que.top().first;
auto [ci, cj] = que.top().second;
que.pop();
if (dist[ci][cj] < dxy)
continue;
rep(dir, 4) {
ll ni = ci + DI[dir];
ll nj = cj + DJ[dir];
if (ni < 0 || h <= ni || nj < 0 || w <= nj || s[ni][nj] == '#')
continue;
auto nd = dxy;
if (ci == ni) {
nd.first++;
} else {
nd.second++;
}
if (dist[ni][nj] <= nd)
continue;
dist[ni][nj] = nd;
que.push({nd, {ni, nj}});
}
}
auto [x, y] = dist[h - 1][w - 1];
if (x == INF) {
cout << "No\n";
} else {
cout << "Yes\n";
cout << x << ' ' << y << '\n';
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int T = 1;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}