Submission #230634

# Submission time Handle Problem Language Result Execution time Memory
230634 2020-05-10T16:34:38 Z wilwxk Chameleon's Love (JOI20_chameleon) C++14
100 / 100
63 ms 588 KB
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;

const int MAXN = 1005;
const int LOGN = 9;
int color[MAXN];
vector<int> bad[MAXN], ans[MAXN];
vector<int> comp[2];
int n;

void dfs(int u) {
	for(auto v : ans[u]) {
		if(color[v] != -1) continue;
		color[v] = color[u]^1;
		dfs(v);
	}
}

void separate(int k) {
	for(int i = 1; i <= k; i++) color[i] = -1;
	for(int i = 1; i <= k; i++) {
		if(color[i] != -1) continue;
		color[i] = 0;
		dfs(i);
	}

	comp[0].clear();
	comp[1].clear();
	for(int i = 1; i <= k; i++) comp[color[i]].push_back(i);
}

int bsearch(int u, int k, int l, int r) {
	if(l >= r) return l;
	int x = l;
	vector<int> qv;

	comp[k].push_back(u);
	if(Query(comp[k]) == comp[k].size()) {
		comp[k].pop_back();
		return r;
	} 
	comp[k].pop_back();

	for(int j = LOGN; j >= 0; j--) {
		int ind = x + (1<<j);
		if(ind > r) continue;
		qv.clear();
		for(int i = l+1; i <= ind; i++) qv.push_back(comp[k][i]);
		qv.push_back(u);
		// for(auto a : qv) printf("%d ", a); cout << endl;
		// printf("q %d / %d %d %d %d\n", ind, u, k, l, r);
		if(Query(qv) == qv.size()) x = ind;
	}
	return x;
}

void Solve(int N) {
	n = 2*N;

	comp[0].push_back(1);

	for(int u = 2; u <= n; u++) {

		separate(u-1);

		int cnt = 0;
		for(int k = 0; k < 2; k++) {

			int l = -1; int r = comp[k].size()-1;

			for(int kk = 0; kk < 3; kk++) {
				if(cnt == 3) break;
				int ind = bsearch(u, k, l, r);
				if(ind == r) break;

				ans[u].push_back(comp[k][ind+1]);
				ans[comp[k][ind+1]].push_back(u);
				// printf("connect %d %d\n", u, comp[k][ind+1]);

				cnt++;
				l = ind+1;
			}
			
		}
	}


	for(int u = 1; u <= n; u++) {
		if(ans[u].size() == 1) continue;
		else {
			if(Query({u, ans[u][0], ans[u][1]}) == 1) {
				bad[ans[u][2]].push_back(u);
				bad[u].push_back(ans[u][2]);
			}
			else if(Query({u, ans[u][1], ans[u][2]}) == 1) {
				bad[ans[u][0]].push_back(u);
				bad[u].push_back(ans[u][0]);
			}
			else {
				bad[ans[u][1]].push_back(u);
				bad[u].push_back(ans[u][1]);
			}
		}
	}

	for(int u = 1; u <= n; u++) {
		if(color[u] == 2) continue;

		int x;
		if(ans[u].size() == 1) {
			x = ans[u][0];
		}
		else {
			for(int k = 0; k < 3; k++) {
				if(ans[u][k] != bad[u][0] && ans[u][k] != bad[u][1]) {
					x = ans[u][k];
				}
			}
		}
		
		Answer(u, x);
		color[u] = color[x] = 2;
	}
}

Compilation message

chameleon.cpp: In function 'int bsearch(int, int, int, int)':
chameleon.cpp:39:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(Query(comp[k]) == comp[k].size()) {
     ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
chameleon.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(Query(qv) == qv.size()) x = ind;
      ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:123:23: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   color[u] = color[x] = 2;
              ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 42 ms 384 KB Output is correct
4 Correct 42 ms 384 KB Output is correct
5 Correct 42 ms 384 KB Output is correct
6 Correct 42 ms 384 KB Output is correct
7 Correct 44 ms 512 KB Output is correct
8 Correct 42 ms 384 KB Output is correct
9 Correct 43 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 62 ms 588 KB Output is correct
4 Correct 55 ms 464 KB Output is correct
5 Correct 55 ms 504 KB Output is correct
6 Correct 56 ms 504 KB Output is correct
7 Correct 55 ms 504 KB Output is correct
8 Correct 57 ms 512 KB Output is correct
9 Correct 58 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 42 ms 384 KB Output is correct
4 Correct 42 ms 384 KB Output is correct
5 Correct 42 ms 384 KB Output is correct
6 Correct 42 ms 384 KB Output is correct
7 Correct 44 ms 512 KB Output is correct
8 Correct 42 ms 384 KB Output is correct
9 Correct 43 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 62 ms 588 KB Output is correct
31 Correct 55 ms 464 KB Output is correct
32 Correct 55 ms 504 KB Output is correct
33 Correct 56 ms 504 KB Output is correct
34 Correct 55 ms 504 KB Output is correct
35 Correct 57 ms 512 KB Output is correct
36 Correct 58 ms 468 KB Output is correct
37 Correct 61 ms 456 KB Output is correct
38 Correct 43 ms 464 KB Output is correct
39 Correct 63 ms 504 KB Output is correct
40 Correct 61 ms 504 KB Output is correct
41 Correct 61 ms 512 KB Output is correct
42 Correct 42 ms 384 KB Output is correct
43 Correct 55 ms 504 KB Output is correct
44 Correct 62 ms 456 KB Output is correct
45 Correct 63 ms 504 KB Output is correct