답안 #99479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99479 2019-03-04T10:41:30 Z mzhao Dango Maker (JOI18_dango_maker) C++11
33 / 100
2000 ms 241284 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define D(x...) printf(x)
#else
#define D(x...)
#endif

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

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

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

int dp[9999][4]; // left is first bit   right is second bit
bool vis[9100100];

void comp(int d, int l, int r) {
	vis[l] = vis[r] = 1;
	vector<int> ladj, radj;
	for (int i : adj[l]) if (!vis[i]) ladj.push_back(i);
	for (int i : adj[r]) if (!vis[i]) radj.push_back(i);
	assert(ladj.size() < 3 && radj.size() < 3);
	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) {
		assert(ladj[0] == radj[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+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) {
		assert(radj.size() == 1);
		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) {
		assert(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;
		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;
	} else {
		assert(0);
	}
	D("COMP %d %d %d\n", d, l, r);
	D("dp %d = %d %d %d % d\n", d, dp[d][0], dp[d][1], dp[d][2], dp[d][3]);
}

int main() {
	scanf("%d%d", &R, &C);
	for (int i = 0; i < R; i++) {
		char A;
		scanf("\n");
		for (int j = 0; j < C; j++) {
			scanf("%c", &A);
			if (A == 'G') G[i][j] = 1;
			if (A == 'W') G[i][j] = 2;
		}
	}
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			if (i < R-2 && G[i][j] == 0 && G[i+1][j] == 1 && G[i+2][j] == 2)
				f[i][j][1] = 1;
			if (j < C-2 && G[i][j] == 0 && G[i][j+1] == 1 && G[i][j+2] == 2)
				f[i][j][0] = 1;
		}
	}
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) D("%d", f[i][j][0]);
		D("\n");
	}
	D("\n");
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) D("%d", f[i][j][1]);
		D("\n");
	}
	D("\n");
	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]) {
					dfs(0, i, j, k);
					comp(0, adj[0].back(), 0);
					ans += max(dp[0][0], dp[0][1]);
				}
			}
		}
	}
	for (int i = 0; i <= nn; i++) {
		D("%d = ", i);
		for (int j : adj[i]) D("%d ", j);
		D("\n");
	}
	printf("%d\n", ans);
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:148:12: warning: unused variable 'j' [-Wunused-variable]
   for (int j : adj[i]) D("%d ", j);
            ^
dango_maker.cpp:107: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:110:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("\n");
   ~~~~~^~~~~~
dango_maker.cpp:112:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%c", &A);
    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 214096 KB Output is correct
