Submission #356773

# Submission time Handle Problem Language Result Execution time Memory
356773 2021-01-23T16:21:33 Z Mefarnis Hotter Colder (IOI10_hottercolder) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;

int l,r,last,guess;

void guessL() {
	guess = Guess(l);
	last = l;
	if(guess == 0)
		return mid;
	if((l+r)%2 == 0) {
		if(guess == 1)
			r = mid-1;
		else
			l = mid+1;
	}
	else {
		if(guess == 1)
			r = mid;
		else
			l = mid+1;
	}
}

void guessR() {
	guess = Guess(r);
	last = r;
	if(guess == 0)
		return mid;
	if((l+r)%2 == 0) {
		if(guess == -1)
			r = mid-1;
		else
			l = mid+1;
	}
	else {
		if(guess == -1)
			r = mid;
		else
			l = mid+1;
	}
}

int HC(int n) {
	srand(time(NULL));
	l = 1 , r = n;
	last = -1 , guess = -1;
	while(l < r) {
		int mid = (l+r) >> 1;
		if(guess == 1) {
			if(last == l)
				guessR();
			else
				guessL();
		}
		else {
			if(rand()%2 == 0) {
				Guess(l);
				guessR();
			}
			else {
				Guess(r);
				guessL();
			}
		}
	}
	return l;
}

Compilation message

hottercolder.cpp: In function 'void guessL()':
hottercolder.cpp:11:10: error: 'mid' was not declared in this scope
   11 |   return mid;
      |          ^~~
hottercolder.cpp:11:10: error: return-statement with a value, in function returning 'void' [-fpermissive]
hottercolder.cpp:14:8: error: 'mid' was not declared in this scope
   14 |    r = mid-1;
      |        ^~~
hottercolder.cpp:16:8: error: 'mid' was not declared in this scope
   16 |    l = mid+1;
      |        ^~~
hottercolder.cpp:20:8: error: 'mid' was not declared in this scope
   20 |    r = mid;
      |        ^~~
hottercolder.cpp:22:8: error: 'mid' was not declared in this scope
   22 |    l = mid+1;
      |        ^~~
hottercolder.cpp: In function 'void guessR()':
hottercolder.cpp:30:10: error: 'mid' was not declared in this scope
   30 |   return mid;
      |          ^~~
hottercolder.cpp:30:10: error: return-statement with a value, in function returning 'void' [-fpermissive]
hottercolder.cpp:33:8: error: 'mid' was not declared in this scope
   33 |    r = mid-1;
      |        ^~~
hottercolder.cpp:35:8: error: 'mid' was not declared in this scope
   35 |    l = mid+1;
      |        ^~~
hottercolder.cpp:39:8: error: 'mid' was not declared in this scope
   39 |    r = mid;
      |        ^~~
hottercolder.cpp:41:8: error: 'mid' was not declared in this scope
   41 |    l = mid+1;
      |        ^~~
hottercolder.cpp: In function 'int HC(int)':
hottercolder.cpp:50:7: warning: unused variable 'mid' [-Wunused-variable]
   50 |   int mid = (l+r) >> 1;
      |       ^~~