Submission #58505
ソースコード
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]){ 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:27:44 |
言語 | C++ |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 1409 Byte |
最大実行時間 | 1205 ms |
最大メモリ使用量 | 102976 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | Easy | 1 / 1 | *easy, *sample* |
2 | ALL | 9 / 9 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | |
---|---|---|---|---|---|
input-sample1 | AC | 24 ms | 4700 KB |
1
|
2
|
input-sample2 | AC | 20 ms | 4788 KB |
1
|
2
|
input01-easy | AC | 20 ms | 13176 KB |
1
|
2
|
input02-easy | AC | 24 ms | 13192 KB |
1
|
2
|
input03-easy | AC | 25 ms | 17508 KB |
1
|
2
|
input04 | AC | 638 ms | 88544 KB |
2
|
|
input05 | AC | 426 ms | 80828 KB |
2
|
|
input06 | AC | 607 ms | 85776 KB |
2
|
|
input07 | AC | 657 ms | 80776 KB |
2
|
|
input08 | AC | 748 ms | 96500 KB |
2
|
|
input09 | AC | 765 ms | 97864 KB |
2
|
|
input10 | AC | 769 ms | 98584 KB |
2
|
|
input11 | AC | 1205 ms | 102380 KB |
2
|
|
input12 | AC | 747 ms | 102976 KB |
2
|
|
input13 | AC | 22 ms | 15888 KB |
2
|
|
input14 | AC | 24 ms | 15856 KB |
2
|