結果
| 問題 |
No.3212 SUPER Guess the Number
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-07-31 17:42:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 1,094 bytes |
| コンパイル時間 | 574 ms |
| コンパイル使用メモリ | 42,184 KB |
| 実行使用メモリ | 26,356 KB |
| 平均クエリ数 | 22.92 |
| 最終ジャッジ日時 | 2025-07-31 17:42:52 |
| 合計ジャッジ時間 | 2,557 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int query(int, bool)’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d", &r);
| ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3212.cc: No.3212 SUPER Guess the Number - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
/* constant */
const int MIN_A = 1;
const int MAX_A = 1000000;
const int MIN_X = -1000000000;
const int MAX_X = 1000000000;
/* typedef */
/* global variables */
/* subroutines */
int query(int a, bool rf = true) {
printf("? %d\n", a); fflush(stdout);
if (rf) {
int r;
scanf("%d", &r);
if (r < 0) exit(0);
return r;
}
return 0;
}
/* main */
int main() {
int px = MIN_A, p = 0;
query(px, false);
int a0 = MIN_A, a1 = MAX_A;
while (a0 < a1) {
if (p == 0) { // px = left side
int a = (a0 + a1 + 1) / 2;
int xi = a * 2 - px;
if (query(xi)) a0 = a; // ans-px>=xi-ans
else a1 = a;
px = xi, p = 1;
}
else { // px = right side
int a = (a0 + a1) / 2;
int xi = a * 2 - px;
if (query(xi)) a1 = a;
else a0 = a;
px = xi, p = 0;
}
}
printf("! %d\n", a0); fflush(stdout);
for (int i = 0; i < 1e9; i++);
return 0;
}
tnakao0123