This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "park.h"
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
#define maxn 1405
static int pl[1400];
ll n;
bool ok[maxn],use[maxn],lif[maxn];
ll deg[maxn];
vector<ll> dpt[maxn];
bool ask(ll x,ll y){
for(ll i = 0;i<n;i++) pl[i] = use[i];
pl[x] = pl[y] = 1;
//ceri(pl,0,n-1);
return Ask(x,y,pl);
}
void add(ll x,ll y){
if(x>y) swap(x,y);
//cerr<<"uv: "<<x<< " "<<y<<endl;
Answer(x,y);
}
ll get(ll x){
ll l = 0,r = n-1,mid,rez;
while(l<=r){
mid = (l+r)/2;
for(ll i = 0;i<n;i++) use[i] = ok[i];
for(ll i = 0;i<=mid;i++) use[i] = 1;
if(!ask(0,x)){
rez = mid;
l = mid+1;
}else r = mid-1;
}
rez++;
//cerr<<"get: "<<x<< " "<<rez<<endl;
return rez;
}
void reshi(ll x){
//here;
//ceri(ok,0,n-1);
//dbg(x);
for(ll i = 0;i<n;i++) use[i] = ok[i];
while(!ask(0,x)){
reshi(get(x));
for(ll i = 0;i<n;i++) use[i] = ok[i];
}
for(ll d = n-1;d>=0;d--){
ll l = 0,r = sz(dpt[d])-1,mid,rez = -1;
while(l<=r){
mid = (l+r)/2;
for(ll i = 0;i<n;i++) use[i] = ok[i];
for(ll i = 0;i<=mid;i++) use[dpt[d][i]] = 0;
if(!ask(0,x)){
rez = mid;
r = mid-1;
}else l = mid+1;
}
if(rez!=-1){
add(x,dpt[d][rez]);
dpt[d+1].pb(x);
ok[x] = 1;
return;
}
}
ll rez = 0,d = 0;
add(x,dpt[d][rez]);
dpt[d+1].pb(x);
ok[x] = 1;
}
void Detect(int T,int N){
n = N;
ok[0] = 1;
dpt[0].pb(0);
lif[0] = 1;
for(ll i = 1;i<n;i++) if(!ok[i]) reshi(i);
return;
}
/*
1
6
7
0 1
0 3
1 2
1 4
2 4
2 5
3 4
1
6
5
0 1
1 2
1 4
2 5
3 4
*/
Compilation message (stderr)
park.cpp: In function 'long long int get(long long int)':
park.cpp:53:8: warning: 'rez' may be used uninitialized in this function [-Wmaybe-uninitialized]
53 | rez++;
| ~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |