Submission #330291

# Submission time Handle Problem Language Result Execution time Memory
330291 2020-11-24T14:01:37 Z maximath_1 Chameleon's Love (JOI20_chameleon) C++17
100 / 100
67 ms 644 KB
#include "chameleon.h"
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

bool bad(vector<int> v, int x){
	v.push_back(x);
	return Query(v) != v.size();
}

void Solve(int n){
	vector<int> adj[2 * n + 5];

	for(int cr = 1; cr <= 2 * n; cr ++){
		vector<int> color(cr), inset[2];

		function<void(int, int)> dfs = [&](int nw, int cl){
			if(color[nw]) return;
			color[nw] = cl;
			for(int nx : adj[nw])
				dfs(nx, 3 - cl);
		};

		for(int i = 1; i < cr; i ++){
			if(!color[i]) dfs(i, 1);
			inset[color[i] - 1].push_back(i);
		}

		for(int i = 0; i < 2; i ++){
			while(bad(inset[i], cr)){
				int lf = 1, rg = inset[i].size();
				for(int md; lf < rg;){
					md = (lf + rg) / 2;
					if(bad(vector<int>(inset[i].begin(), inset[i].begin() + md), cr))
						rg = md;
					else
						lf = md + 1;
				}

				adj[cr].push_back(inset[i][lf - 1]);
				adj[inset[i][lf - 1]].push_back(cr);

				inset[i] = vector<int>(inset[i].begin() + lf, inset[i].end());
			}
		}
	}

	vector<int> same(2 * n + 5), n1(2 * n + 5), n2(2 * n + 5);

	for(int i = 1; i <= 2 * n; i ++){
		if(adj[i].size() == 1)
			same[i] = adj[i][0];
		else{
			while(Query({i, adj[i][0], adj[i][1]}) != 1)
				rotate(adj[i].begin(), adj[i].begin() + 1, adj[i].end());
			n1[i] = adj[i][2];
			n2[adj[i][2]] = i;
		}
	}

	for(int i = 1; i <= 2 * n; i ++){
		if(!same[i])
			same[i] = adj[i][0] + adj[i][1] + adj[i][2] - n1[i] - n2[i];
		if(i > same[i])
			Answer(same[i], i);
	}

	return;
}

Compilation message

chameleon.cpp: In function 'bool bad(std::vector<int>, int)':
chameleon.cpp:9:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |  return Query(v) != v.size();
      |         ~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 40 ms 620 KB Output is correct
4 Correct 37 ms 492 KB Output is correct
5 Correct 38 ms 492 KB Output is correct
6 Correct 40 ms 620 KB Output is correct
7 Correct 37 ms 492 KB Output is correct
8 Correct 37 ms 492 KB Output is correct
9 Correct 37 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 57 ms 492 KB Output is correct
4 Correct 58 ms 492 KB Output is correct
5 Correct 67 ms 492 KB Output is correct
6 Correct 58 ms 492 KB Output is correct
7 Correct 58 ms 512 KB Output is correct
8 Correct 57 ms 620 KB Output is correct
9 Correct 58 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 40 ms 620 KB Output is correct
4 Correct 37 ms 492 KB Output is correct
5 Correct 38 ms 492 KB Output is correct
6 Correct 40 ms 620 KB Output is correct
7 Correct 37 ms 492 KB Output is correct
8 Correct 37 ms 492 KB Output is correct
9 Correct 37 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 0 ms 364 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 57 ms 492 KB Output is correct
31 Correct 58 ms 492 KB Output is correct
32 Correct 67 ms 492 KB Output is correct
33 Correct 58 ms 492 KB Output is correct
34 Correct 58 ms 512 KB Output is correct
35 Correct 57 ms 620 KB Output is correct
36 Correct 58 ms 492 KB Output is correct
37 Correct 58 ms 492 KB Output is correct
38 Correct 37 ms 512 KB Output is correct
39 Correct 58 ms 644 KB Output is correct
40 Correct 58 ms 492 KB Output is correct
41 Correct 59 ms 492 KB Output is correct
42 Correct 37 ms 492 KB Output is correct
43 Correct 57 ms 492 KB Output is correct
44 Correct 58 ms 492 KB Output is correct
45 Correct 58 ms 492 KB Output is correct