Submission #667565

# Submission time Handle Problem Language Result Execution time Memory
667565 2022-12-01T17:43:12 Z AmirAli_H1 Dango Maker (JOI18_dango_maker) C++17
0 / 100
1 ms 432 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;
const int maxs = 9e6 + 5;
const int maxc = 6e6 + 5;
string s[maxn];
int arr[maxs][2];
vector<pair<pii, bool>> V;
bitset<maxc> mark, c4;
int dp[maxc][8];
vector<int> A;

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

void get_adj(int v) {
	A.clear();
	int i = V[v].F.F, j = V[v].F.S; bool f = V[v].S;
	if (f == 0) {
		for (int j1 : {j, j + 1, j + 2}) {
			if (arr[GI(i, j1)][1] != -1) A.pb(arr[GI(i, j1)][1]);
		}
	}
	else {
		for (int i1 : {i, i + 1, i + 2}) {
			if (arr[GI(i1, j)][0] != -1) A.pb(arr[GI(i1, j)][0]);
		}
	}
}
 
void dfs(int v, int p = -1) {
	mark[v] = 1;
	vector<int> vc;
	get_adj(v);
	for (int u : A) {
		if (!mark[u]) {
			dfs(u, v);
			vc.pb(u);
		}
		else if (u != p) {
			c4[v] = 1;
		}
	}
	for (int i = 0; i < 8; i++) {
		int b1 = (bool) (i & 1), b2 = (bool) (i & 2), b3 = (bool) (i & 4);
		if ((b1 && b2) || (b2 && b3)) continue;
		dp[v][i] += b1;
		for (int u : vc) {
			int val0 = b1 * 2 + b2 * 4, val1 = 1 + b1 * 2 + b2 * 4;
			if (b1 || (c4[u] && b3)) {
				dp[v][i] += dp[u][val0];
			}
			else {
				dp[v][i] += max(dp[u][val0], dp[u][val1]);
			}
		}
	}
	vc.clear();
}
 
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 * m; i++) {
		arr[i][0] = -1; arr[i][1] = -1;
	}
	
	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') {
				for (int j1 : {j, j + 1, j + 2}) {
					arr[GI(i, j1)][0] = len(V);
				}
				V.pb(Mp(Mp(i, j), 0));
			}
		}
	}
	
	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') {
				for (int i1 : {i, i + 1, i + 2}) {
					arr[GI(i1, j)][1] = len(V);
				}
				V.pb(Mp(Mp(i, j), 1));
			}
		}
	}
	
	int output = 0;
	for (int i = 0; i < len(V); i++) {
		if (!mark[i]) {
			dfs(i);
			output += max(dp[i][0], dp[i][1]);
		}
	}
	
	cout << output << endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Halted 0 ms 0 KB -