結果
問題 | No.402 最も海から遠い場所 |
ユーザー | hiyokko2 |
提出日時 | 2016-07-31 15:35:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,350 bytes |
コンパイル時間 | 1,461 ms |
コンパイル使用メモリ | 168,084 KB |
実行使用メモリ | 578,944 KB |
最終ジャッジ日時 | 2024-04-24 13:18:27 |
合計ジャッジ時間 | 9,303 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,624 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 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 | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 12 ms
5,760 KB |
testcase_14 | AC | 10 ms
5,504 KB |
testcase_15 | AC | 71 ms
15,744 KB |
testcase_16 | AC | 244 ms
33,536 KB |
testcase_17 | AC | 1,560 ms
212,224 KB |
testcase_18 | MLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) //#define int long long using namespace std; int H, W; char grid[3000][3000]; set<pair<int, int> > riku; int di[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; int dj[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; //海に隣接していたらtrueを返す bool check(int i, int j) { rep(ii,8) { int ni = i + di[ii]; int nj = j + dj[ii]; if (ni < 0 || H <= ni || nj < 0 || W <= nj) { return true; } if (grid[ni][nj] == '.') { return true; } } return false; } signed main() { cin >> H >> W; rep(i,H) { cin >> grid[i]; } rep(i,H) { rep(j,W) { if (grid[i][j] == '#') { riku.insert(pair<int, int>(i, j)); } } } int ans = 0; while (!riku.empty()) { //printf("riku.size() = %d\n", riku.size()); ans++; set<pair<int, int> > new_riku; set<pair<int, int> > unimisuru; set<pair<int, int> >::iterator it = riku.begin(); while (it != riku.end()) { if (check(it->first, it->second)) { unimisuru.insert(pair<int, int>(it->first, it->second)); //grid[it->first][it->second] = '.'; } else { new_riku.insert(pair<int, int>(it->first, it->second)); } ++it; } it = unimisuru.begin(); while (it != unimisuru.end()) { grid[it->first][it->second] = '.'; ++it; } riku = new_riku; } cout << ans << endl; }