답안 #212247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212247 2020-03-22T15:41:33 Z abacaba 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
67 ms 508 KB
#include <chameleon.h>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
constexpr int Q_MAX = 20'000;
constexpr int N_MAX = 515;
int n, cl[N_MAX << 1];
 
vector <int> g[N_MAX << 1];
vector <int> s[2];
 
void dfs(int v) {
	for(int to : g[v])
		if(!cl[to]) {
			cl[to] = 3 - cl[v];
			dfs(to);
		}
}
 
 
inline bool bad(vector <int> x, int r) {
	x.pb(r);
	return Query(x) != x.size();
}
 
int same_color[N_MAX << 1];
 
inline pii gt(int a, int b) {
	return mp(min(a, b), max(a, b));
}
 
set <pii> is;
 
int loves[N_MAX << 1];
 
void Solve(int N) {
	n = N;
	for(int i = 1; i <= 2 * n; ++i) {
		for(int j = 0; j < 2; ++j)
			s[j].clear();
		for(int j = 1; j < i; ++j)
			cl[j] = 0;
		for(int j = 1; j < i; ++j) {
			if(!cl[j]) {
				cl[j] = 1;
				dfs(j);
			}
			s[cl[j] - 1].pb(j);
		}
		for(int j = 0; j < 2; ++j) {
			vector <int> cur = s[j];
			while(bad(cur, i)) {
				int l = 0, r = (int)cur.size() - 1, res = -1;
				while(l <= r) {
					int mid = l + r >> 1;
					if(bad(vector <int> (cur.begin() + mid, cur.end()), i))
						l = mid + 1, res = mid;
					else
						r = mid - 1;
				}
				assert(res != -1);
				g[cur[res]].pb(i), g[i].pb(cur[res]);
				cur = vector <int> (cur.begin(), cur.begin() + res);
			}
		}
	}
	for(int i = 1; i <= 2 * n; ++i) {
		assert(g[i].size() == 1 || g[i].size() == 3);
		if(g[i].size() == 1)
			same_color[i] = g[i][0];
		else {
			for(int mask = 0; mask < 8; ++mask) {
				if(cntbit(mask) != 2)
					continue;
				vector <int> now = {i};
				for(int j = 0; j < 3; ++j)
					if(1 << j & mask)
						now.pb(g[i][j]);
				if(Query(now) == 1) {
					for(int j = 0; j < 3; ++j)
						if(!(1 << j & mask))
							loves[i] = g[i][j];
				}
			}
		}
	}
	for(int i = 1; i <= 2 * n; ++i) {
		if(g[i].size() == 1)
			is.insert(gt(i, same_color[i]));
		else {
			for(int j = 0; j < 3; ++j) {
				if(g[i][j] != loves[i] && loves[g[i][j]] != i) {
					same_color[g[i][j]] = i;
					same_color[i] = g[i][j];
				}
			}
		}
		is.insert(gt(same_color[i], i));
	}
	for(pii e : is)
		Answer(e.f, e.se);
}

Compilation message

chameleon.cpp: In function 'bool bad(std::vector<int>, int)':
chameleon.cpp:58:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return Query(x) != x.size();
         ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:90:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
      int mid = l + r >> 1;
                ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 36 ms 384 KB Output is correct
4 Correct 36 ms 444 KB Output is correct
5 Correct 37 ms 504 KB Output is correct
6 Correct 37 ms 508 KB Output is correct
7 Correct 36 ms 384 KB Output is correct
8 Correct 36 ms 384 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 61 ms 460 KB Output is correct
4 Correct 61 ms 432 KB Output is correct
5 Correct 67 ms 504 KB Output is correct
6 Correct 61 ms 504 KB Output is correct
7 Correct 64 ms 504 KB Output is correct
8 Correct 60 ms 504 KB Output is correct
9 Correct 61 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 36 ms 384 KB Output is correct
4 Correct 36 ms 444 KB Output is correct
5 Correct 37 ms 504 KB Output is correct
6 Correct 37 ms 508 KB Output is correct
7 Correct 36 ms 384 KB Output is correct
8 Correct 36 ms 384 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
17 Correct 4 ms 384 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 6 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 61 ms 460 KB Output is correct
31 Correct 61 ms 432 KB Output is correct
32 Correct 67 ms 504 KB Output is correct
33 Correct 61 ms 504 KB Output is correct
34 Correct 64 ms 504 KB Output is correct
35 Correct 60 ms 504 KB Output is correct
36 Correct 61 ms 504 KB Output is correct
37 Correct 61 ms 508 KB Output is correct
38 Correct 36 ms 384 KB Output is correct
39 Correct 62 ms 504 KB Output is correct
40 Correct 59 ms 504 KB Output is correct
41 Correct 61 ms 504 KB Output is correct
42 Correct 36 ms 384 KB Output is correct
43 Correct 60 ms 504 KB Output is correct
44 Correct 59 ms 504 KB Output is correct
45 Correct 62 ms 504 KB Output is correct