Submission #58261
ソースコード
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 | #include <bits/stdc++.h> // #include <iostream> // #include <fstream> // #include <string> // #include <map> // #include <vector> // #include <algorithm> // #include <regex> // #include <chrono> // #include <sstream> // #include <iomanip> // #include <queue> // #include <stack> // #include <set> // #include <unordered_map> // #include <unordered_set> using namespace std; #define __ <<" "<< #define ___ <<" " #define bash push_back #define ALL(x) x.begin(),x.end() //#define int long long struct IoSetup { IoSetup() { cin.tie(0); ios::sync_with_stdio( false ); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } }IoSetup; typedef long long ll; typedef pair < int , int > pii; static const signed int INF = 0x3f3f3f3f; static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL; static const signed int SMOD = 1000000007; static const signed int NMOD = 998244353; static const signed int dx[]={1,0,-1,0,1,1,-1,-1}; static const signed int dy[]={0,-1,0,1,-1,1,-1,1}; bool inside( int x, int y, int w, int h){ return (x>=0 && y>=0 && x<w && y<h);} template < class T> bool chmax(T &a, const T&b){ if (a<b) return (a=b,1); return 0;} template < class T> bool chmin(T &a, const T&b){ if (b<a) return (a=b,1); return 0;} struct UnionFind { vector< int > v; UnionFind( int n) : v(n+5, -1){} int root( int x){ return (v[x] < 0?x:root(v[x]));} int size( int x){ return -v[root(x)];} bool same( int x, int y){ return root(x)==root(y);} bool mage( int x, int y){ if ((x=root(x))==(y=root(y))) return false ; if (v[y]<v[x])swap(x,y);v[x] += v[y]; v[y] = x; return true ;} }; int h, w, q; string mas[1010]; signed main() { cin >> h >> w >> q; UnionFind uf(h*w); for ( int i = 0; i < h; i++) cin >> mas[i]; for ( int i = 0; i < h; i++) { for ( int j = 0; j < w; j++) { if (mas[i][j] == '#' ) { for ( int k = 0; k < 4; k++) { int y = i + dy[k]; int x = j + dx[k]; if (inside(x, y, w, h) && mas[y][x]== '#' ) { uf.mage(i*w+j, y*w+x); } } } } } int a, b, c; for ( int i = 0; i < q; i++) { cin >> a >> b >> c; b--, c--; if (!a){ mas[b][c] = '#' ; for ( int j = 0; j < 4; j++) { int y = b + dy[j]; int x = c + dx[j]; if (inside(x, y, w, h) && mas[y][x] == '#' ) uf.mage(b*w+c, y*w+x); } } else { if (mas[b][c] == '.' ) cout << 0 << endl; else cout << uf.size(b*w+c) << endl; } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0971 - 島の創造 |
ユーザー名 | ei1821 |
投稿日時 | 2020-01-24 19:22:22 |
言語 | C++14 |
状態 | Accepted |
得点 | 10 |
ソースコード長 | 2524 Byte |
最大実行時間 | 1015 ms |
最大メモリ使用量 | 16744 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | Easy | 1 / 1 | *easy, *sample* |
2 | ALL | 9 / 9 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | |
---|---|---|---|---|---|
input-sample1 | AC | 30 ms | 604 KB |
1
|
2
|
input-sample2 | AC | 20 ms | 648 KB |
1
|
2
|
input01-easy | AC | 27 ms | 564 KB |
1
|
2
|
input02-easy | AC | 21 ms | 540 KB |
1
|
2
|
input03-easy | AC | 16 ms | 640 KB |
1
|
2
|
input04 | AC | 515 ms | 5924 KB |
2
|
|
input05 | AC | 330 ms | 6212 KB |
2
|
|
input06 | AC | 467 ms | 6764 KB |
2
|
|
input07 | AC | 527 ms | 7832 KB |
2
|
|
input08 | AC | 556 ms | 10336 KB |
2
|
|
input09 | AC | 559 ms | 11716 KB |
2
|
|
input10 | AC | 578 ms | 12324 KB |
2
|
|
input11 | AC | 1015 ms | 16264 KB |
2
|
|
input12 | AC | 548 ms | 16744 KB |
2
|
|
input13 | AC | 16 ms | 11852 KB |
2
|
|
input14 | AC | 22 ms | 11776 KB |
2
|