답안 #838300

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838300 2023-08-26T13:26:13 Z MohamedAhmed04 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
48 ms 532 KB
#include <bits/stdc++.h>
#include "chameleon.h"

using namespace std ;

const int MAX = 1000 + 10 ;

int n ;
int mark[MAX] ;
vector<int>v[2] ;

vector< vector<int> >adj(MAX) ;

int query(int x , int t , int l , int r)
{
	vector<int>vq = {x} ;
	for(int i = l ; i <= r ; ++i)
		vq.push_back(v[t][i]) ;
	return Query(vq) ;
}

int vis[MAX] , col[MAX] ;

void dfs(int node)
{
	vis[node] = 1 ;
	v[col[node]].push_back(node) ;
	for(auto &child : adj[node])
	{
		if(vis[child])
			continue ;
		col[child] = !col[node] ;
		dfs(child) ;
	}
}

int ans[MAX] ;
int to[MAX] , prv[MAX] ;

void Solve(int N) 
{
	n = N ;
	for(int i = 1 ; i <= 2*n ; ++i)
	{
		for(int j = 0 ; j < 2 ; ++j)
		{
			int sz = v[j].size() , prv = -1 ;
			bool ok = (query(i , j , 0 , sz-1) == sz+1) ;
			while(!ok)
			{
				int l = prv+1 , r = sz-1 ;
				int idx = r ;
				while(l <= r)
				{
					int mid = (l + r) >> 1 ;
					if(query(i , j , prv+1 , mid) != mid-prv+1)
						idx = mid , r = mid-1 ;
					else
						l = mid+1 ;
				}
				adj[i].push_back(v[j][idx]) , adj[v[j][idx]].push_back(i) ;
				prv = idx ;
				ok = (query(i , j , idx+1 , sz-1) == sz-idx) ;
			}
		}
		v[0].clear() , v[1].clear() ;
		memset(vis , 0 , sizeof(vis)) ;
		for(int j = 1 ; j <= i ; ++j)
		{
			if(vis[j])
				continue ;
			col[j] = 0 ;
			dfs(j) ;
		}	
	}
	for(int i = 1 ; i <= 2*n ; ++i)
	{
		assert(adj[i].size() == 1 || adj[i].size() == 3) ;
		if(adj[i].size() == 1)
		{
			ans[i] = adj[i][0] , ans[adj[i][0]] = i ;
			continue ;
		}
		for(int j = 0 ; j < 3 ; ++j)
		{
			for(int k = j+1 ; k < 3 ; ++k)
			{
				vector<int>vq = {i , adj[i][j] , adj[i][k]} ;
				if(Query(vq) == 1)
				{
					int x = adj[i][3 ^ j ^ k] ;
					prv[i] = x , to[x] = i ;
				}
			}
		}
	}
	for(int i = 1 ; i <= 2*n ; ++i)
	{
		if(adj[i].size() != 3)
			continue ;
		for(int j = 0 ; j < 3 ; ++j)
		{
			int x = adj[i][j] ;
			if(to[i] != x && prv[i] != x)
				ans[i] = x , ans[x] = i ;
		}
	}
	for(int i = 1 ; i <= 2*n ; ++i)
	{
		if(ans[i] > i)
			Answer(i , ans[i]) ;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 18 ms 388 KB Output is correct
4 Correct 18 ms 336 KB Output is correct
5 Correct 19 ms 336 KB Output is correct
6 Correct 20 ms 336 KB Output is correct
7 Correct 20 ms 388 KB Output is correct
8 Correct 20 ms 336 KB Output is correct
9 Correct 19 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 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 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 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 0 ms 336 KB Output is correct
7 Correct 0 ms 336 KB Output is correct
8 Correct 0 ms 336 KB Output is correct
9 Correct 1 ms 368 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 40 ms 500 KB Output is correct
4 Correct 43 ms 396 KB Output is correct
5 Correct 40 ms 336 KB Output is correct
6 Correct 42 ms 532 KB Output is correct
7 Correct 42 ms 412 KB Output is correct
8 Correct 41 ms 336 KB Output is correct
9 Correct 44 ms 388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 18 ms 388 KB Output is correct
4 Correct 18 ms 336 KB Output is correct
5 Correct 19 ms 336 KB Output is correct
6 Correct 20 ms 336 KB Output is correct
7 Correct 20 ms 388 KB Output is correct
8 Correct 20 ms 336 KB Output is correct
9 Correct 19 ms 336 KB Output is correct
10 Correct 0 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 0 ms 336 KB Output is correct
14 Correct 0 ms 336 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 368 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 1 ms 336 KB Output is correct
29 Correct 0 ms 336 KB Output is correct
30 Correct 40 ms 500 KB Output is correct
31 Correct 43 ms 396 KB Output is correct
32 Correct 40 ms 336 KB Output is correct
33 Correct 42 ms 532 KB Output is correct
34 Correct 42 ms 412 KB Output is correct
35 Correct 41 ms 336 KB Output is correct
36 Correct 44 ms 388 KB Output is correct
37 Correct 42 ms 408 KB Output is correct
38 Correct 18 ms 336 KB Output is correct
39 Correct 42 ms 416 KB Output is correct
40 Correct 48 ms 524 KB Output is correct
41 Correct 42 ms 424 KB Output is correct
42 Correct 18 ms 388 KB Output is correct
43 Correct 42 ms 380 KB Output is correct
44 Correct 42 ms 336 KB Output is correct
45 Correct 47 ms 460 KB Output is correct