답안 #66756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66756 2018-08-12T09:06:04 Z cdemirer Dango Maker (JOI18_dango_maker) C++17
13 / 100
229 ms 212148 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<vi> vvi;
typedef pair<double, double> dodo;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)


int N, M;

vvi edges;
int num_nodes = 0;
int createNode() {
	edges.pb(vi());
	return num_nodes++;
}
void connect(int a, int b) {
	edges[a].pb(b);
	edges[b].pb(a);
}

const int ARRSIZE = 3000*3000;
int parent[ARRSIZE];
bool vis[ARRSIZE] = {0};
/*int dpi[ARRSIZE], dpe[ARRSIZE];

void dfs(int x) {
	vis[x] = true;
	int no = -1;
	for (int i = 0; i < edges[x].size(); i++) {
		int y = edges[x][i];
		if (y == parent[x]) continue;
		if (vis[y]) {
			no = i;
			continue;
		}
		parent[y] = x;
		dfs(y);
	}
	dpi[x] = 1;
	for (int i = 0; i < edges[x].size(); i++) {
		int y = edges[x][i];
		if (y == parent[x]) continue;
		if (y == no) continue;
		dpi[x] += dpe[y];
	}
	dpe[x] = 0;
	for (int i = 0; i < edges[x].size(); i++) {
		int y = edges[x][i];
		if (y == parent[x]) continue;
		if (y == no) continue;
		dpe[x] += max(dpi[y], dpe[y]);
	}
}*/
int dfs(int x, bool b) {
	vis[x] = true;
	int ret = b;
	for (int i = 0; i < edges[x].size(); i++) {
		int y = edges[x][i];
		if (vis[y]) continue;
		ret += dfs(y, !b);
	}
	return ret;
}
void clean(int x) {
	vis[x] = false;
	for (int i = 0; i < edges[x].size(); i++) {
		int y = edges[x][i];
		if (!vis[y]) continue;
		clean(y);
	}
}	

int mat[3000][3000];
vi touch[3000][3000];
void memory_opt() {
	
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		for (int j = 0; j < M; j++) {
			if (s[j] == 'R') mat[i][j] = 0;
			if (s[j] == 'G') mat[i][j] = 1;
			if (s[j] == 'W') mat[i][j] = 2;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M-2; j++) {
			if (mat[i][j]*9 + mat[i][j+1]*3 + mat[i][j+2]*1 == 5) {
				int x = createNode();
				if (touch[i][j].size() > 0) {
					for (int k = 0; k < touch[i][j].size(); k++) connect(x, touch[i][j][k]);
				}
				touch[i][j].pb(x);
				if (touch[i][j+1].size() > 0) {
					for (int k = 0; k < touch[i][j+1].size(); k++) connect(x, touch[i][j+1][k]);
				}
				touch[i][j+1].pb(x);
				if (touch[i][j+2].size() > 0) {
					for (int k = 0; k < touch[i][j+2].size(); k++) connect(x, touch[i][j+2][k]);
				}
				touch[i][j+2].pb(x);
			}
		}
	}
	for (int i = 0; i < N-2; i++) {
		for (int j = 0; j < M; j++) {
			if (mat[i][j]*9 + mat[i+1][j]*3 + mat[i+2][j]*1 == 5) {
				int x = createNode();
				if (touch[i][j].size() > 0) {
					for (int k = 0; k < touch[i][j].size(); k++) connect(x, touch[i][j][k]);
				}
				touch[i][j].pb(x);
				if (touch[i+1][j].size() > 0) {
					for (int k = 0; k < touch[i+1][j].size(); k++) connect(x, touch[i+1][j][k]);
				}
				touch[i+1][j].pb(x);
				if (touch[i+2][j].size() > 0) {
					for (int k = 0; k < touch[i+2][j].size(); k++) connect(x, touch[i+2][j][k]);
				}
				touch[i+2][j].pb(x);
			}
		}
	}
}

int main(int argc, char **argv) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	memory_opt();
	
	//cerr << num_nodes << endl;
	int sum = 0;
	for (int i = 0; i < num_nodes; i++) {
		if (vis[i]) continue;
		//parent[i] = -1;
		int a = dfs(i, true);
		clean(i);
		int b = dfs(i, false);
		sum += max(a, b);
		//sum += max(dpi[i], dpe[i]);
		//cerr << "i am " << i << " i added " << max(dpi[i], dpe[i]) << endl;
	}
	cout << sum << endl;
	
	return 0;
}

Compilation message

dango_maker.cpp: In function 'int dfs(int, bool)':
dango_maker.cpp:63:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < edges[x].size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'void clean(int)':
dango_maker.cpp:72:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < edges[x].size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'void memory_opt()':
dango_maker.cpp:97:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int k = 0; k < touch[i][j].size(); k++) connect(x, touch[i][j][k]);
                      ~~^~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:101:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int k = 0; k < touch[i][j+1].size(); k++) connect(x, touch[i][j+1][k]);
                      ~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:105:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int k = 0; k < touch[i][j+2].size(); k++) connect(x, touch[i][j+2][k]);
                      ~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:116:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int k = 0; k < touch[i][j].size(); k++) connect(x, touch[i][j][k]);
                      ~~^~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:120:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int k = 0; k < touch[i+1][j].size(); k++) connect(x, touch[i+1][j][k]);
                      ~~^~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:124:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for (int k = 0; k < touch[i+2][j].size(); k++) connect(x, touch[i+2][j][k]);
                      ~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 211704 KB Output is correct
