結果

問題 No.402 最も海から遠い場所
ユーザー ctyl_0ctyl_0
提出日時 2016-07-22 23:41:19
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,129 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 99,304 KB
実行使用メモリ 470,272 KB
最終ジャッジ日時 2024-04-24 06:16:50
合計ジャッジ時間 15,125 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 12 ms
5,504 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 71 ms
15,104 KB
testcase_16 AC 119 ms
21,120 KB
testcase_17 AC 1,643 ms
227,712 KB
testcase_18 AC 2,739 ms
94,336 KB
testcase_19 TLE -
testcase_20 AC 1,309 ms
49,536 KB
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    rep(i, H) cin >> A[i];
    vector<vector<int>> B(H, vector<int>(W, -1));
    
    set<pair<int, int>> st;
    
    rep(i, H) rep(j, W){
        if(A[i][j] == '.') B[i][j] = 0, st.insert(mp(i, j));
    }
    
    
    
    int cur = 0;
    while(!st.empty() || cur == 0){
        cur++;
        set<pair<int, int>> tmp;
        for(auto itr = st.begin(); itr != st.end(); ++itr) {
            int y = (*itr).first, x = (*itr).second;
            rep(i, 8){
                if(y + dy[i] >= 0 && y + dy[i] < H && x + dx[i] >= 0 && x + dx[i] < W){
                    if(B[y + dy[i]][x + dx[i]] == -1){
                        B[y + dy[i]][x + dx[i]] = cur;
                        tmp.insert(mp(y + dy[i], x + dx[i]));
                    }
                }
            }
        }
        if(cur == 1){
            rep(i, H){
                if(B[i][0] == -1) B[i][0] = 1, tmp.insert(mp(i, 0));
                if(B[i][W - 1] == -1) B[i][W - 1] = 1, tmp.insert(mp(i, W - 1));
            }
            rep(i, W){
                if(B[0][i] == -1) B[0][i] = 1, tmp.insert(mp(0, i));
                if(B[H - 1][i] == -1) B[H - 1][i] = 1, tmp.insert(mp(H - 1, i));
            }
        }
        st = tmp;
    }
    
    output(cur - 1, 0);
    return 0;
}
0