結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
Captain
|
| 提出日時 | 2019-10-24 16:40:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,515 bytes |
| コンパイル時間 | 1,805 ms |
| コンパイル使用メモリ | 179,280 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-16 04:27:37 |
| 合計ジャッジ時間 | 2,328 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 16 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define SORT(i) sort((i).begin(),(i).end())
constexpr ll INF = 2000000000;
constexpr ll mod = 1000000007;
int y[4] = { 0,1,0,-1 };
int x[4] = { 1,0,-1,0 };
int main() {
int W, H; cin >> W >> H;
vector<vector<char>>maze(H, vector<char>(W));
vector<vector<int>>dist(H, vector<int>(W, -1));
queue<pair<int, int>>que;
queue<pair<int, int>>q;
rep(i, H) {
rep(j, W) {
cin >> maze[i][j];
if (maze[i][j] == '.') {
dist[i][j] = INF;
que.push(make_pair(i, j));
q.push(make_pair(i, j));
}
}
}
int ny, nx;
while (!que.empty()) {
pair<int, int>N = que.front(); que.pop();
rep(i, 4) {
ny = N.first + y[i], nx = N.second + x[i];
if (ny < 0 || nx < 0 || ny >= H || nx >= W || dist[ny][nx] != -1 || maze[ny][nx] == '#')continue;
dist[ny][nx] = INF;
que.push(make_pair(ny, nx));
q.push(make_pair(ny, nx));
}
}
int ans = INF;
while (!q.empty()) {
pair<int, int>N = q.front();q.pop();
rep(i, 4) {
ny = N.first + y[i], nx = N.second + x[i];
if (ny < 0 || nx < 0 || ny >= H || nx >= W || dist[ny][nx] != -1)continue;
if (dist[N.first][N.second] == INF) {
dist[ny][nx] = 1;
}
else if (maze[ny][nx] == '.') {
ans = min(ans, dist[N.first][N.second]);
dist[ny][nx] = dist[N.first][N.second] + 1;
}
else {
dist[ny][nx] = dist[N.first][N.second] + 1;
}
q.push(make_pair(ny, nx));
}
}
cout << ans << "\n";
return 0;
}
Captain