Submission #799823

# Submission time Handle Problem Language Result Execution time Memory
799823 2023-08-01T05:34:20 Z 박상훈(#10082) Chameleon's Love (JOI20_chameleon) C++17
100 / 100
34 ms 416 KB
#include "chameleon.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

namespace {

int n;

vector<pair<int, int>> adj[1010];

vector<int> operator + (const vector<int> &x, const vector<int> &y){
	vector<int> ret = x;
	for (auto &_:y) ret.push_back(_);
	return ret;
}

vector<int> operator - (const vector<int> &x, const vector<int> &y){
	vector<int> ret = x;
	for (auto &_:y){
		auto iter = find(ret.begin(), ret.end(), _);
		// assert(iter!=ret.end());
		if (iter==ret.end()) continue;
		ret.erase(iter);
	} 
	return ret;
}

vector<int> cut (const vector<int> &x, int l, int r){
	vector<int> ret;
	for (int i=l;i<=r;i++) ret.push_back(x[i]);
	return ret;
}

void erase(int x, int y){
	auto iter1 = find(adj[x].begin(), adj[x].end(), pair<int, int>(y, 0));
	auto iter2 = find(adj[y].begin(), adj[y].end(), pair<int, int>(x, 0));

	assert(iter1!=adj[x].end());
	assert(iter2!=adj[y].end());

	iter1->second = 1;
	iter2->second = 1;
}

}  // namespace

void Solve(int N) {
	n = N*2;
	
	vector<vector<int>> C;
	vector<int> chk(n+1, 0);
	int cnt = 0;

	while(cnt < n){
		C.emplace_back();
		assert(C.size() <= 4);

		for (int i=1;i<=n;i++) if (!chk[i]){
			C.back().push_back(i);
			if (Query(C.back()) != (int)C.back().size()) {C.back().pop_back(); continue;}

			chk[i] = 1;
			cnt++;
		}
	}

	// printf("ok1\n");

	for (int ci=0;ci<(int)C.size();ci++){
		for (int cj=ci+1;cj<(int)C.size();cj++){
			for (auto &x:C[ci]){
				vector<int> fuck;

				while(true){
					if (Query(C[cj] + vector<int>{x} - fuck) == (int)C[cj].size() - (int)fuck.size() + 1) break;
					
					int l = 0, r = (int)C[cj].size()-1;
					while(l<r){
						int m = (l+r)>>1;
						auto V = cut(C[cj], l, m) + vector<int>{x} - fuck;
						if (Query(V) < (int)V.size()) r = m;
						else l = m+1;
					}

					int ans = C[cj][l];
					adj[x].emplace_back(ans, 0);
					adj[ans].emplace_back(x, 0);

					// printf("ok push %d %d / l = %d / size = %d\n", x, ans, l, (int)C[cj].size());
					// assert(Query({x, ans})==1);

					fuck.push_back(ans);
				}
				

				
			}
		}
	}

	for (int i=1;i<=n;i++) if (adj[i].size() > 1){
		assert(adj[i].size()==3);
		if (Query({adj[i][0].first, adj[i][1].first, i}) == 1) erase(i, adj[i][2].first);
		else if (Query({adj[i][0].first, adj[i][2].first, i}) == 1) erase(i, adj[i][1].first);
		else erase(i, adj[i][0].first);
	}

	for (int i=1;i<=n;i++){
		int ans = -1;
		for (auto &[x, y]:adj[i]) if (y==0) ans = x;
		assert(ans != -1);

		if (i < ans) Answer(i, ans);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 14 ms 368 KB Output is correct
4 Correct 12 ms 380 KB Output is correct
5 Correct 12 ms 336 KB Output is correct
6 Correct 12 ms 392 KB Output is correct
7 Correct 12 ms 376 KB Output is correct
8 Correct 16 ms 360 KB Output is correct
9 Correct 15 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 27 ms 356 KB Output is correct
4 Correct 29 ms 392 KB Output is correct
5 Correct 27 ms 372 KB Output is correct
6 Correct 33 ms 364 KB Output is correct
7 Correct 26 ms 416 KB Output is correct
8 Correct 27 ms 380 KB Output is correct
9 Correct 29 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 14 ms 368 KB Output is correct
4 Correct 12 ms 380 KB Output is correct
5 Correct 12 ms 336 KB Output is correct
6 Correct 12 ms 392 KB Output is correct
7 Correct 12 ms 376 KB Output is correct
8 Correct 16 ms 360 KB Output is correct
9 Correct 15 ms 336 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 0 ms 336 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 0 ms 336 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 27 ms 356 KB Output is correct
31 Correct 29 ms 392 KB Output is correct
32 Correct 27 ms 372 KB Output is correct
33 Correct 33 ms 364 KB Output is correct
34 Correct 26 ms 416 KB Output is correct
35 Correct 27 ms 380 KB Output is correct
36 Correct 29 ms 388 KB Output is correct
37 Correct 25 ms 388 KB Output is correct
38 Correct 12 ms 360 KB Output is correct
39 Correct 31 ms 392 KB Output is correct
40 Correct 25 ms 364 KB Output is correct
41 Correct 25 ms 392 KB Output is correct
42 Correct 12 ms 388 KB Output is correct
43 Correct 28 ms 400 KB Output is correct
44 Correct 24 ms 384 KB Output is correct
45 Correct 34 ms 368 KB Output is correct