Submission #450410

#TimeUsernameProblemLanguageResultExecution timeMemory
450410nonsensenonsense1Worm Worries (BOI18_worm)C++17
32 / 100
1 ms220 KiB
#include <cstdio>
#include <algorithm>

int n, m, k, q;

int query(int x) 
{
	printf("? %d 1 1\n", x);
	fflush(stdout);
	scanf("%d", &x);
	return x;
}

int main() 
{
	scanf("%d%d%d%d", &n, &m, &k, &q);
	int l = 1, r = n, x = -1, xval, y = -1, yval;
	while (l < r) {
		if (x == -1) {
			x = (34 * l + 21 * r) / 55;
			if (y != -1) x = std::min(x, y - 1);
			if (!x) {
				++x;
				++y;
				yval = query(y);
			}
			xval = query(x);
		}
		if (y == -1) {
			y = (21 * l + 34 * r - 1) / 55 + 1;
			if (x != -1) y = std::max(y, x + 1);
			if (y == n + 1) {
				--x;
				--y;
				xval = query(x);
			}
			yval = query(y);
		}
		if (xval > yval) {
			r = y - 1;
			y = x;
			yval = xval;
			x = -1;
		}
		else {
			l = x + 1;
			x = y;
			xval = yval;
			y = -1;
		}
	}
	printf("! %d 1 1\n", l);
	return 0;
}

Compilation message (stderr)

worm.cpp: In function 'int query(int)':
worm.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%d", &x);
      |  ~~~~~^~~~~~~~~~
worm.cpp: In function 'int main()':
worm.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d%d%d%d", &n, &m, &k, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
worm.cpp:39:3: warning: 'yval' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |   if (xval > yval) {
      |   ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...