Submission #10018399
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
/* 幅優先探索。dequeをキューとして使う。ABC007/c とほぼ同じ。スタート地点が複数あるので、最初の時点でキューに複数のタプルが挿入される。*/
int main(void){
int H,W;
cin >> H >> W;
char board[H][W];
deque<tuple<int, int, int>> will_search;
int dot_count = 0;
rep(i,H){
rep(j,W){
cin >> board[i][j];
if(board[i][j] == '#')will_search.emplace_back(make_tuple(i,j,0));
}
}
const int DIRECTION_NUM = 4;
const int dx[DIRECTION_NUM] = {1, -1, 0, 0};
const int dy[DIRECTION_NUM] = {0, 0, 1, -1};
int ans = 0;
while(!will_search.empty()){
tuple<int, int, int> current_location = will_search.front();
will_search.pop_front();
rep(i,DIRECTION_NUM){
int next_y = get<0>(current_location) + dy[i];
int next_x = get<1>(current_location) + dx[i];
int step = get<2>(current_location) + 1;
if(next_x >= 0 && next_x < W && next_y >= 0 && next_y < H){
if(board[next_y][next_x] == '.'){
will_search.emplace_back(make_tuple(next_y, next_x, step));
board[next_y][next_x] = '#';
ans = step;
}
}
}
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Darker and Darker |
| User | tubotu |
| Language | C++14 (GCC 5.4.1) |
| Score | 300 |
| Code Size | 1473 Byte |
| Status | AC |
| Exec Time | 80 ms |
| Memory | 13328 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample01.txt, sample02.txt |
| All | sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, sample01.txt, sample02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| in01.txt | AC | 75 ms | 5120 KiB |
| in02.txt | AC | 80 ms | 7428 KiB |
| in03.txt | AC | 70 ms | 8720 KiB |
| in04.txt | AC | 74 ms | 13328 KiB |
| in05.txt | AC | 1 ms | 256 KiB |
| in06.txt | AC | 69 ms | 1280 KiB |
| in07.txt | AC | 69 ms | 1280 KiB |
| in08.txt | AC | 69 ms | 1280 KiB |
| in09.txt | AC | 69 ms | 1280 KiB |
| in10.txt | AC | 32 ms | 768 KiB |
| in11.txt | AC | 28 ms | 640 KiB |
| in12.txt | AC | 29 ms | 640 KiB |
| in13.txt | AC | 29 ms | 768 KiB |
| sample01.txt | AC | 1 ms | 256 KiB |
| sample02.txt | AC | 1 ms | 256 KiB |