답안 #433556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433556 2021-06-20T06:18:51 Z Kevin_Zhang_TW 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
110 ms 572 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
#include "chameleon.h"
#include <vector>

namespace {

const int MAX_N = 1010;

int qcnt;
int qry(vector<int> p) { for (int &i : p) ++i; ++qcnt; return Query(p);  }

int n, love[MAX_N];
vector<int> edge[MAX_N];
void ans(int a, int b) { ++a, ++b; if (a > b) return; Answer(a, b); }

void add_edge(int a, int b) {
	edge[a].pb(b), edge[b].pb(a);
}

void find(int x, vector<int> g) {
	auto gen_vec = [&](int id) {
		vector<int> ret(begin(g), begin(g)+id+1);
		ret.pb(x);
		return ret;
	};
	if (g.empty()) return;

	for (int i = 0;i < 3;++i) {
		auto vec = gen_vec(g.size()-1);
		if (qry(vec) == vec.size()) break;
		int l = 0, r = g.size()-1, mid;
		while (l < r) {
			mid = l + r >> 1;
			auto vec = gen_vec(mid);
			if (qry(vec) == vec.size())
				l = mid+1;
			else
				r = mid;
		}
		int y = g[l];
		add_edge(x, y);
		g.erase(begin(g)+l);
	}
}

vector<int> part[2];
bool vis[MAX_N];
void dfs(int x, int c) {
	if (vis[x]) return;
	part[c].pb(x);
	vis[x] = true;
	for (int u : edge[x])
		dfs(u, c^1);
}

void init_lr(int m) {
	part[0] = part[1] = vector<int>();

	memset(vis, 0, sizeof(vis));

	for (int i = 0;i < m;++i) {
		if (!vis[i]) dfs(i, 0);
	}
}
void make_edge() {
	for (int i = 0;i < n + n;++i) {
		init_lr(i);
		find(i, part[0]);
		find(i, part[1]);
	}

//	for (int i = 0;i < n + n;++i) {
//		one.pb(i);
//		if (qry(one) != one.size()) {
//			one.pop_back();
//			two.pb(i);
//		}
//	}

//	assert(one.size() == n && two.size() == n);
//
//	for (int i = 0;i < n;++i) {
//		int oc = qcnt;
//		find(one[i], two);
//		int use = qcnt - oc;
//		DE(i, use, edge[ one[i] ].size());
//		debug(AI( edge[ one[i] ]));
//	}
}

}


void Solve(int N) {
	n = N;
	fill(love, love + n + n, -1);

	make_edge();


	for (int i = 0;i < n + n;++i) {
		assert(edge[i].size() == 1 || edge[i].size() == 3);
		if (edge[i].size() == 1) continue;

		int cnt = 0;
		for (int j = 0;j < 3;++j) {
			vector<int> p {i};
			for (int k = 0;k < 3;++k) if (j != k) p.pb( edge[i][k] );
			if (qry(p) == 1) {
				love[ i ] = edge[i][j];
				++cnt;
			}
		}
		assert(cnt == 1);
	}

	for (int i = 0;i < n + n;++i) {
		for (int j = 0;j < edge[i].size();++j) {
			if (love[i] != edge[i][j] && love[ edge[i][j] ] != i)
				ans(i, edge[i][j]);
		}
	}

}

Compilation message

chameleon.cpp: In function 'void {anonymous}::find(int, std::vector<int>)':
chameleon.cpp:45:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   if (qry(vec) == vec.size()) break;
      |       ~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:48:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |    mid = l + r >> 1;
      |          ~~^~~
chameleon.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    if (qry(vec) == vec.size())
      |        ~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:133:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |   for (int j = 0;j < edge[i].size();++j) {
      |                  ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 36 ms 328 KB Output is correct
4 Correct 42 ms 536 KB Output is correct
5 Correct 42 ms 424 KB Output is correct
6 Correct 36 ms 416 KB Output is correct
7 Correct 36 ms 428 KB Output is correct
8 Correct 36 ms 416 KB Output is correct
9 Correct 36 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 0 ms 328 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 2 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 2 ms 328 KB Output is correct
14 Correct 2 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 87 ms 432 KB Output is correct
4 Correct 93 ms 428 KB Output is correct
5 Correct 94 ms 444 KB Output is correct
6 Correct 87 ms 420 KB Output is correct
7 Correct 89 ms 428 KB Output is correct
8 Correct 87 ms 464 KB Output is correct
9 Correct 110 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 36 ms 328 KB Output is correct
4 Correct 42 ms 536 KB Output is correct
5 Correct 42 ms 424 KB Output is correct
6 Correct 36 ms 416 KB Output is correct
7 Correct 36 ms 428 KB Output is correct
8 Correct 36 ms 416 KB Output is correct
9 Correct 36 ms 420 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 2 ms 328 KB Output is correct
20 Correct 2 ms 328 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 2 ms 328 KB Output is correct
23 Correct 2 ms 328 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 328 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 87 ms 432 KB Output is correct
31 Correct 93 ms 428 KB Output is correct
32 Correct 94 ms 444 KB Output is correct
33 Correct 87 ms 420 KB Output is correct
34 Correct 89 ms 428 KB Output is correct
35 Correct 87 ms 464 KB Output is correct
36 Correct 110 ms 416 KB Output is correct
37 Correct 83 ms 428 KB Output is correct
38 Correct 35 ms 328 KB Output is correct
39 Correct 87 ms 572 KB Output is correct
40 Correct 94 ms 448 KB Output is correct
41 Correct 84 ms 448 KB Output is correct
42 Correct 35 ms 420 KB Output is correct
43 Correct 88 ms 536 KB Output is correct
44 Correct 83 ms 448 KB Output is correct
45 Correct 88 ms 564 KB Output is correct