Submission #709592

# Submission time Handle Problem Language Result Execution time Memory
709592 2023-03-14T00:35:35 Z vjudge1 Hotter Colder (IOI10_hottercolder) C++14
100 / 100
1053 ms 33228 KB
#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"
bool flg,rev;
i64 n;
int f[105][105][205],i,j,k,p;
i64 g[75];
int query(i64 t)
{
	if(rev) t=n-t+1;
	return Guess(t);
}
void init()
{
	flg=1;int i,j,k,p;
	memset(f,0x3f,sizeof(f));
	fz1(i,100)fz1(j,100)f[i][i][j]=0;
	fd1(i,100)fz(j,i+1,100)fz1(k,j*2){
		fz1(p,j*2)if(p!=k){
			int ml=(p+k+1)/2-1,mr=(p+k)/2+1,s=0;
			if(i<=ml) s=max(s,f[i][ml][p]);
			if(mr<=j) s=max(s,f[mr][j][p]);
			f[i][j][k]=min(f[i][j][k],s+1);
		}
	}
	fz1(i,100) g[f[1][i][i]]=i;
	fz(i,3,62){
		g[i]=max(g[i],g[i-2]+(1ll<<i));
	}
}
i64 solves(i64 l,i64 r,i64 k)
{
	if(l==r) return l;int p;
	fz1(p,r*2)if(p!=k){
		int ml=(p+k+1)/2-1,mr=(p+k)/2+1,s=0;
		if(l<=ml) s=max(s,f[l][ml][p]);
		if(mr<=r) s=max(s,f[mr][r][p]);
		if(f[l][r][k]==s+1) break;
	}
	int t=query(p);
	if(t==0) return (k+p)/2;
	int ml=(p+k+1)/2-1,mr=(p+k)/2+1;
	if((t==1)==(p<k)) return solves(l,ml,p); else return solves(mr,r,p);
}
i64 solveb(i64 l,i64 r,i64 k,bool flg=0,int ek=0x3f3f3f3f)
{
	if(l==r) return l;assert(ek);i64 p=l+r-k;
	if(flg) p=min(p,l*2);
	if(p==k){if(p<=(l+r)/2)p++; else p--;}
	i64 ml=(p+k+1)/2-1,mr=(p+k)/2+1;
	int t=query(p);
	if(t==0) return (k+p)/2;
	if((t==1)==(p<k)) return solveb(l,min(r,ml),p,0,ek-1); else return solveb(max(l,mr),r,p,0,ek-1);
}
i64 solvep(i64 n,int ek=0x3f3f3f3f)
{ 
	if(n<=100){assert(f[1][n][n]<=ek);return solves(1,n,n);}
	int k=2;while(g[k]<n)k++;assert(k<=ek);
	int t=query(g[k-2]-2);if(t==0) return (g[k-2]-2+n)/2;
	if(t==-1) return solveb((g[k-2]-2+n)/2+1,n,g[k-2]-2,1,k-1);
	t=query(g[k-2]);if(t==0) return g[k-2]-1;
	if(t==1){return solveb(g[k-2],(g[k-2]-1+n)/2-1,g[k-2],0,k-2);}
	return solvep(g[k-2],k-2);
}
int HC(int nn)
{
	if(nn==1) return 1;
	if(nn==2){Guess(1);if(Guess(2)==1)return 2;else return 1;}
	int ek=1;while((1ll<<(ek+1))<=nn*3)ek++; 
	if(!flg) init();
	n=nn;Guess(n/2);int t=Guess(n/2+1);i64 ans;
	if(t==1) rev=1,ans=solvep(n-n/2,ek-2);
	else rev=0,ans=solvep(n/2+1,ek-2);
	if(rev) ans=n-ans+1;return ans;
}

Compilation message

hottercolder.cpp: In function 'i64 solves(i64, i64, i64)':
hottercolder.cpp:70:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   70 |  if(l==r) return l;int p;
      |  ^~
hottercolder.cpp:70:20: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   70 |  if(l==r) return l;int p;
      |                    ^~~
hottercolder.cpp: In function 'int HC(int)':
hottercolder.cpp:111:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  111 |  if(rev) ans=n-ans+1;return ans;
      |  ^~
hottercolder.cpp:111:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  111 |  if(rev) ans=n-ans+1;return ans;
      |                      ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 435 ms 10132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 478 ms 10124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 443 ms 10132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 1053 ms 33228 KB Output is partially correct - alpha = 1.000000000000