Submission #58506


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
int p[100000005] , rank[100000005] ;
char m[100000005];
int findSet( int x ){
if(x != p[x]){
p[x] = findSet(p[x]);
}
return(p[x]);
}
void link( int x , int y ){
int X = findSet(x);
int Y = findSet(y);
if(X != Y){
if(rank[X] > rank[Y]){
rank[X] += rank[Y];
p[Y] = X;
} else {
rank[Y] += rank[X];
p[X] = Y;
}
}
}
void appiar(int x ,int y){
m[x*10000+y] = '#';
if(rank[x*10000+y] == 0){
rank[x*10000+y]++;
if(m[(x-1)*10000+y] == '#'){
link(x*10000+y , (x-1)*10000+y);
}
if(m[(x+1)*10000+y] == '#'){
link(x*10000+y , (x+1)*10000+y);
}
if(m[x*10000+y-1] == '#'){
link(x*10000+y , x*10000+y-1);
}
if(m[x*10000+y+1] == '#'){
link(x*10000+y , x*10000+y+1);
}
}
}
int land(int x , int y){
int z=findSet(x*10000+y);
return(rank[z]);
}
signed main(){
int h , w , q , com , a , b;
cin>> h >> w >> q;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
p[i*10000+j] = i*10000+j;
rank[i*10000+j] = 0;
cin>>m[i*10000+j];
if(m[i*10000+j] == '#'){
appiar(i,j);
}
}
}
for(int i=0;i<q;i++){
cin>> com >> a >> b;
if(com == 0){
appiar(a,b);
} else {
cout<<land(a,b)<<endl;
}
}
return(0);
}

ステータス

項目 データ
問題 0971 - 島の創造
ユーザー名 ei1929
投稿日時 2020-02-06 17:29:21
言語 C++
状態 Accepted
得点 10
ソースコード長 1412 Byte
最大実行時間 1217 ms
最大メモリ使用量 103004 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input-sample1 AC 25 ms 4700 KB
1
2
input-sample2 AC 21 ms 4660 KB
1
2
input01-easy AC 24 ms 13308 KB
1
2
input02-easy AC 16 ms 13320 KB
1
2
input03-easy AC 23 ms 17508 KB
1
2
input04 AC 637 ms 88416 KB
2
input05 AC 431 ms 80832 KB
2
input06 AC 612 ms 85784 KB
2
input07 AC 674 ms 80788 KB
2
input08 AC 732 ms 96516 KB
2
input09 AC 759 ms 97880 KB
2
input10 AC 760 ms 98736 KB
2
input11 AC 1217 ms 102404 KB
2
input12 AC 758 ms 103004 KB
2
input13 AC 17 ms 15796 KB
2
input14 AC 21 ms 15896 KB
2