Submission #20209546
Source Code Expand
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
#define rep(i, n)for(int i=0; i<n; i++)
#define ll long long
ll INF = 1000000007;
ll H, W;
// (h, w)が領域に収まっていればtrue
bool included(ll h, ll w){
bool ret = false;
if(0 <= h && h <H && 0 <= w && w < W){
ret = true;
}
return ret;
}
int main(){
cin >> H >> W;
char A[H][W];
rep(i, H)
rep(j, W)
cin >> A[i][j];
//
// 4近傍を見る
ll hy[] = {0, -1, 0, 1};
ll wx[] = {1, 0, -1, 0};
ll ans = 0;
// 黒マスをキューに入れる
// 黒マスの数をカウント
queue<pair<ll, ll>> q;
ll black_num = 0;
bool visited[H][W];
rep(i, H){
rep(j, W){
visited[i][j] = false;
}
}
rep(i, H){
rep(j, W){
if(A[i][j] == '#'){
q.push(make_pair(i, j) );
visited[i][j] = true;
black_num++;
}
}
}
while(black_num < H*W){
ll num = q.size();
for(ll i = 0; i<num; i++){
ll y = q.front().first, x = q.front().second;
q.pop();
// 4近傍を見る
for(ll k=0; k<4; k++){
// 次の点を処理
ll ny = y + hy[k], nx = x + wx[k];
// 領域におさまっている,かつ未訪問
if(included(ny, nx) ){
if(!visited[ny][nx]){
q.push(make_pair(ny, nx) );
visited[ny][nx] = true;
black_num++;
}
}
}
} // for( auto )
ans++;
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Darker and Darker |
| User | kilu23 |
| Language | C++ (GCC 9.2.1) |
| Score | 300 |
| Code Size | 1756 Byte |
| Status | AC |
| Exec Time | 69 ms |
| Memory | 21676 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 | 67 ms | 10280 KiB |
| in02.txt | AC | 69 ms | 13656 KiB |
| in03.txt | AC | 63 ms | 15248 KiB |
| in04.txt | AC | 61 ms | 21676 KiB |
| in05.txt | AC | 2 ms | 3560 KiB |
| in06.txt | AC | 54 ms | 5524 KiB |
| in07.txt | AC | 57 ms | 5584 KiB |
| in08.txt | AC | 58 ms | 5636 KiB |
| in09.txt | AC | 55 ms | 5508 KiB |
| in10.txt | AC | 33 ms | 4416 KiB |
| in11.txt | AC | 31 ms | 4496 KiB |
| in12.txt | AC | 31 ms | 4328 KiB |
| in13.txt | AC | 33 ms | 4456 KiB |
| sample01.txt | AC | 2 ms | 3500 KiB |
| sample02.txt | AC | 3 ms | 3536 KiB |