結果
| 問題 |
No.2913 二次元距離空間
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-04 23:28:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 1,264 bytes |
| コンパイル時間 | 2,431 ms |
| コンパイル使用メモリ | 205,668 KB |
| 最終ジャッジ日時 | 2025-02-24 15:39:59 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#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};
deque<pair<ll, ll>> que;
que.push_back({0, 0});
while (!que.empty()) {
auto [ci, cj] = que.front();
que.pop_front();
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 = dist[ci][cj];
if (ci == ni) {
nd.first++;
} else {
nd.second++;
}
if (dist[ni][nj] <= nd)
continue;
dist[ni][nj] = nd;
if (ci == ni) {
que.push_back({ni, nj});
} else {
que.push_front({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;
}