結果

問題 No.402 最も海から遠い場所
ユーザー mamekin
提出日時 2016-10-07 12:59:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 692 ms / 3,000 ms
コード長 1,449 bytes
コンパイル時間 1,109 ms
コンパイル使用メモリ 110,832 KB
実行使用メモリ 86,060 KB
最終ジャッジ日時 2024-11-21 19:35:24
合計ジャッジ時間 5,460 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h+4, string(w+4, '.'));
    for(int y=0; y<h; ++y){
        for(int x=0; x<w; ++x){
            cin >> s[y+2][x+2];
        }
    }

    h += 4;
    w += 4;
    queue<pair<int, int> > q;
    for(int y=1; y<h-1; ++y){
        for(int x=1; x<w-1; ++x){
            if(s[y][x] == '.')
                q.push(make_pair(y, x));
        }
    }

    int ans = -1;
    while(!q.empty()){
        int n = q.size();
        while(--n >= 0){
            int y, x;
            tie(y, x) = q.front();
            q.pop();

            for(int dy=-1; dy<=1; ++dy){
                for(int dx=-1; dx<=1; ++dx){
                    int y2 = y + dy;
                    int x2 = x + dx;
                    if(s[y2][x2] == '#'){
                        s[y2][x2] = '.';
                        q.push(make_pair(y2, x2));
                    }
                }
            }
        }
        ++ ans;
    }
    cout << ans << endl;

    return 0;
}
0