제출 #953583

#제출 시각아이디문제언어결과실행 시간메모리
953583roshanVermaTracks in the Snow (BOI13_tracks)C++17
2.19 / 100
2062 ms923192 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 4020;
int foxVis[N][N], rabbitVis[N][N];
int h,w,fox;
string forest[N];

void dfs( int x, int y ){
	if( x < 0 || x >= h || y < 0 || y >= w || forest[h][w] == '.' ) return;
	if( fox ){
		if( foxVis[x][y] == 1 ) return;
		foxVis[x][y] = 1;
	}else{
		if( rabbitVis[x][y] == 1 ) return;
		rabbitVis[x][y] = 1;
	}
	dfs(x+1,y);
	dfs(x-1,y);
	dfs(x,y+1);
	dfs(x,y-1);
}

int main(){
	cin >> h >> w;
	for( int i = 0 ; i < h ; i++ ) cin >> forest[i];

	int f = 0, r = 0;
	for( int i = 0 ; i < h ; i++ ){
		for( int j = 0 ; j < w ; j++ ){
			if( forest[i][j] == 'F' ) f = 1;
			else if( forest[i][j] == 'R' ) r = 1;
		}
	}

	int ans = 0, ans1 = 0, ans2 = 0;
	for( int i = 0 ; i < h ; i++ ){
		for( int j = 0 ; j < w ; j++ ){
			if( forest[i][j] == '.' || rabbitVis[i][j] ) continue;
			ans1++;
			dfs(i,j);
		}
	}

	fox = 1;
	for( int i = 0 ; i < h ; i++ ){
		for( int j = 0 ; j < w ; j++ ){
			if( forest[i][j] == '.' || foxVis[i][j] ) continue;
			ans2++;
			dfs(i,j);
		}
	}

	if( f ) ans += ans2;
	if( r ) ans += ans1;

	cout << ans << endl;

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...