Submission #21472171


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
	using T = int;
	const T def = 0;
	T f(T a, T b) { return a + b; }
	//==========================================
    vector<int> par; 
	vector<T> value;
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
	void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
	int operator[](int x) {
		if (par[x] == x) return x;
		else {
			int res = operator[](par[x]);
			if (res != par[x]) {
				value[res] = f(value[res], value[par[x]]);
				value[par[x]] = def;
			}
			return par[x] = res;
		}
	}
	// uf(x,y)->y
    void operator()(int x, int y) {
		x = operator[](x); y = operator[](y); 
		if (x != y) {
			value[y] += value[par[x]];
			value[par[x]] = def;
			par[x] = y;
		}
	}
	T getValues(int x) { return value[operator[](x)]; };
};
struct UnionFind2D {
	using T = int;
	int H, W;
	UnionFind uf;
	UnionFind2D() {}
	UnionFind2D(int NH, int NW) { init(NH, NW); }
	void init(int NH, int NW) { H = NH, W = NW, uf.init(H * W); }
	// {x, y}
	pair<int, int> get(int x, int y) { return { uf[y * W + x] % W, uf[y * W + x] / W }; }
	void marge(int x1, int y1, int x2, int y2) {
		uf(x1 + y1 * W, x2 + y2 * W);
	}
	T getValue(int x, int y) { 
		return uf.getValues(x + y * W);
	}
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int H, W;
string S[10];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W;
	rep(y, 0, H) cin >> S[y];

	int ans = 0;
	rep(sy, 0, H) rep(sx, 0, W) if (S[sy][sx] == '#') {
		S[sy][sx] = '.';
		UnionFind2D uf(H, W);
		rep(y, 0, H - 1) rep(x, 0, W) if (S[y][x] == '.' && S[y + 1][x] == '.') {
			uf.marge(x, y, x, y + 1);
		}
		rep(y, 0, H) rep(x, 0, W - 1) if (S[y][x] == '.' && S[y][x + 1] == '.') {
			uf.marge(x, y, x + 1, y);
		}
		set<pair<int, int>> s;
		rep(y, 0, H) rep(x, 0, W) if (S[y][x] == '.') s.insert(uf.get(x, y));

		if (s.size() == 1) ans++;

		S[sy][sx] = '#';
	}
	cout << ans << endl;
}





Submission Info

Submission Time
Task G - 村整備
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 3328 Byte
Status AC
Exec Time 7 ms
Memory 3600 KB

Compile Error

./Main.cpp: In member function ‘void UnionFind::reset()’:
./Main.cpp:2:33: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    2 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
   23 |     void reset() { rep(i, 0, par.size()) par[i] = i; }
      |                        ~~~~~~~~~~~~~~~~
./Main.cpp:23:20: note: in expansion of macro ‘rep’
   23 |     void reset() { rep(i, 0, par.size()) par[i] = i; }
      |                    ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 2
AC × 44
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All handmade_00.txt, handmade_01.txt, handmade_02.txt, handmade_03.txt, handmade_04.txt, handmade_05.txt, handmade_06.txt, handmade_07.txt, handmade_08.txt, handmade_09.txt, handmade_10.txt, handmade_11.txt, random_2_components_00.txt, random_2_components_01.txt, random_2_components_02.txt, random_2_components_03.txt, random_2_components_04.txt, random_2_components_05.txt, random_2_components_06.txt, random_2_components_07.txt, random_2_components_08.txt, random_2_components_09.txt, random_3_components_00.txt, random_3_components_01.txt, random_3_components_02.txt, random_3_components_03.txt, random_3_components_04.txt, random_3_components_05.txt, random_3_components_06.txt, random_3_components_07.txt, random_3_components_08.txt, random_3_components_09.txt, random_connected_00.txt, random_connected_01.txt, random_connected_02.txt, random_connected_03.txt, random_connected_04.txt, random_connected_05.txt, random_connected_06.txt, random_connected_07.txt, random_connected_08.txt, random_connected_09.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
handmade_00.txt AC 7 ms 3544 KB
handmade_01.txt AC 3 ms 3548 KB
handmade_02.txt AC 2 ms 3584 KB
handmade_03.txt AC 3 ms 3520 KB
handmade_04.txt AC 4 ms 3600 KB
handmade_05.txt AC 3 ms 3532 KB
handmade_06.txt AC 2 ms 3576 KB
handmade_07.txt AC 2 ms 3484 KB
handmade_08.txt AC 2 ms 3540 KB
handmade_09.txt AC 1 ms 3580 KB
handmade_10.txt AC 3 ms 3588 KB
handmade_11.txt AC 3 ms 3536 KB
random_2_components_00.txt AC 2 ms 3460 KB
random_2_components_01.txt AC 3 ms 3548 KB
random_2_components_02.txt AC 2 ms 3532 KB
random_2_components_03.txt AC 2 ms 3600 KB
random_2_components_04.txt AC 2 ms 3532 KB
random_2_components_05.txt AC 2 ms 3596 KB
random_2_components_06.txt AC 2 ms 3520 KB
random_2_components_07.txt AC 3 ms 3576 KB
random_2_components_08.txt AC 3 ms 3412 KB
random_2_components_09.txt AC 2 ms 3576 KB
random_3_components_00.txt AC 3 ms 3516 KB
random_3_components_01.txt AC 3 ms 3580 KB
random_3_components_02.txt AC 2 ms 3516 KB
random_3_components_03.txt AC 2 ms 3544 KB
random_3_components_04.txt AC 2 ms 3532 KB
random_3_components_05.txt AC 2 ms 3592 KB
random_3_components_06.txt AC 2 ms 3548 KB
random_3_components_07.txt AC 2 ms 3528 KB
random_3_components_08.txt AC 2 ms 3580 KB
random_3_components_09.txt AC 3 ms 3588 KB
random_connected_00.txt AC 2 ms 3520 KB
random_connected_01.txt AC 2 ms 3588 KB
random_connected_02.txt AC 2 ms 3488 KB
random_connected_03.txt AC 7 ms 3536 KB
random_connected_04.txt AC 2 ms 3588 KB
random_connected_05.txt AC 2 ms 3576 KB
random_connected_06.txt AC 2 ms 3600 KB
random_connected_07.txt AC 2 ms 3600 KB
random_connected_08.txt AC 2 ms 3480 KB
random_connected_09.txt AC 4 ms 3460 KB
sample_01.txt AC 2 ms 3516 KB
sample_02.txt AC 2 ms 3576 KB