#include "grader.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
int HC(int n){
//ofstream out("01.out");
//for(int i=1;i<=500;i++){for(int j=1;j<=i;j++) out<<i<<" "<<j<<endl;}
int l=1,r=n,ct=0,res=0;
vector<pair<int,int> >a;
while(l<=r){
//printf("%i %i\n",l,r);
if(r-l==2){
if(a.size() && a.back().se==r){
int x=Guess(l);
if(x==1) res=l;
else if(x==0) res=l+1;
else res=r;
}
else if(a.size() && a.back().se==l){
int x=Guess(r);
if(x==1) res=r;
else if(x==0) res=l+1;
else res=l;
}
else{
int x=Guess(l),y=Guess(r);
if(y==1) res=r;
else if(y==0) res=l+1;
else res=l;
}
break;
}
if(r-l==1){
if(a.size() && a.back().se==r){
a.pb({Guess(l),l});
if(a.back().fi==1) res=l;
else res=r;
}
else if(a.size() && a.back().se==l){
a.pb({Guess(r),r});
if(a.back().fi==1) res=r;
else res=l;
}
else{
int x=Guess(l),y=Guess(r);
if(y==1) res=r;
else res=l;
}
break;
}
if(l==r){res=l;break;}
int mid=l+r>>1;
if(ct%2==0){
a.pb({Guess(mid),mid});
a.pb({Guess(mid+1),mid+1});
if(a.back().fi==-1) r=mid;
else l=mid+1;
ct=1;
}
else{
if(a.back().se<=mid){
mid=r;
//printf("%i\n",mid);
a.pb({Guess(mid),mid});
if(a.back().fi==1) l=l+r+1>>1;
else r=l+r>>1;
}
else{
mid=l;
//printf("%i\n",mid);
a.pb({Guess(mid),mid});
if(a.back().fi==1) r=l+r+1>>1;
else l=l+r>>1;
}
ct=0;
}
}
return res;
}
Compilation message
hottercolder.cpp: In function 'int HC(int)':
hottercolder.cpp:30:9: warning: unused variable 'x' [-Wunused-variable]
30 | int x=Guess(l),y=Guess(r);
| ^
hottercolder.cpp:49:9: warning: unused variable 'x' [-Wunused-variable]
49 | int x=Guess(l),y=Guess(r);
| ^
hottercolder.cpp:56:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
56 | int mid=l+r>>1;
| ~^~
hottercolder.cpp:69:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | if(a.back().fi==1) l=l+r+1>>1;
| ~~~^~
hottercolder.cpp:70:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | else r=l+r>>1;
| ~^~
hottercolder.cpp:76:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
76 | if(a.back().fi==1) r=l+r+1>>1;
| ~~~^~
hottercolder.cpp:77:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
77 | else l=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
778 ms |
24512 KB |
Output is partially correct - alpha = 0.333333333333 |