結果
| 問題 | No.2913 二次元距離空間 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-10-04 22:14:25 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,261 bytes |
| 記録 | |
| コンパイル時間 | 1,255 ms |
| コンパイル使用メモリ | 228,152 KB |
| 実行使用メモリ | 16,768 KB |
| 最終ジャッジ日時 | 2026-07-05 21:04:21 |
| 合計ジャッジ時間 | 2,963 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int H,W; cin >> H >> W;
vector<string> S(H);
for(auto &s : S) cin >> s;
vector<vector<pair<int,int>>> dist(H,vector<pair<int,int>>(W,{1001001001,-1}));
dist.at(0).at(0) = {0,0};
deque<pair<int,int>> Q; Q.push_back({0,0});
vector<pair<int,int>> dxy = {{-1,0},{0,1},{1,0},{0,-1}};
while(Q.size()){
auto [x,y] = Q.front(); Q.pop_front();
auto [cx,cy] = dist.at(x).at(y);
for(auto [dx,dy] : dxy){
if(dy != 0) cx++;
else cy++;
int nx = x+dx,ny = y+dy;
if(nx < 0 || ny < 0 || nx >= H || ny >= W){}
else if(S.at(nx).at(ny) != '#'){
if(dist.at(nx).at(ny) > make_pair(cx,cy)){
dist.at(nx).at(ny) = {cx,cy};
if(dy) Q.push_back({nx,ny});
else Q.push_front({nx,ny});
}
}
if(dy != 0) cx--;
else cy--;
}
}
if(dist.at(H-1).at(W-1).first != 1001001001){
cout << "Yes\n";
auto [X,Y] = dist.at(H-1).at(W-1);
cout << X << " " << Y << endl;
}
else cout << "No\n";
}