Submission #58743

#TimeUsernameProblemLanguageResultExecution timeMemory
58743YaDon4ickDango Maker (JOI18_dango_maker)C++11
13 / 100
4 ms752 KiB
//By Don4ick
#define _GLIBCXX_DEBUG
 
#include <bits/stdc++.h>
 
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
 
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234
 
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
 
const int N = 3005;
const int M = N * N * 2;
 
using namespace std;
 
bool was[2][N][N];
int n, m, cnt0, cnt1;
string s[N];
 
bool check(int x, int y, int type)
{
	if (x < 0 || x > n || y < 0 || y > m)
		return false;
	if (type == 0)	
	{
		if (y >= m - 2)
			return false;
		return s[x][y] == 'R' && s[x][y + 1] == 'G' && s[x][y + 2] == 'W';	
	}
	else
	{
		if (x >= n - 2)
			return false;
		return s[x][y] == 'R' && s[x + 1][y] == 'G' && s[x + 2][y] == 'W';
	}
}
 
void dfs(int x, int y, int type)
{
	was[type][x][y] = true;
	if (type == 0)
	{
		cnt0++;
		for (int i = 0; i < 3; i++)
		{
			int tx = x - i, ty = y + i;
			if (check(tx, ty, 1) && !was[1][tx][ty])
				dfs(tx, ty, 1);
		}
	}	
	else
	{
		cnt1++;
		for (int i = 0; i < 3; i++)
		{
			int tx = x + i, ty = y - i;
			if (check(tx, ty, 0) && !was[0][tx][ty])
				dfs(tx, ty, 0);
		}
	}
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
 
	//~read
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> s[i];
	//~solve
	int ans = 0; 
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (check(i, j, 0) && !was[0][i][j])
			{
				cnt0 = cnt1 = 0;
				dfs(i, j, 0);
				ans += max(cnt0, cnt1);
			}
			if (check(i, j, 1) && !was[1][i][j])
			{
				cnt0 = cnt1 = 0;
				dfs(i, j, 1);
				ans += max(cnt0, cnt1);
	    	}
		}
	}
	//~result
	cout << ans << endl;
 
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...