結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-05 23:37:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,766 bytes |
| コンパイル時間 | 672 ms |
| コンパイル使用メモリ | 95,624 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 14:23:59 |
| 合計ジャッジ時間 | 2,343 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 9 RE * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:5: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | ff(x, y);
| ~~^~~~~~
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;
const int N = 30;
string s[30];
int first[N][N] = {0};
int dp[N][N] = {0};
int dx[4] = {1,0,-1,0}, dy[4] = {0, 1, 0, -1};
void ff(int x, int y) {
if (s[x][y] != '.') {
return;
}
first[x][y] = 1;
REP (i, 0, 4) {
if (first[x + dx[i]][y + dy[i]] == 0) {
ff(x + dx[i], y + dy[i]);
}
}
}
int main(void){
int w,h;
cin >> w >> h;
int x = -1,y;
REP(i, 0, h) {
cin >> s[i];
REP(j, 0, w) {
if (x == -1 && s[i][j] == '.') {
x = i, y = j;
}
}
fill_n(dp[i], w, -1);
}
ff(x, y);
queue<pair<PI, int> > que;
REP(i,0, h) {
REP(j, 0, w) {
if (first[i][j]) {
que.push(pair<PI,int>(PI(i, j), 0));
}
}
}
int mi = 1000000;
while (! que.empty()) {
pair<PI, int> pi = que.front(); que.pop();
PI p = pi.first;
if (dp[p.first][p.second] >= 0) {
continue;
}
dp[p.first][p.second] = pi.second;
if (s[p.first][p.second] == '.' && pi.second) {
mi = min(mi, pi.second);
}
REP(i, 0, 4) {
int nx = p.first + dx[i], ny = p.second + dy[i];
int nv = pi.second + 1;
que.push(pair<PI, int>(PI(nx,ny), nv));
}
}
cout << mi - 1 << endl;
}