結果

問題 No.594 壊れた宝物発見機
ユーザー tkmst201tkmst201
提出日時 2021-02-19 10:01:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,454 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 193,292 KB
最終ジャッジ日時 2025-01-18 22:45:58
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |                 scanf("%d", &D);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	auto query = [](int X, int Y, int Z) -> int {
		printf("? %d %d %d\n", X, Y, Z);
		fflush(stdout);
		int D;
		scanf("%d", &D);
		if (D == -1) assert(false);
		return D;
	};
	
	int l[3] {}, r[3] {};
	REP(i, 3) {
		l[i] = -102;
		r[i] = 102;
		int lv = -1, rv = -1;
		auto q = [&](int x) {
			int arg[3];
			REP(j, 3) arg[j] = i == j ? x : l[j];
			return query(arg[0], arg[1], arg[2]);
		};
		while (r[i] - l[i] > 2) {
			const int m1 = (2 * l[i] + r[i]) / 3, m2 = (l[i] + 2 * r[i]) / 3;
			const int y1 = q(m1), y2 = q(m2);
			if (y1 < y2) r[i] = m2, rv = y2;
			else l[i] = m1, lv = y1;
		}
		if (r[i] - l[i] == 1 && lv > rv) swap(l[i], r[i]);
		else {
			int m = (l[i] + r[i]) / 2;
			int y = q(m);
			if (y > lv) m = l[i], y = lv;
			if (y > rv) m = r[i], y = rv;
			l[i] = m;
		}
	}
	
	printf("! %d %d %d\n", l[0], l[1], l[2]);
}
0