Submission #944406

# Submission time Handle Problem Language Result Execution time Memory
944406 2024-03-12T17:04:35 Z MilosMilutinovic Chameleon's Love (JOI20_chameleon) C++14
100 / 100
44 ms 768 KB
#include "chameleon.h"
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
 
namespace {
	int c[1005][1005],nxt[1005],dep[1005];
	vector<int> g[1005];
	bool done[1005];
}
 
void dfs(int x){
	if(dep[x]==-1) dep[x]=0;
	for(int y:g[x]){
		if(dep[y]!=-1){
			assert(dep[y]!=dep[x]);
			continue;
		}
		dep[y]=(dep[x]+1)%2;
		dfs(y);
	}
}
 
bool Ok(vector<int> v,int i){
	if(v.empty()) return false;
	v.pb(i);
	return Query(v)!=v.size();
}
 
void Solve(int n){
	for(int i=1;i<=2*n;i++){
		for(int j=1;j<=2*n;j++) dep[j]=-1;
		for(int j=1;j<i;j++) if(dep[j]==-1) dfs(j);
		vector<int> a,b;
		for(int j=1;j<i;j++) (dep[j]==0?a:b).pb(j);
		for(int iter=1;iter<=3;iter++){
			vector<int> na,nb;
			for(int x:a){
				bool ok=false;
				for(int y:g[i]) if(x==y) ok=true;
				if(!ok) na.pb(x);
			}
			for(int x:b){
				bool ok=false;
				for(int y:g[i]) if(x==y) ok=true;
				if(!ok) nb.pb(x);
			}
			a=na;
			b=nb;
			if(Ok(a,i)){
				int l=0,r=(int)a.size()-1,p=-1;
				while(l<=r){
					int mid=(l+r)/2;
					vector<int> qv(1,i);
					for(int j=0;j<=mid;j++) qv.pb(a[j]);
					if(Query(qv)!=(int)qv.size()) p=mid,r=mid-1;
					else l=mid+1;
				}
				if(p!=-1){
					g[i].pb(a[p]);
					g[a[p]].pb(i);
				}else a.clear();
			}else a.clear();
          if(Ok(b,i)){
				int l=0,r=(int)b.size()-1,p=-1;
				while(l<=r){
					int mid=(l+r)/2;
					vector<int> qv(1,i);
					for(int j=0;j<=mid;j++) qv.pb(b[j]);
					if(Query(qv)!=(int)qv.size()) p=mid,r=mid-1;
					else l=mid+1;
				}
				if(p!=-1){
					g[i].pb(b[p]);
					g[b[p]].pb(i);
				}else b.clear();
			}else b.clear(); 
        }
	}
	vector<pii> res;
	for(int i=1;i<=2*n;i++){
		sort(g[i].begin(),g[i].end());
		g[i].erase(unique(g[i].begin(),g[i].end()),g[i].end());
		int sz=(int)g[i].size();
		if(sz==3){
			for(int x=0;x<3;x++){
				vector<int> qv={i};
				for(int y=0;y<3;y++) if(y!=x) qv.pb(g[i][y]);
				if(Query(qv)==1){
					nxt[i]=g[i][x];
					break;
				}
			}
		}else{
			done[i]=true;
			res.pb(mp(min(i,g[i][0]),max(i,g[i][0])));
		}
	}
	for(int i=1;i<=2*n;i++){
		if(done[i]) continue;
		vector<int> cyc;
		cyc.pb(i);
		int ver=i;
		while(!done[ver]) cyc.pb(ver),done[ver]=true,ver=nxt[ver];
		for(int v:cyc){
			for(int x:g[v]){
				if(x!=nxt[v]&&nxt[x]!=v){
					res.pb(mp(min(v,x),max(v,x)));
				}
			}
		}
	}
	sort(res.begin(),res.end());
	res.erase(unique(res.begin(),res.end()),res.end());
	for(auto&p:res) Answer(p.fi,p.se);
}

Compilation message

chameleon.cpp: In function 'bool Ok(std::vector<int>, int)':
chameleon.cpp:48:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  return Query(v)!=v.size();
      |         ~~~~~~~~^~~~~~~~~~
chameleon.cpp: At global scope:
chameleon.cpp:28:6: warning: '{anonymous}::c' defined but not used [-Wunused-variable]
   28 |  int c[1005][1005],nxt[1005],dep[1005];
      |      ^
# 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 20 ms 552 KB Output is correct
4 Correct 30 ms 344 KB Output is correct
5 Correct 20 ms 344 KB Output is correct
6 Correct 21 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 20 ms 344 KB Output is correct
9 Correct 20 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
# 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 44 ms 572 KB Output is correct
4 Correct 44 ms 344 KB Output is correct
5 Correct 44 ms 768 KB Output is correct
6 Correct 44 ms 344 KB Output is correct
7 Correct 44 ms 564 KB Output is correct
8 Correct 44 ms 344 KB Output is correct
9 Correct 44 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 20 ms 552 KB Output is correct
4 Correct 30 ms 344 KB Output is correct
5 Correct 20 ms 344 KB Output is correct
6 Correct 21 ms 344 KB Output is correct
7 Correct 20 ms 344 KB Output is correct
8 Correct 20 ms 344 KB Output is correct
9 Correct 20 ms 344 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 44 ms 572 KB Output is correct
31 Correct 44 ms 344 KB Output is correct
32 Correct 44 ms 768 KB Output is correct
33 Correct 44 ms 344 KB Output is correct
34 Correct 44 ms 564 KB Output is correct
35 Correct 44 ms 344 KB Output is correct
36 Correct 44 ms 344 KB Output is correct
37 Correct 40 ms 344 KB Output is correct
38 Correct 20 ms 540 KB Output is correct
39 Correct 41 ms 584 KB Output is correct
40 Correct 43 ms 600 KB Output is correct
41 Correct 40 ms 572 KB Output is correct
42 Correct 20 ms 344 KB Output is correct
43 Correct 44 ms 572 KB Output is correct
44 Correct 40 ms 344 KB Output is correct
45 Correct 40 ms 564 KB Output is correct