結果
問題 | No.253 ロウソクの長さ |
ユーザー |
![]() |
提出日時 | 2016-02-25 14:33:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 1,546 bytes |
コンパイル時間 | 508 ms |
コンパイル使用メモリ | 74,356 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 35.83 |
最終ジャッジ日時 | 2024-07-16 22:57:18 |
合計ジャッジ時間 | 3,095 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
ソースコード
#include <cstdio>#include <iostream>#include <algorithm>#include <complex>#include <queue>#include <map>using namespace std;#define FOR(i,a,b) for (int i=(a);i<(b);i++)#define FORR(i,a,b) for (int i=(b)-1;i>=(a);i--)#define REP(i,n) for (int i=0;i<(n);i++)#define RREP(i,n) for (int i=(n)-1;i>=0;i--)#define pb push_back#define ALL(a) (a).begin(),(a).end()#define EPS (1e-10)#define EQ(a,b) (abs((a)-(b)) < EPS)#define PI 3.1415926535typedef long long ll;//typedef pair<int, int> P;//typedef complex<double> C;int ask(int Y){cout << "? " << Y << endl;int res;cin >> res;return res;}void ans(int Y) {cout << "! " << Y << endl;}void solve() {// 質問回数(ろうそくの減った長さ)int cnt = 0;// L < Y となるまでYを増やすll Y = 10;while (true) {int query = ask(Y);if (query == 0) {// L == Yans(Y + cnt);return;} else if (query == -1) {// L < Ybreak;}Y *= 2;cnt++;}cnt++;int ok = 0;int ng = Y;while (true) {int mid = (ok + ng) / 2;int query = ask(mid);if (query == 0) {// L == Yans(mid + cnt);return;} else if (query == 1) {// L > Yok = mid;} else {ng = mid;}ok = max(0, ok - 1);ng--;cnt++;}}int main() {// input();solve();return 0;}