답안 #99503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99503 2019-03-04T11:24:53 Z mzhao Dango Maker (JOI18_dango_maker) C++11
100 / 100
1136 ms 107024 KB
#include <bits/stdc++.h>
using namespace std;

int R, C, ans;
char G[3001][3001];
bool f[3001][3001][2]; // 0 is horizontal, 1 is vertical
int id[3001][3001][2];

int nn;
vector<int> adj[6001];

void dfs(int p, int x, int y, int z) {
	if (id[x][y][z]) {
		if (p) adj[p].push_back(id[x][y][z]);
		return;
	}
	id[x][y][z] = ++nn;
	adj[id[x][y][z]].clear();
	if (p) adj[p].push_back(id[x][y][z]);
	if (z) {
		if (f[x][y][0]) dfs(id[x][y][z], x, y, 0);
		if (y > 0 && f[x+1][y-1][0]) dfs(id[x][y][z], x+1, y-1, 0);
		if (y > 1 && f[x+2][y-2][0]) dfs(id[x][y][z], x+2, y-2, 0);
	} else {
		if (f[x][y][1]) dfs(id[x][y][z], x, y, 1);
		if (x > 0 && f[x-1][y+1][1]) dfs(id[x][y][z], x-1, y+1, 1);
		if (x > 1 && f[x-2][y+2][1]) dfs(id[x][y][z], x-2, y+2, 1);
	}
}

int dp[6001][4]; // left is first bit   right is second bit
bool vis[6001];
vector<int> ladj, radj;

void comp(int d, int l, int r) {
	vis[l] = vis[r] = 1;
	ladj.clear(); radj.clear();
	for (int i : adj[l]) if (!vis[i]) ladj.push_back(i);
	for (int i : adj[r]) if (!vis[i]) radj.push_back(i);
	if (!ladj.size() && !radj.size()) {
		if (l) {
			dp[d][0] = 0;
			dp[d][1] = 1;
		}
		if (r) {
			dp[d][2] = 1;
			dp[d][3] = 2;
		}
		return;
	}
	if (l && r && ladj.size() == 1 && radj.size() == 1) {
		comp(d+1, ladj[0], 0);
		dp[d][0] = max(dp[d+1][0], dp[d+1][1]);
		dp[d][1] = dp[d+1][0]+1;
		dp[d][2] = dp[d+1][0]+1;
		dp[d][3] = dp[d+1][0]+2;
	} else if (l && r && ladj.size() == 2 && radj.size() == 1) {
		if (ladj[0] == radj[0]) swap(ladj[0], ladj[1]);
		comp(d+1, ladj[0], ladj[1]);
		dp[d][0] = max(max(dp[d+1][0], dp[d+1][1]), max(dp[d+1][2], dp[d+1][3]));
		dp[d][1] = dp[d+1][0]+1;
		dp[d][2] = max(dp[d+1][0], dp[d+1][1])+1;
		dp[d][3] = dp[d+1][0]+2;
	} else if (l && r && radj.size() == 2 && ladj.size() == 1) {
		if (radj[1] == ladj[0]) swap(radj[0], radj[1]);
		comp(d+1, radj[0], radj[1]);
		dp[d][0] = max(max(dp[d+1][0], dp[d+1][1]), max(dp[d+1][2], dp[d+1][3]));
		dp[d][1] = max(dp[d+1][0], dp[d+1][2])+1;
		dp[d][2] = dp[d+1][0]+1;
		dp[d][3] = dp[d+1][0]+2;
	} else if (l && r && ladj.size() == 0) {
		comp(d+1, radj[0], 0);
		dp[d][0] = max(dp[d+1][0], dp[d+1][1]);
		dp[d][1] = dp[d][0]+1;
		dp[d][2] = dp[d+1][0]+1;
		dp[d][3] = dp[d+1][0]+2;
	} else if (l && r && radj.size() == 0) {
		comp(d+1, ladj[0], 0);
		dp[d][0] = max(dp[d+1][0], dp[d+1][1]);
		dp[d][1] = dp[d+1][0]+1;
		dp[d][2] = dp[d][0]+1;
		dp[d][3] = dp[d+1][0]+2;
	} else if (l && !r && ladj.size() == 2) {
		comp(d+1, ladj[0], ladj[1]);
		dp[d][0] = max(max(dp[d+1][0], dp[d+1][1]), max(dp[d+1][2], dp[d+1][3]));
		dp[d][1] = dp[d+1][0]+1;
	} else if (l && !r && ladj.size() == 1) {
		comp(d+1, ladj[0], 0);
		dp[d][0] = max(dp[d+1][0], dp[d+1][1]);
		dp[d][1] = dp[d+1][0]+1;
	}
}

