結果
問題 | No.157 2つの空洞 |
ユーザー |
|
提出日時 | 2016-09-22 17:43:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,752 bytes |
コンパイル時間 | 1,872 ms |
コンパイル使用メモリ | 174,076 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 13:09:28 |
合計ジャッジ時間 | 2,743 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" #define REP(i,a,b) for(i=a;i<b;++i) #define rep(i,n) REP(i,0,n) #define ll long long #define ull unsigned ll typedef long double ld; #define ALL(a) begin(a),end(a) #define ifnot(a) if(not a) #define dump(x) cerr << #x << " = " << (x) << endl using namespace std; // #define int ll #ifdef _MSC_VER const bool test = true; #else const bool test = false; #endif int dx[] = { 0,1,0,-1 }; int dy[] = { 1,0,-1,0 }; #define INF (1 << 28) ull mod = (int)1e9 + 7; //..................... #define MAX (int)1e6 + 5 char field[30][30]; int fieldv[30][30]; struct Point { int y, x, cnt; }; queue<Point> q; int H, W; bool ng(int y, int x) { return y < 0 || H <= y || x < 0 || W <= x; } void dfs(int y,int x) { int i, j; field[y][x] = '!'; q.push({ y,x,0 }); fieldv[y][x] = 0; rep(i, 4) { int ny = y + dy[i]; int nx = x + dx[i]; if (ng(ny, nx)) continue; if (field[ny][nx] == '.') { dfs(ny, nx); } } } void grid_bfs() { int i, j; //............. cin >> W >> H; rep(i, H) { cin >> field[i]; } //.............. rep(i, H) rep(j, W) fieldv[i][j] = INF; rep(i, H) rep(j, W) { if (field[i][j] == '.') { dfs(i, j); goto part1; } } part1: rep(i, H) { cerr << field[i] << endl; } while (q.size()) { auto now = q.front(); q.pop(); auto next = now; next.cnt++; rep(i, 4) { next.y = now.y + dy[i]; next.x = now.x + dx[i]; if (ng(next.y, next.x)) continue; if (fieldv[next.y][next.x] == INF) { if (field[next.y][next.x] == '.') { cout << now.cnt << endl; return; } fieldv[next.y][next.x] = next.cnt; q.push(next); } } } } signed main(void) { int i, j, k, l; grid_bfs(); return 0; }