Submission #288797

# Submission time Handle Problem Language Result Execution time Memory
288797 2020-09-01T22:20:10 Z Saboon Chameleon's Love (JOI20_chameleon) C++17
100 / 100
64 ms 4472 KB
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;
typedef long long ll;

const int maxn = 1000 + 10;

int cnt[maxn][maxn];
vector<int> g[maxn];
int h[maxn];
vector<int> a, b;

void dfs(int v){
	if (h[v] % 2 == 0)
		a.push_back(v);
	else
		b.push_back(v);
	for (auto u : g[v])
		if (h[u] == -1){
			h[u] = h[v] + 1;
			dfs(u);
		}
}

int now = 0;

bool find(int l, int r, int v, vector<int> &x, bool sure = false){
	if (now == 3)
		return false;
	vector<int> Q;
	if (!sure){
		for (int i = l; i < r; i++)
			Q.push_back(x[i]);
		Q.push_back(v);
		if (Query(Q) == Q.size())
			return false;
	}
	if (l+1 == r){
		g[v].push_back(x[l]);
		g[x[l]].push_back(v);
		now ++;
		return true;
	}
	int mid = (l+r) >> 1;
	bool ret = find(l, mid, v, x);
	ret |= find(mid, r, v, x, ret^1);
	return ret;
}

void Solve(int n){
	for (int i = 2; i <= 2*n; i++){
		memset(h, -1, sizeof h);
		a.clear();
		b.clear();
		for (int j = 1; j <= i-1; j++){
			if (h[j] == -1){
				h[j] = 0;
				dfs(j);
			}
		}
		now = 0;
		find(0, a.size(), i, a);
		find(0, b.size(), i, b);
	}

	for (int i = 1; i <= 2*n; i++){
		if (g[i].size() == 1){
			cnt[i][g[i][0]] ++, cnt[g[i][0]][i] ++;
			continue;
		}
		bool found = false;
		for (int x = 0; !found and x < 3; x++){
			for (int y = x+1; !found and y < 3; y++){
				vector<int> v = {i, g[i][x], g[i][y]};
				if (Query(v) == 1){
					cnt[i][g[i][x]] ++, cnt[g[i][x]][i] ++;
					cnt[i][g[i][y]] ++, cnt[g[i][y]][i] ++;
					found = true;
				}
			}
		}
	}
	for (int i = 1; i <= 2*n; i++)
		for (int j = 1; j < i; j++)
			if (cnt[i][j] == 2)
				Answer(i,j);
}

Compilation message

chameleon.cpp: In function 'bool find(int, int, int, std::vector<int>&, bool)':
chameleon.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   if (Query(Q) == Q.size())
      |       ~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 32 ms 3704 KB Output is correct
4 Correct 32 ms 3704 KB Output is correct
5 Correct 32 ms 3704 KB Output is correct
6 Correct 33 ms 3704 KB Output is correct
7 Correct 33 ms 3704 KB Output is correct
8 Correct 32 ms 3704 KB Output is correct
9 Correct 32 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 1 ms 768 KB Output is correct
17 Correct 1 ms 768 KB Output is correct
18 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 55 ms 4344 KB Output is correct
4 Correct 58 ms 4348 KB Output is correct
5 Correct 60 ms 4344 KB Output is correct
6 Correct 55 ms 4344 KB Output is correct
7 Correct 56 ms 4344 KB Output is correct
8 Correct 57 ms 4344 KB Output is correct
9 Correct 55 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 32 ms 3704 KB Output is correct
4 Correct 32 ms 3704 KB Output is correct
5 Correct 32 ms 3704 KB Output is correct
6 Correct 33 ms 3704 KB Output is correct
7 Correct 33 ms 3704 KB Output is correct
8 Correct 32 ms 3704 KB Output is correct
9 Correct 32 ms 3712 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 768 KB Output is correct
20 Correct 1 ms 768 KB Output is correct
21 Correct 1 ms 768 KB Output is correct
22 Correct 1 ms 768 KB Output is correct
23 Correct 2 ms 768 KB Output is correct
24 Correct 1 ms 768 KB Output is correct
25 Correct 1 ms 768 KB Output is correct
26 Correct 1 ms 768 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 0 ms 384 KB Output is correct
30 Correct 55 ms 4344 KB Output is correct
31 Correct 58 ms 4348 KB Output is correct
32 Correct 60 ms 4344 KB Output is correct
33 Correct 55 ms 4344 KB Output is correct
34 Correct 56 ms 4344 KB Output is correct
35 Correct 57 ms 4344 KB Output is correct
36 Correct 55 ms 4344 KB Output is correct
37 Correct 61 ms 4348 KB Output is correct
38 Correct 32 ms 3704 KB Output is correct
39 Correct 63 ms 4344 KB Output is correct
40 Correct 61 ms 4344 KB Output is correct
41 Correct 61 ms 4344 KB Output is correct
42 Correct 32 ms 3736 KB Output is correct
43 Correct 55 ms 4344 KB Output is correct
44 Correct 64 ms 4472 KB Output is correct
45 Correct 61 ms 4344 KB Output is correct