int main() {
	scanf("%d%d", &R, &C);
	for (int i = 0; i < R; i++) {
		scanf("\n");
		for (int j = 0; j < C; j++) {
			scanf("%c", &G[i][j]);
		}
	}
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			if (i < R-2 && G[i][j] == 'R' && G[i+1][j] == 'G' && G[i+2][j] == 'W')
				f[i][j][1] = 1;
			if (j < C-2 && G[i][j] == 'R' && G[i][j+1] == 'G' && G[i][j+2] == 'W')
				f[i][j][0] = 1;
		}
	}
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			for (int k = 0; k < 2; k++) {
				if (!id[i][j][k] && f[i][j][k]) {
					nn = 0;
					dfs(0, i, j, k);
					for (int z = 0; z <= nn; z++) vis[z] = 0;
					comp(0, 1, 0);
					ans += max(dp[0][0], dp[0][1]);
				}
			}
		}
	}
	printf("%d\n", ans);
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &R, &C);
  ~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("\n");
   ~~~~~^~~~~~
dango_maker.cpp:99:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%c", &G[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 3 ms 640 KB Output is correct
34 Correct 3 ms 640 KB Output is correct
35 Correct 3 ms 640 KB Output is correct
36 Correct 2 ms 640 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 2 ms 640 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 3 ms 640 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 640 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 640 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 0 ms 512 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 2 ms 640 KB Output is correct
51 Correct 3 ms 640 KB Output is correct
52 Correct 4 ms 640 KB Output is correct
53 Correct 3 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 3 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 2 ms 640 KB Output is correct
21 Correct 2 ms 640 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 3 ms 640 KB Output is correct
34 Correct 3 ms 640 KB Output is correct
35 Correct 3 ms 640 KB Output is correct
36 Correct 2 ms 640 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 2 ms 640 KB Output is correct
40 Correct 2 ms 640 KB Output is correct
41 Correct 3 ms 640 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 640 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 640 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 0 ms 512 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 2 ms 640 KB Output is correct
51 Correct 3 ms 640 KB Output is correct
52 Correct 4 ms 640 KB Output is correct
53 Correct 3 ms 640 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 16 ms 10240 KB Output is correct
56 Correct 4 ms 640 KB Output is correct
57 Correct 22 ms 20472 KB Output is correct
58 Correct 79 ms 20964 KB Output is correct
59 Correct 748 ms 97372 KB Output is correct
60 Correct 711 ms 97420 KB Output is correct
61 Correct 607 ms 97488 KB Output is correct
62 Correct 3 ms 640 KB Output is correct
63 Correct 631 ms 97528 KB Output is correct
64 Correct 956 ms 98168 KB Output is correct
65 Correct 1082 ms 107024 KB Output is correct
66 Correct 1136 ms 106936 KB Output is correct
67 Correct 580 ms 55560 KB Output is correct
68 Correct 553 ms 55800 KB Output is correct
69 Correct 561 ms 66140 KB Output is correct
70 Correct 138 ms 22312 KB Output is correct
71 Correct 109 ms 22256 KB Output is correct
72 Correct 106 ms 22236 KB Output is correct
73 Correct 120 ms 22264 KB Output is correct
74 Correct 100 ms 22448 KB Output is correct
75 Correct 109 ms 22296 KB Output is correct
76 Correct 111 ms 22276 KB Output is correct
77 Correct 124 ms 22360 KB Output is correct
78 Correct 118 ms 22284 KB Output is correct
79 Correct 104 ms 22256 KB Output is correct
80 Correct 96 ms 22392 KB Output is correct
81 Correct 150 ms 22392 KB Output is correct
82 Correct 98 ms 22264 KB Output is correct
83 Correct 128 ms 22332 KB Output is correct
84 Correct 121 ms 22340 KB Output is correct
85 Correct 115 ms 22336 KB Output is correct
86 Correct 112 ms 22236 KB Output is correct
87 Correct 121 ms 22328 KB Output is correct
88 Correct 115 ms 22448 KB Output is correct
89 Correct 115 ms 22336 KB Output is correct
90 Correct 138 ms 22264 KB Output is correct