//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "chameleon.h"
namespace {
vector <int> edge[55];
bool vis[55];
vector <int> hi;
int n;
} // namespace
vector <int> getprefix(int x) {
vector <int> ret;
rep(i,0,x+1) ret.pb(hi[i]);
return ret;
}
void solve() {
rep(i,1,2*n+1) hi.pb(i);
while (!hi.empty()) {
int l = 0,r = SZ(hi)-1;
while (l<r) {
int mid=l+r>>1;
if (Query(getprefix(mid))==mid+1) l = mid+1; //the prefix are all of different color
else r = mid;
}
int cur = l;
debug(cur);
l = 0,r = cur-1;
while (l<r) {
int mid=l+r>>1;
vector <int> tmp = getprefix(mid);
tmp.pb(hi[cur]);
if (Query(tmp)==mid+1) r = mid;
else l = mid+1;
}
Answer(hi[cur],hi[l]);
hi.erase(hi.begin()+cur);
hi.erase(hi.begin()+l);
}
}
void Solve(int N) {
n =N;
if (N>50) {
solve();
return;
}
rep(i,1,2*N+1)
rep(j,1,i) {
int cnt = Query({i,j});
if (cnt==1) edge[i].pb(j),edge[j].pb(i);
}
rep(i,1,2*N+1) {
if (SZ(edge[i])==3) {
int x = edge[i][0], y = edge[i][1], z = edge[i][2];
if (Query({i,x,y})==1) edge[i] = {x,y};
else if (Query({i,x,z})==1) edge[i] = {x,z};
else {
// assert(Query({i,y,z})==1);
edge[i] = {y,z};
}
}
}
rep(i,1,2*N+1) {
if (vis[i]) continue;
if (SZ(edge[i])==1) {
Answer(i,edge[i][0]);
vis[i] = vis[edge[i][0]] = 1;
}
else {
assert(SZ(edge[i])==2);
int x = edge[i][0], y = edge[i][1];
if (vis[y] or SZ(edge[x])==1) {
Answer(i,x);
vis[i] = vis[x] = 1;
}
else if (vis[x] or SZ(edge[y])==1) {
Answer(i,y);
vis[i] = vis[y] = 1;
}
else {
if (edge[x][0]==i or edge[x][1]==i) Answer(i,x),vis[i]=vis[x]=1;
else assert(edge[y][0]==i or edge[y][1]==i),Answer(i,y),vis[i]=vis[y]=1;
}
}
}
return;
}
Compilation message
chameleon.cpp: In function 'void solve()':
chameleon.cpp:46:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int mid=l+r>>1;
| ~^~
chameleon.cpp:54:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
54 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
24 ms |
320 KB |
Output is correct |
4 |
Correct |
23 ms |
208 KB |
Output is correct |
5 |
Correct |
23 ms |
328 KB |
Output is correct |
6 |
Correct |
22 ms |
208 KB |
Output is correct |
7 |
Correct |
22 ms |
208 KB |
Output is correct |
8 |
Correct |
23 ms |
328 KB |
Output is correct |
9 |
Correct |
24 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [5] |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
24 ms |
320 KB |
Output is correct |
4 |
Correct |
23 ms |
208 KB |
Output is correct |
5 |
Correct |
23 ms |
328 KB |
Output is correct |
6 |
Correct |
22 ms |
208 KB |
Output is correct |
7 |
Correct |
22 ms |
208 KB |
Output is correct |
8 |
Correct |
23 ms |
328 KB |
Output is correct |
9 |
Correct |
24 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [5] |
20 |
Halted |
0 ms |
0 KB |
- |