Submission #291675

# Submission time Handle Problem Language Result Execution time Memory
291675 2020-09-05T16:01:04 Z reymontada61 Dango Maker (JOI18_dango_maker) C++14
13 / 100
1 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

const int MXN = 3005;
int n, m;
int grid[MXN][MXN];
int horizontal[MXN][MXN];
int vertical[MXN][MXN];
int hnum, vnum;

int par[MXN * MXN];
int gs[MXN * MXN];
int tgs[MXN * MXN];

int parent(int x) {
	if (par[x] == x) return x;
	return par[x] = parent(par[x]);
}

void connect(int a, int b) {
	a = parent(a);
	b = parent(b);
	if (a == b) return;
	gs[a] += gs[b];
	tgs[a] += tgs[b];
	par[b] = a;
}

signed main() {

	cin >> n >> m;
	for (int i=1; i<=n; i++) {
		string s;
		cin >> s;
		for (int j=1; j<=m; j++) {
			if (s[j-1] == 'R') grid[i][j] = 1;
			if (s[j-1] == 'G') grid[i][j] = 2;
			if (s[j-1] == 'W') grid[i][j] = 3;
		}
	}
	
	
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			if (grid[i][j] == 1 && grid[i][j+1] == 2 && grid[i][j+2] == 3) {
				hnum++;
				horizontal[i][j] = hnum;
			}
			if (grid[i][j] == 1 && grid[i+1][j] == 2 && grid[i+2][j] == 3) {
				hnum++;
				vertical[i][j] = hnum;
				tgs[hnum] = 1;
			}
		}
	}
	
	for (int i=0; i<=hnum; i++) par[i] = i, gs[i] = 1;
	
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			int c = grid[i][j] - 1;
			if (vertical[i-c][j] > 0 && horizontal[i][j-c] > 0) {
				int x = horizontal[i][j-c];
				int y = vertical[i-c][j];
				connect(x, y);
			}
		}
	}
	
	int x = 0;
	
	for (int i=1; i<=hnum; i++) {
		if (par[i] == i) {
			x += max(gs[i] - tgs[i], tgs[i]);
		}
	}
	
	cout << x << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Incorrect 1 ms 512 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 640 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Incorrect 1 ms 512 KB Output isn't correct
35 Halted 0 ms 0 KB -