#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<cassert>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(((long long)(n))-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
//#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define pb push_back
#define mk make_pair
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
typedef long long i64;
typedef long double f80;
typedef unsigned int u32;
typedef unsigned long long u64;
#include "grader.h"
i64 n;
i64 solve(i64 l,i64 r,i64 k)
{
if(l==r) return l;i64 md=(l+r)/2;
if(l<=3&&n-r>3) md=(l+l+r)/3;
if(n-r<=3&&l>3) md=(l+r+r)/3;
i64 p=md*2-k;p=max(1ll,p);p=min(n,p);
if(p==k){if(p<=(l+r)/2)p++; else p--;}
i64 ml=(p+k+1)/2-1,mr=(p+k)/2+1;
if(ml-l+1<(r-l+1)/4-2||r-mr+1<(r-l+1)/4-2) p=md,ml=(p+k+1)/2-1,mr=(p+k)/2+1;
int t=Guess(p);
if(t==0) return (k+p)/2;
if((t==1)==(p<k)) return solve(l,min(r,ml),p); else return solve(max(l,mr),r,p);
}
int cal(int n) {
return n < 5 ? 1 : (n + 1 >> 1) - cal(n >> 1);
}
int std_(int N){
int L = 1, R = N, prv, nxt, t, W = log(3 * N) / log(2);
while (L < R) {
if (R == 2) {
Guess(1);
return Guess(2) < 0 ? 1 : 2;
}
int cut = W & 1 ? (2 << W - 2) / 3 + 1 : (2 << W - 2) / 3 + 2;
nxt = R == N ? cut + cal(R - cut) : cut + cut - 1;
prv = cut + cut - nxt;
Guess(prv);
t = Guess(nxt);
if (t == -1) R = prv + nxt - 1 >> 1;
if (t == 0) return prv + nxt >> 1;
if (t == 1) {
L = prv + nxt + 2 >> 1;
prv = nxt;
while (L < R) {
nxt = (L + R >> 1 << 1) - prv;
if (nxt == prv) nxt++;
if (nxt < 1) nxt = 1;
if (nxt > N) nxt = N;
t = Guess(nxt);
if (t == -1) {
if (prv < nxt) R = nxt + prv - 1 >> 1;
else L = nxt + prv + 2 >> 1;
}
if (t == 0) return nxt + prv >> 1;
if (t == 1) {
if (prv < nxt) L = nxt + prv + 2 >> 1;
else R = nxt + prv - 1 >> 1;
}
prv = nxt;
}
}
W -= 2;
}
return L;
}
int HC(int nn)
{
if(nn<500) return std_(nn);
n=nn;Guess(1);return solve(1,n,1);
}
Compilation message
hottercolder.cpp: In function 'i64 solve(i64, i64, i64)':
hottercolder.cpp:44:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
44 | if(l==r) return l;i64 md=(l+r)/2;
| ^~
hottercolder.cpp:44:20: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
44 | if(l==r) return l;i64 md=(l+r)/2;
| ^~~
hottercolder.cpp: In function 'int cal(int)':
hottercolder.cpp:57:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
57 | return n < 5 ? 1 : (n + 1 >> 1) - cal(n >> 1);
| ~~^~~
hottercolder.cpp: In function 'int std_(int)':
hottercolder.cpp:66:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
66 | int cut = W & 1 ? (2 << W - 2) / 3 + 1 : (2 << W - 2) / 3 + 2;
| ~~^~~
hottercolder.cpp:66:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
66 | int cut = W & 1 ? (2 << W - 2) / 3 + 1 : (2 << W - 2) / 3 + 2;
| ~~^~~
hottercolder.cpp:71:32: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
71 | if (t == -1) R = prv + nxt - 1 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:72:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
72 | if (t == 0) return prv + nxt >> 1;
| ~~~~^~~~~
hottercolder.cpp:74:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
74 | L = prv + nxt + 2 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:77:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
77 | nxt = (L + R >> 1 << 1) - prv;
| ~~^~~
hottercolder.cpp:83:40: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
83 | if (prv < nxt) R = nxt + prv - 1 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:84:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
84 | else L = nxt + prv + 2 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:86:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
86 | if (t == 0) return nxt + prv >> 1;
| ~~~~^~~~~
hottercolder.cpp:88:40: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
88 | if (prv < nxt) L = nxt + prv + 2 >> 1;
| ~~~~~~~~~~^~~
hottercolder.cpp:89:30: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
89 | else R = nxt + prv - 1 >> 1;
| ~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
580 ms |
8252 KB |
Output is partially correct - alpha = 0.800000000000 |