Submission #41095


ソースコード

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
#include<bits/stdc++.h>
using namespace std;
void search(int x,int y);
int find(int x);
int same(int x,int y);
void unite(int x,int y);
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
int h,w,q;
int mp[1009][1009];
int p[1000009];
int cost[1000009];
int main(){
scanf("%d %d %d",&h,&w,&q);
for(int i=0;i<h*w;i++){
p[i]=i;
cost[i]=0;
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
scanf(" %c",&mp[i][j]);
if(mp[i][j]=='#')cost[i*w+j]++;
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(mp[i][j]=='#'){
search(j,i);
}
}
}
for(int i=0;i<q;i++){
int t,x,y;
scanf("%d %d %d",&t,&y,&x);
x--;y--;
if(t==0){
mp[y][x]='#';
cost[y*w+x]++;
search(x,y);
}
else if(t==1){
printf("%d\n",cost[find(y*w+x)]);
}
}
return(0);
}
void search(int x,int y){
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(0<=nx&&nx<w&&0<=ny&&ny<h&&mp[ny][nx]=='#'){
if(!same(y*w+x,ny*w+nx)){
unite(y*w+x,ny*w+nx);
}
}
}
}
int find(int x){
if(p[x]==x)return x;
return p[x]=find(p[x]);
}
int same(int x,int y){
if(find(x)==find(y))return 1;
return 0;
}
void unite(int x,int y){
x=find(x);
y=find(y);
p[x]=y;
cost[y]+=cost[x];
}

ステータス

項目 データ
問題 0971 - 島の創造
ユーザー名 r1705
投稿日時 2018-08-10 10:29:33
言語 C++11
状態 Accepted
得点 10
ソースコード長 1344 Byte
最大実行時間 207 ms
最大メモリ使用量 23436 KB

セット

セット 得点 Cases
1 Easy 1 / 1 *easy, *sample*
2 ALL 9 / 9 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input-sample1 AC 25 ms 4576 KB
1
2
input-sample2 AC 25 ms 4548 KB
1
2
input01-easy AC 26 ms 4516 KB
1
2
input02-easy AC 25 ms 4568 KB
1
2
input03-easy AC 24 ms 6788 KB
1
2
input04 AC 205 ms 12912 KB
2
input05 AC 144 ms 13088 KB
2
input06 AC 171 ms 14092 KB
2
input07 AC 195 ms 14888 KB
2
input08 AC 192 ms 16948 KB
2
input09 AC 190 ms 18348 KB
2
input10 AC 207 ms 19104 KB
2
input11 AC 204 ms 22940 KB
2
input12 AC 189 ms 23436 KB
2
input13 AC 19 ms 15748 KB
2
input14 AC 20 ms 15720 KB
2