2 Correct 210 ms 214076 KB Output is correct
3 Correct 207 ms 214136 KB Output is correct
4 Correct 206 ms 214008 KB Output is correct
5 Correct 220 ms 214008 KB Output is correct
6 Correct 212 ms 214136 KB Output is correct
7 Correct 208 ms 214108 KB Output is correct
8 Correct 204 ms 214004 KB Output is correct
9 Correct 218 ms 214104 KB Output is correct
10 Correct 206 ms 214152 KB Output is correct
11 Correct 197 ms 214108 KB Output is correct
12 Correct 196 ms 214136 KB Output is correct
13 Correct 196 ms 214064 KB Output is correct
14 Correct 193 ms 214008 KB Output is correct
15 Correct 204 ms 214188 KB Output is correct
16 Correct 218 ms 214016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 214096 KB Output is correct
2 Correct 210 ms 214076 KB Output is correct
3 Correct 207 ms 214136 KB Output is correct
4 Correct 206 ms 214008 KB Output is correct
5 Correct 220 ms 214008 KB Output is correct
6 Correct 212 ms 214136 KB Output is correct
7 Correct 208 ms 214108 KB Output is correct
8 Correct 204 ms 214004 KB Output is correct
9 Correct 218 ms 214104 KB Output is correct
10 Correct 206 ms 214152 KB Output is correct
11 Correct 197 ms 214108 KB Output is correct
12 Correct 196 ms 214136 KB Output is correct
13 Correct 196 ms 214064 KB Output is correct
14 Correct 193 ms 214008 KB Output is correct
15 Correct 204 ms 214188 KB Output is correct
16 Correct 218 ms 214016 KB Output is correct
17 Correct 195 ms 214020 KB Output is correct
18 Correct 212 ms 214268 KB Output is correct
19 Correct 200 ms 214128 KB Output is correct
20 Correct 213 ms 214120 KB Output is correct
21 Correct 194 ms 214136 KB Output is correct
22 Correct 198 ms 214264 KB Output is correct
23 Correct 211 ms 214136 KB Output is correct
24 Correct 209 ms 214092 KB Output is correct
25 Correct 213 ms 214136 KB Output is correct
26 Correct 226 ms 214008 KB Output is correct
27 Correct 194 ms 214216 KB Output is correct
28 Correct 203 ms 214260 KB Output is correct
29 Correct 197 ms 214136 KB Output is correct
30 Correct 223 ms 214392 KB Output is correct
31 Correct 186 ms 214212 KB Output is correct
32 Correct 202 ms 214244 KB Output is correct
33 Correct 195 ms 214136 KB Output is correct
34 Correct 197 ms 214136 KB Output is correct
35 Correct 198 ms 214264 KB Output is correct
36 Correct 185 ms 214136 KB Output is correct
37 Correct 191 ms 214288 KB Output is correct
38 Correct 182 ms 214180 KB Output is correct
39 Correct 205 ms 214136 KB Output is correct
40 Correct 201 ms 214136 KB Output is correct
41 Correct 184 ms 214264 KB Output is correct
42 Correct 196 ms 214188 KB Output is correct
43 Correct 202 ms 214264 KB Output is correct
44 Correct 218 ms 214264 KB Output is correct
45 Correct 204 ms 214136 KB Output is correct
46 Correct 192 ms 214264 KB Output is correct
47 Correct 196 ms 214156 KB Output is correct
48 Correct 198 ms 214264 KB Output is correct
49 Correct 211 ms 214136 KB Output is correct
50 Correct 189 ms 214180 KB Output is correct
51 Correct 207 ms 214296 KB Output is correct
52 Correct 201 ms 214268 KB Output is correct
53 Correct 199 ms 214252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 214096 KB Output is correct
2 Correct 210 ms 214076 KB Output is correct
3 Correct 207 ms 214136 KB Output is correct
4 Correct 206 ms 214008 KB Output is correct
5 Correct 220 ms 214008 KB Output is correct
6 Correct 212 ms 214136 KB Output is correct
7 Correct 208 ms 214108 KB Output is correct
8 Correct 204 ms 214004 KB Output is correct
9 Correct 218 ms 214104 KB Output is correct
10 Correct 206 ms 214152 KB Output is correct
11 Correct 197 ms 214108 KB Output is correct
12 Correct 196 ms 214136 KB Output is correct
13 Correct 196 ms 214064 KB Output is correct
14 Correct 193 ms 214008 KB Output is correct
15 Correct 204 ms 214188 KB Output is correct
16 Correct 218 ms 214016 KB Output is correct
17 Correct 195 ms 214020 KB Output is correct
18 Correct 212 ms 214268 KB Output is correct
19 Correct 200 ms 214128 KB Output is correct
20 Correct 213 ms 214120 KB Output is correct
21 Correct 194 ms 214136 KB Output is correct
22 Correct 198 ms 214264 KB Output is correct
23 Correct 211 ms 214136 KB Output is correct
24 Correct 209 ms 214092 KB Output is correct
25 Correct 213 ms 214136 KB Output is correct
26 Correct 226 ms 214008 KB Output is correct
27 Correct 194 ms 214216 KB Output is correct
28 Correct 203 ms 214260 KB Output is correct
29 Correct 197 ms 214136 KB Output is correct
30 Correct 223 ms 214392 KB Output is correct
31 Correct 186 ms 214212 KB Output is correct
32 Correct 202 ms 214244 KB Output is correct
33 Correct 195 ms 214136 KB Output is correct
34 Correct 197 ms 214136 KB Output is correct
35 Correct 198 ms 214264 KB Output is correct
36 Correct 185 ms 214136 KB Output is correct
37 Correct 191 ms 214288 KB Output is correct
38 Correct 182 ms 214180 KB Output is correct
39 Correct 205 ms 214136 KB Output is correct
40 Correct 201 ms 214136 KB Output is correct
41 Correct 184 ms 214264 KB Output is correct
42 Correct 196 ms 214188 KB Output is correct
43 Correct 202 ms 214264 KB Output is correct
44 Correct 218 ms 214264 KB Output is correct
45 Correct 204 ms 214136 KB Output is correct
46 Correct 192 ms 214264 KB Output is correct
47 Correct 196 ms 214156 KB Output is correct
48 Correct 198 ms 214264 KB Output is correct
49 Correct 211 ms 214136 KB Output is correct
50 Correct 189 ms 214180 KB Output is correct
51 Correct 207 ms 214296 KB Output is correct
52 Correct 201 ms 214268 KB Output is correct
53 Correct 199 ms 214252 KB Output is correct
54 Correct 196 ms 214060 KB Output is correct
55 Correct 212 ms 223224 KB Output is correct
56 Correct 219 ms 214448 KB Output is correct
57 Correct 244 ms 236552 KB Output is correct
58 Execution timed out 2053 ms 241284 KB Time limit exceeded
59 Halted 0 ms 0 KB -