제출 #1145208

#제출 시각아이디문제언어결과실행 시간메모리
1145208LucaLucaMWorm Worries (BOI18_worm)C++20
59 / 100
365 ms412 KiB
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <random>
#include <algorithm>
#include <cassert>

int q;

int query(int x, int y, int z) {
  q--;
	printf("? %d %d %d\n", x, y, z);
	fflush(stdout);
	int ans = -1;
	(void)scanf("%d", &ans);
	if (ans == -1) exit(0);
	return ans;
}

__attribute__((noreturn))
void guess(int x, int y, int z) {
	printf("! %d %d %d\n", x, y, z);
	exit(0);
}

std::mt19937 rng(123);

struct Max {
  int x, y, z, value;
  bool operator < (const Max &other) const {
    return value < other.value;
  };
};

const int dx[6] = {+1, -1, 0, 0, 0, 0};
const int dy[6] = {0, 0, +1, -1, 0, 0};
const int dz[6] = {0, 0, 0, 0, +1, -1};

int main() {
  int n, m, k;
  std::cin >> n >> m >> k >> q;
  Max maxi;
  maxi.x = maxi.y = maxi.z = 1;
  maxi.value = query(1, 1, 1);

  int steps = q / 2;
  for (int i = 0; i < steps; i++) {
    int x = rng() % n + 1, y = rng() % m + 1, z  = rng() % k + 1;
    Max nw;
    nw.x = rng() % n + 1;
    nw.y = rng() % m + 1;
    nw.z = rng() % k + 1;
    nw.value = query(nw.x, nw.y, nw.z);
    maxi = std::max(maxi, nw);
  } 

  while (q > 0) {
    for (int i = 0; i < 6 && q > 0; i++) {
      Max nw = maxi;
      nw.x += dx[i];
      nw.y += dy[i];
      nw.z += dz[i];
      if (1 <= nw.x && nw.x <= n && 1 <= nw.y && nw.y <= m && 1 <= nw.z && nw.z <= k) {
        nw.value = query(nw.x, nw.y, nw.z);
        if (maxi < nw) {
          maxi = nw;
          break;
        }
      }
    }
  }

  std::cout << "! " << maxi.x << ' ' << maxi.y << ' ' << maxi.z << '\n';
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

worm.cpp: In function 'int query(int, int, int)':
worm.cpp:15:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         (void)scanf("%d", &ans);
      |               ~~~~~^~~~~~~~~~~~
#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...