Submission #1350437


Source Code Expand

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int H,W;
	cin >> H >> W;
	vector< string > org(H),fldA(H),fldB(H);
	UnionFind uf(H*W);
	vector< bool > used(H*W,false);//代表値のみuf.find()
	for(int h=0;h<H;++h){
		cin >> org[h];
		fldA[h] = org[h];
		fldB[h] = org[h];
		for(int w=0;w<W;++w){
			if( org[h][w] != '#' ) continue;
			if( org[h-1][w] == '#' ){
				uf.add((h-1)*W + w,h*W + w);
			}
			if( org[h][w-1] == '#' ){
				uf.add(h*W + (w-1),h*W + w );
			}
		}
	}
	
	
	for(int w=1;w<W-1;++w){//端でない一番上を塗る。
		fldA[1][w] = '#';
		if( w > 1 ){//左と繋ぐ
			uf.add(W + w-1,W + w);
			int num = uf.find(W+w);
			used[num] = true;
		}
		if( 2 < H ){
			if( fldA[2][w] == '#' ){//下
				uf.add(1*W + w, 2*W + w);
				int num = uf.find(1*W+w);
				used[num] = true;
			}
		}
	}
	
	for(int h=0;h<H;++h){//全面塗る。
		for(int w=0;w<W;++w){
			fldB[h][w] = '#';
		}
		if( h==1 ){
			for(int w=1;w<W-1;++w){
				if( org[h][w] != '#' ){
					fldB[h][w] = '.';//fldAで塗っている
				}
			}
		}
	}
	
	for(int h=2;h<H-1;++h){
		for(int w=1;w<W-1;++w){
			if( org[h][w] != '#' ) continue;
			int num = h*W + w;
			num = uf.find( num );
			if( used[num] ) continue;
			used[num] = true;
			for(int hh = h-1; hh>=1;--hh){
				if( org[hh][w] == '#' ) break;
				fldA[hh][w] = '#';
				fldB[hh][w] = '.';
			}
		}
	}
	for(int h=0;h<H;++h){
		cout << fldA[h] << endl;
	}
	cout << endl;
	for(int h=0;h<H;++h){
		cout << fldB[h] << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()

Submission Info

Submission Time
Task C - AND Grid
User akarin55
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2689 Byte
Status CE

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:51:2: error: ‘UnionFind’ was not declared in this scope
  UnionFind uf(H*W);
  ^
./Main.cpp:60:5: error: ‘uf’ was not declared in this scope
     uf.add((h-1)*W + w,h*W + w);
     ^
./Main.cpp:63:5: error: ‘uf’ was not declared in this scope
     uf.add(h*W + (w-1),h*W + w );
     ^
./Main.cpp:72:4: error: ‘uf’ was not declared in this scope
    uf.add(W + w-1,W + w);
    ^
./Main.cpp:78:5: error: ‘uf’ was not declared in this scope
     uf.add(1*W + w, 2*W + w);
     ^
./Main.cpp:102:10: error: ‘uf’ was not declared in this scope
    num = uf.find( num );
          ^