답안 #667475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667475 2022-12-01T14:04:53 Z AmirAli_H1 Dango Maker (JOI18_dango_maker) C++17
0 / 100
103 ms 262144 KB
// In the name of Allah

#include <bits/stdc++.h>
using namespace std;

typedef long long int	ll;
typedef long double	ld;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;

#define all(x)		(x).begin(),(x).end()
#define len(x)		((ll) (x).size())
#define F		first
#define S		second
#define pb		push_back
#define sep             ' '
#define endl            '\n'
#define Mp		make_pair
#define debug(x)	cerr << #x << ": " <<  x << endl;
#define kill(x)		cout << x << '\n', exit(0);
#define set_dec(x)	cout << fixed << setprecision(x);
#define file_io(x,y)	freopen(x, "r", stdin); freopen(y, "w", stdout);

int n, m;
const int maxn = 3e3 + 5;
string s[maxn];
int cntv = 0;
vector<int> arr[maxn * maxn];
vector<int> adj[maxn * maxn];
bool mark[maxn];
int h[maxn]; int cnt[2];

int GI(int i, int j) {
	return i * m + j;
}

void dfs(int v) {
	mark[v] = 1;
	cnt[h[v] % 2]++;
	for (int u : adj[v]) {
		if (!mark[u]) {
			h[u] = h[v] + 1;
			dfs(u);
		}
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> s[i];
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m - 2; j++) {
			if (s[i][j] == 'R' && s[i][j + 1] == 'G' && s[i][j + 2] == 'W') {
				arr[GI(i, j)].pb(cntv); arr[GI(i, j + 1)].pb(cntv); arr[GI(i, j + 2)].pb(cntv);
				cntv++;
			}
		}
	}
	
	for (int i = 0; i < n - 2; i++) {
		for (int j = 0; j < m; j++) {
			if (s[i][j] == 'R' && s[i + 1][j] == 'G' && s[i + 2][j] == 'W') {
				arr[GI(i, j)].pb(cntv); arr[GI(i + 1, j)].pb(cntv); arr[GI(i + 2, j)].pb(cntv);
				cntv++;
			}
		}
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int k1 = 0; k1 < len(arr[GI(i, j)]); k1++) {
				for (int k2 = k1 + 1; k2 < len(arr[GI(i, j)]); k2++) {
					int v1 = arr[GI(i, j)][k1], v2 = arr[GI(i, j)][k2];
					adj[v1].pb(v2); adj[v2].pb(v1);
				}
			}
		}
	}
	
	int output = 0;
	for (int i = 0; i < cntv; i++) {
		if (!mark[i]) {
			dfs(i);
			output += max(cnt[0], cnt[1]);
			cnt[0] = 0; cnt[1] = 0;
		}
	}
	
	cout << output << endl;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 103 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 103 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 103 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -