Submission #1020292

# Submission time Handle Problem Language Result Execution time Memory
1020292 2024-07-11T19:48:05 Z ttamx Chameleon's Love (JOI20_chameleon) C++17
100 / 100
45 ms 600 KB
#include "chameleon.h"
#include <bits/stdc++.h>

using namespace std;

void Solve(int n){
	auto check=[&](vector<int> &a,int l,int r,int u){
		vector<int> b{u};
		for(int i=l;i<=r;i++)b.emplace_back(a[i]);
		return Query(b)<b.size();
	};
	auto bsearch=[&](vector<int> &a,int st,int u){
		int l=st,r=a.size();
		while(l<r){
			int m=(l+r)/2;
			if(check(a,st,m,u))r=m;
			else l=m+1;
		}
		return l;
	};
	vector<vector<int>> adj(2*n+1);
	for(int i=2;i<=2*n;i++){
		vector<int> col(i);
		function<void(int,int)> dfs=[&](int u,int c){
			if(col[u])return;
			col[u]=c;
			for(auto v:adj[u])dfs(v,3-c);
		};
		for(int j=1;j<i;j++)dfs(j,1);
		vector<int> comp[2];
		for(int j=1;j<i;j++)comp[col[j]-1].emplace_back(j);
		for(int j=0;j<2;j++){
			int st=0;
			while(check(comp[j],st,comp[j].size()-1,i)){
				st=bsearch(comp[j],st,i);
				int u=comp[j][st];
				adj[i].emplace_back(u);
				adj[u].emplace_back(i);
				st++;
			}
		}
	}
	vector<int> ans(2*n+1),val(2*n+1);
	for(int i=1;i<=2*n;i++){
		if(adj[i].size()==1){
			ans[i]=adj[i][0];
			ans[adj[i][0]]=i;
		}else{
			for(auto x:adj[i])val[i]^=x;
			while(Query({i,adj[i][0],adj[i][1]})>1){
				rotate(adj[i].begin(),adj[i].begin()+1,adj[i].end());
			}
			val[i]^=adj[i][2];
			val[adj[i][2]]^=i;
		}
	}
	for(int i=1;i<=2*n;i++){
		if(!ans[i])ans[i]=val[i];
		if(i<ans[i])Answer(i,ans[i]);
	}
}

Compilation message

chameleon.cpp: In lambda function:
chameleon.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |   return Query(b)<b.size();
      |          ~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
4 Correct 20 ms 532 KB Output is correct
5 Correct 19 ms 344 KB Output is correct
6 Correct 20 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 20 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 34 ms 344 KB Output is correct
4 Correct 36 ms 344 KB Output is correct
5 Correct 43 ms 564 KB Output is correct
6 Correct 45 ms 344 KB Output is correct
7 Correct 34 ms 560 KB Output is correct
8 Correct 34 ms 600 KB Output is correct
9 Correct 34 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 19 ms 344 KB Output is correct
4 Correct 20 ms 532 KB Output is correct
5 Correct 19 ms 344 KB Output is correct
6 Correct 20 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 20 ms 528 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 34 ms 344 KB Output is correct
31 Correct 36 ms 344 KB Output is correct
32 Correct 43 ms 564 KB Output is correct
33 Correct 45 ms 344 KB Output is correct
34 Correct 34 ms 560 KB Output is correct
35 Correct 34 ms 600 KB Output is correct
36 Correct 34 ms 564 KB Output is correct
37 Correct 35 ms 344 KB Output is correct
38 Correct 20 ms 516 KB Output is correct
39 Correct 37 ms 344 KB Output is correct
40 Correct 35 ms 344 KB Output is correct
41 Correct 35 ms 344 KB Output is correct
42 Correct 20 ms 536 KB Output is correct
43 Correct 34 ms 528 KB Output is correct
44 Correct 42 ms 552 KB Output is correct
45 Correct 35 ms 344 KB Output is correct