結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
iqueue02
|
| 提出日時 | 2019-11-04 17:43:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,130 bytes |
| コンパイル時間 | 1,786 ms |
| コンパイル使用メモリ | 179,548 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 23:45:50 |
| 合計ジャッジ時間 | 2,703 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:26:14: warning: 'sx' may be used uninitialized [-Wmaybe-uninitialized]
26 | dist[sy][sx] = 0;
| ^
main.cpp:17:11: note: 'sx' was declared here
17 | int sy, sx;
| ^~
main.cpp:26:10: warning: 'sy' may be used uninitialized [-Wmaybe-uninitialized]
26 | dist[sy][sx] = 0;
| ^
main.cpp:17:7: note: 'sy' was declared here
17 | int sy, sx;
| ^~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
int dy[] = {1,0,-1,0};
int dx[] = {0,1,0,-1};
int main(){
int h, w;
cin >> w >> h;
vector<vector<char>> g(h,vector<char>(w));
int sy, sx;
rep(i,h) rep(j,w) {
cin >> g[i][j];
if (g[i][j] == '.') sy = i, sx = j;
}
vector<vector<int>> dist(h,vector<int>(w,INF));
int res = INF;
deque<P> deq;
deq.push_front({sy,sx});
dist[sy][sx] = 0;
while (!deq.empty()) {
P p = deq.front(); deq.pop_front();
rep(i,4) {
int ny = p.first + dy[i];
int nx = p.second + dx[i];
if (ny < 0 || nx < 0 || nx >= w-1 || ny >= h-1) continue;
if (dist[ny][nx] != INF) continue;
if (g[ny][nx] == '.') {
if (g[p.first][p.second] == '#') res = min(res,dist[p.first][p.second]);
dist[ny][nx] = 0;
deq.push_front({ny,nx});
} else {
dist[ny][nx] = dist[p.first][p.second] + 1;
deq.push_back({ny,nx});
}
}
}
cout << res << endl;
return 0;
}
iqueue02