Submission #00032


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <cstdio>
#include <queue>
#include <utility>
#define DEBUG printf("foobar\n");
using namespace std;
typedef struct {
int y, x;
}pos;
int h, w;
int group[1005][1005], d = 1;
char mp[1005][1005];
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
queue<pos>que;
void bomb(int y, int x, int level);
void bfs(int y, int x);
void printm(); //Debug Ojisan dayooo^~
int main()
{
int n;
int sy, sx;
int gy, gx;
cin >> h >> w;
for ( int i = 0; i < h; i++) {
for ( int j = 0; j < w; j++) {
cin >> mp[i][j];
}
}
//Bomb
for ( int i = 0; i < h; i++) {
for ( int j = 0; j < w; j++) {
if ( mp[i][j] >= '1' && mp[i][j] <= '9' ) {
bomb(i, j, (int)(mp[i][j] - '0'));
}
}
}
//Bomb
//group
for ( int i = 0; i < h; i++) {
for ( int j = 0; j < w; j++) {
if ( group[i][j] == 0 && mp[i][j] == '.') {
bfs(i, j);
d++;
}
}
}
//group
cin >> n;
for ( int i = 0; i < n; i++) {
cin >> sx >> sy >> gx >> gy;
if ( group[sy][sx] == group[gy][gx] && group[sy][sx] != 0) {
printf("yes\n");
} else {
printf("no\n");
}
}
return (0);
}
void bomb(int y, int x, int level)
{
mp[y][x] = '.';
for ( int i = y - level; i <= y + level; i++) {
for ( int j = x - level; j <= x + level; j++) {
if ( i >= 0 && i < h && j >= 0 && j < w ) {
if ( mp[i][j] == '#' ) {
mp[i][j] = '.';
}
}
}
}
return;
}
void bfs(int y, int x)
{
group[y][x] = d;
que.push((pos){y, x});
while( !que.empty() ) {
pos now = que.front(); que.pop();
int y = now.y;
int x = now.x;
for ( int i = 0; i < 4; i++) {
int ny = y + dy[i];
int nx = x + dx[i];
if ( ny >= 0 && ny < h && nx >= 0 && nx < w ) {
if ( mp[ny][nx] == '.' && group[ny][nx] == 0 ) {
group[ny][nx] = d;
que.push((pos){ny, nx});
}
}
}
}
return;
}
void printm()
{
for ( int i = 0; i < h; i++) {
for ( int j = 0; j < w; j++) {
printf("%c", mp[i][j]);
}
printf("\n");
}
return;
}

ステータス

項目 データ
問題 0002 - 韓流ハゲ
ユーザー名 ei1710
投稿日時 2018-08-22 10:40:59
言語 C++14
状態 Accepted
得点 10
ソースコード長 2534 Byte
最大実行時間 103 ms
最大メモリ使用量 5624 KB

セット

セット 得点 Cases
1 ALL 10 / 10 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in00.dat AC 30 ms 608 KB
1
in01.dat AC 20 ms 736 KB
1
in02.dat AC 19 ms 952 KB
1
in03.dat AC 22 ms 1456 KB
1
in04.dat AC 28 ms 4028 KB
1
in05.dat AC 22 ms 4212 KB
1
in06.dat AC 35 ms 4044 KB
1
in07.dat AC 75 ms 5284 KB
1
in08.dat AC 71 ms 5336 KB
1
in09.dat AC 79 ms 5384 KB
1
in10.dat AC 80 ms 5424 KB
1
in11.dat AC 83 ms 5460 KB
1
in12.dat AC 92 ms 5496 KB
1
in13.dat AC 91 ms 5540 KB
1
in14.dat AC 88 ms 5580 KB
1
in15.dat AC 103 ms 5624 KB
1