2 Correct 229 ms 211816 KB Output is correct
3 Correct 179 ms 211816 KB Output is correct
4 Correct 191 ms 211900 KB Output is correct
5 Correct 205 ms 211932 KB Output is correct
6 Correct 228 ms 211932 KB Output is correct
7 Correct 198 ms 212056 KB Output is correct
8 Correct 197 ms 212056 KB Output is correct
9 Correct 195 ms 212056 KB Output is correct
10 Correct 199 ms 212056 KB Output is correct
11 Correct 183 ms 212056 KB Output is correct
12 Correct 172 ms 212056 KB Output is correct
13 Correct 175 ms 212056 KB Output is correct
14 Correct 174 ms 212056 KB Output is correct
15 Correct 174 ms 212056 KB Output is correct
16 Correct 182 ms 212056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 211704 KB Output is correct
2 Correct 229 ms 211816 KB Output is correct
3 Correct 179 ms 211816 KB Output is correct
4 Correct 191 ms 211900 KB Output is correct
5 Correct 205 ms 211932 KB Output is correct
6 Correct 228 ms 211932 KB Output is correct
7 Correct 198 ms 212056 KB Output is correct
8 Correct 197 ms 212056 KB Output is correct
9 Correct 195 ms 212056 KB Output is correct
10 Correct 199 ms 212056 KB Output is correct
11 Correct 183 ms 212056 KB Output is correct
12 Correct 172 ms 212056 KB Output is correct
13 Correct 175 ms 212056 KB Output is correct
14 Correct 174 ms 212056 KB Output is correct
15 Correct 174 ms 212056 KB Output is correct
16 Correct 182 ms 212056 KB Output is correct
17 Correct 183 ms 212056 KB Output is correct
18 Correct 197 ms 212076 KB Output is correct
19 Correct 210 ms 212076 KB Output is correct
20 Correct 195 ms 212076 KB Output is correct
21 Correct 180 ms 212076 KB Output is correct
22 Correct 209 ms 212076 KB Output is correct
23 Correct 199 ms 212076 KB Output is correct
24 Correct 174 ms 212076 KB Output is correct
25 Correct 188 ms 212076 KB Output is correct
26 Correct 176 ms 212076 KB Output is correct
27 Correct 198 ms 212076 KB Output is correct
28 Correct 179 ms 212076 KB Output is correct
29 Correct 193 ms 212076 KB Output is correct
30 Correct 176 ms 212076 KB Output is correct
31 Correct 186 ms 212076 KB Output is correct
32 Correct 193 ms 212148 KB Output is correct
33 Correct 187 ms 212148 KB Output is correct
34 Incorrect 176 ms 212148 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 211704 KB Output is correct
2 Correct 229 ms 211816 KB Output is correct
3 Correct 179 ms 211816 KB Output is correct
4 Correct 191 ms 211900 KB Output is correct
5 Correct 205 ms 211932 KB Output is correct
6 Correct 228 ms 211932 KB Output is correct
7 Correct 198 ms 212056 KB Output is correct
8 Correct 197 ms 212056 KB Output is correct
9 Correct 195 ms 212056 KB Output is correct
10 Correct 199 ms 212056 KB Output is correct
11 Correct 183 ms 212056 KB Output is correct
12 Correct 172 ms 212056 KB Output is correct
13 Correct 175 ms 212056 KB Output is correct
14 Correct 174 ms 212056 KB Output is correct
15 Correct 174 ms 212056 KB Output is correct
16 Correct 182 ms 212056 KB Output is correct
17 Correct 183 ms 212056 KB Output is correct
18 Correct 197 ms 212076 KB Output is correct
19 Correct 210 ms 212076 KB Output is correct
20 Correct 195 ms 212076 KB Output is correct
21 Correct 180 ms 212076 KB Output is correct
22 Correct 209 ms 212076 KB Output is correct
23 Correct 199 ms 212076 KB Output is correct
24 Correct 174 ms 212076 KB Output is correct
25 Correct 188 ms 212076 KB Output is correct
26 Correct 176 ms 212076 KB Output is correct
27 Correct 198 ms 212076 KB Output is correct
28 Correct 179 ms 212076 KB Output is correct
29 Correct 193 ms 212076 KB Output is correct
30 Correct 176 ms 212076 KB Output is correct
31 Correct 186 ms 212076 KB Output is correct
32 Correct 193 ms 212148 KB Output is correct
33 Correct 187 ms 212148 KB Output is correct
34 Incorrect 176 ms 212148 KB Output isn't correct
35 Halted 0 ms 0 KB -