답안 #216055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216055 2020-03-26T16:56:01 Z _7_7_ 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
408 ms 22136 KB
#include "chameleon.h"                                      
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e3 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 333;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
 
 
 



int l[N], n;
vi v[2], g[N];
map < vi, int > was;
bool used[N], used1[N];


int query (vi v) {
	sort(all(v));
	if (was.count(v))
		return was[v];
	return was[v] = Query(v);
}



void ans (int x, int y) {
	assert(used[x] == used[y]);
	if (!used[x])
		Answer(x, y);
	used[x] = used[y] = 1;
}


void dfs (int vv, int cc = 0) {
	v[cc].pb(vv);
	used1[vv] = 1;

	for (auto to : g[vv])
		if (!used1[to])
			dfs(to, cc ^ 1);
}

void f (int i) {
	while (1) {
		v[0].pb(i);
		if (query(v[0]) == sz(v[0]))
			break;
		
		v[0].ppb();
		int l = 0, r = sz(v[0]) - 1, j = -1;
		while (l <= r) {
			int mid = (l + r) >> 1;
			
			vi tmp;
			for (int x = 0; x <= mid; ++x)					
				tmp.pb(v[0][x]);

			tmp.pb(i);
			
			if (query(tmp) != sz(tmp)) {
				j = mid;
				r = mid - 1;
			} else
				l = mid + 1;
		}

		g[i].pb(v[0][j]);
		g[v[0][j]].pb(i);

		swap(v[0][j], v[0][sz(v[0]) - 1]);
		v[0].ppb();		
	}
}

 
void Solve(int nn) {
	n = nn;
	for (int i = 1; i <= n + n; ++i) {
		f(i);
		swap(v[0], v[1]);
		f(i);

		v[0].clear();
		v[1].clear();
		memset(used1, 0, sizeof(used1));
		for (int j = 1; j <= i; ++j)
			if (!used1[j]) 
				dfs(j);
	}/*
	for (auto x : v[0])
		cerr << x << ' ';
	cerr << endl;
	for (auto x : v[1])
		cerr << x << ' ';
	cerr << endl;


	for (int i = 1; i <= n + n; ++i)
		for (auto j : g[i])
			cerr << i << ' ' << j << endl;*/


	for (int i = 1; i <= n + n; ++i)
		if (!used[i]) {
			assert(sz(g[i]) == 1 || sz(g[i]) == 3);

			if (sz(g[i]) == 1) 
				ans(i, g[i][0]);
			else {				
				for (int j = 0; j < 2; ++j) {
					vi tmp;
					tmp.pb(i);
					for (int jj = 0; jj < 3; ++jj)
						if (jj != j)
							tmp.pb(g[i][jj]);

					if (query(tmp) == 1) {
						l[i] = g[i][j]; 
						break;
					}
				}

				if (!l[i])         
					l[i] = g[i][2];
			}
		}

/*	for (int i = 1; i <= n + n; ++i)
		cerr << l[i] << endl;*/

	for (int i = 1; i <= n + n; ++i)
		if (!used[i]) {
			for (int j = 0; j < 3; ++j)
				if (g[i][j] == l[i]) {
					swap(g[i][j], g[i][2]);
					g[i].ppb();
					break;
				}

			assert(sz(g[i]) == 2);
			if (l[g[i][0]] == i || used[g[i][0]]) 
				ans(i, g[i][1]);
			else {
				assert(l[g[i][1]] == i || used[g[i][1]]);
				ans(i, g[i][0]);
			}
		}
			
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 121 ms 7928 KB Output is correct
4 Correct 122 ms 8076 KB Output is correct
5 Correct 124 ms 8056 KB Output is correct
6 Correct 124 ms 8004 KB Output is correct
7 Correct 124 ms 8056 KB Output is correct
8 Correct 121 ms 8056 KB Output is correct
9 Correct 140 ms 8144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 7 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 7 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 7 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 10 ms 640 KB Output is correct
17 Correct 7 ms 512 KB Output is correct
18 Correct 7 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 391 ms 21864 KB Output is correct
4 Correct 387 ms 21612 KB Output is correct
5 Correct 391 ms 21812 KB Output is correct
6 Correct 408 ms 21992 KB Output is correct
7 Correct 394 ms 21968 KB Output is correct
8 Correct 391 ms 21880 KB Output is correct
9 Correct 396 ms 22008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 121 ms 7928 KB Output is correct
4 Correct 122 ms 8076 KB Output is correct
5 Correct 124 ms 8056 KB Output is correct
6 Correct 124 ms 8004 KB Output is correct
7 Correct 124 ms 8056 KB Output is correct
8 Correct 121 ms 8056 KB Output is correct
9 Correct 140 ms 8144 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 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 5 ms 384 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 7 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 7 ms 512 KB Output is correct
22 Correct 7 ms 512 KB Output is correct
23 Correct 7 ms 512 KB Output is correct
24 Correct 6 ms 512 KB Output is correct
25 Correct 10 ms 640 KB Output is correct
26 Correct 7 ms 512 KB Output is correct
27 Correct 7 ms 512 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 391 ms 21864 KB Output is correct
31 Correct 387 ms 21612 KB Output is correct
32 Correct 391 ms 21812 KB Output is correct
33 Correct 408 ms 21992 KB Output is correct
34 Correct 394 ms 21968 KB Output is correct
35 Correct 391 ms 21880 KB Output is correct
36 Correct 396 ms 22008 KB Output is correct
37 Correct 296 ms 15996 KB Output is correct
38 Correct 126 ms 8060 KB Output is correct
39 Correct 284 ms 15608 KB Output is correct
40 Correct 284 ms 15480 KB Output is correct
41 Correct 284 ms 15736 KB Output is correct
42 Correct 131 ms 8056 KB Output is correct
43 Correct 398 ms 22136 KB Output is correct
44 Correct 291 ms 15864 KB Output is correct
45 Correct 290 ms 15736 KB Output is correct