답안 #470449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470449 2021-09-03T19:33:13 Z Namnamseo 카멜레온의 사랑 (JOI20_chameleon) C++17
100 / 100
59 ms 1412 KB
#include "chameleon.h"
#include <utility>
#include <vector>
using namespace std;
using vi=vector<int>;
using pp=pair<int,int>;
using pvi=pair<vi,vi>;
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(t) ((int)((t).size()))
const int maxn2 = int(1e3) + 10;

int n;

vector<pvi> v;
vi graph[maxn2];

bool Search(int i, vi &v, int l, int r, bool must=false) {
	if (l == r) return false;
	if (!must) {
		vi qry(v.begin()+l, v.begin()+r);
		qry.push_back(i);
		int qres = Query(qry);
		if (qres == sz(qry)) return false;
	}
	if (l+1 == r) {
		int j = v[l];
		graph[i].pb(j); graph[j].pb(i);
		return true;
	}
	int md = (l+r)/2;
	Search(i, v, md, r, !Search(i, v, l, md));
	return true;
}

void Rebuild(int p) {
	static bool vis[maxn2], col[maxn2];
	fill(vis+1, vis+p+1, 0);
	fill(col+1, col+p+1, 0);
	int vs = 0;
	for (int i=1; i<=p; ++i) if (!vis[i]) {
		static int q[maxn2], hd, tl;
		hd = 0; tl = 1; q[0] = i; vis[i] = true;
		if (sz(v) <= vs) v.resize(vs+1);
		v[vs].first.clear();
		v[vs].second.clear();
		while (hd < tl) {
			int x = q[hd++];
			(col[x]?v[vs].second:v[vs].first).push_back(x);
			for (int y:graph[x]) if (!vis[y]) {
				vis[y] = true;
				col[y] = !col[x];
				q[tl++] = y;
			}
		}
		++vs;
	}
	v.resize(vs);
}

void Solve(int N_) {
	n = N_;
	for (int i=1; i<=2*n; ++i) {
		static vi lefts, rights;
		lefts.clear(); rights.clear();
		for (auto &tmp : v) {
			if ((sz(tmp.first)<sz(tmp.second)) == (sz(lefts)<sz(rights)))
				swap(lefts, rights);
			lefts.insert(lefts.end(), all(tmp.first));
			rights.insert(rights.end(), all(tmp.second));
		}
		bool found = Search(i, lefts, 0, sz(lefts));
		found = Search(i, rights, 0, sz(rights)) || found;
		if (!found) v.push_back({{i}, {}});
		else Rebuild(i);
	}

	static bool is_directed[maxn2][maxn2];
	for (int i=1; i<=2*n; ++i) {
		if (sz(graph[i]) == 1) continue;
		int a = graph[i][0], b = graph[i][1], c = graph[i][2];
		if (is_directed[i][a] + is_directed[i][b] + is_directed[i][c] == 2) {
			continue;
		}
		int my_out = -1;
		if (!is_directed[i][c] && Query(vi{i, a, b}) == 1) my_out = c; else
		if (!is_directed[i][a] && Query(vi{i, b, c}) == 1) my_out = a; else
			my_out = b;
		is_directed[i][my_out] = true;
		is_directed[my_out][i] = true;
	}
	for (int i=1; i<=2*n; ++i) for (int j:graph[i]) {
		if (i<j && !is_directed[i][j]) {
			Answer(i, j);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 34 ms 424 KB Output is correct
4 Correct 34 ms 436 KB Output is correct
5 Correct 34 ms 448 KB Output is correct
6 Correct 40 ms 420 KB Output is correct
7 Correct 33 ms 424 KB Output is correct
8 Correct 34 ms 424 KB Output is correct
9 Correct 42 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 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 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 0 ms 328 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 0 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 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 432 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 0 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 54 ms 1344 KB Output is correct
4 Correct 52 ms 1344 KB Output is correct
5 Correct 48 ms 1328 KB Output is correct
6 Correct 53 ms 1324 KB Output is correct
7 Correct 50 ms 1332 KB Output is correct
8 Correct 48 ms 1332 KB Output is correct
9 Correct 46 ms 1312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 34 ms 424 KB Output is correct
4 Correct 34 ms 436 KB Output is correct
5 Correct 34 ms 448 KB Output is correct
6 Correct 40 ms 420 KB Output is correct
7 Correct 33 ms 424 KB Output is correct
8 Correct 34 ms 424 KB Output is correct
9 Correct 42 ms 328 KB Output is correct
10 Correct 0 ms 328 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 0 ms 328 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 0 ms 328 KB Output is correct
15 Correct 0 ms 328 KB Output is correct
16 Correct 0 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 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 432 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 0 ms 328 KB Output is correct
29 Correct 0 ms 328 KB Output is correct
30 Correct 54 ms 1344 KB Output is correct
31 Correct 52 ms 1344 KB Output is correct
32 Correct 48 ms 1328 KB Output is correct
33 Correct 53 ms 1324 KB Output is correct
34 Correct 50 ms 1332 KB Output is correct
35 Correct 48 ms 1332 KB Output is correct
36 Correct 46 ms 1312 KB Output is correct
37 Correct 48 ms 1296 KB Output is correct
38 Correct 33 ms 428 KB Output is correct
39 Correct 48 ms 1412 KB Output is correct
40 Correct 59 ms 1292 KB Output is correct
41 Correct 57 ms 1292 KB Output is correct
42 Correct 33 ms 328 KB Output is correct
43 Correct 47 ms 1312 KB Output is correct
44 Correct 49 ms 1296 KB Output is correct
45 Correct 49 ms 1344 KB Output is correct