結果

問題 No.253 ロウソクの長さ
ユーザー y_taira_cy_taira_c
提出日時 2017-07-28 19:56:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,962 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 164,784 KB
実行使用メモリ 24,420 KB
平均クエリ数 21.14
最終ジャッジ日時 2023-09-23 14:20:50
合計ジャッジ時間 4,853 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,664 KB
testcase_01 AC 26 ms
23,520 KB
testcase_02 AC 25 ms
24,324 KB
testcase_03 AC 24 ms
23,532 KB
testcase_04 AC 23 ms
23,832 KB
testcase_05 AC 24 ms
23,364 KB
testcase_06 AC 26 ms
23,820 KB
testcase_07 AC 26 ms
23,640 KB
testcase_08 AC 26 ms
24,000 KB
testcase_09 AC 25 ms
23,520 KB
testcase_10 AC 25 ms
23,640 KB
testcase_11 AC 24 ms
23,400 KB
testcase_12 AC 26 ms
23,544 KB
testcase_13 AC 26 ms
24,360 KB
testcase_14 AC 25 ms
24,420 KB
testcase_15 AC 25 ms
24,012 KB
testcase_16 AC 24 ms
24,336 KB
testcase_17 AC 25 ms
24,336 KB
testcase_18 AC 25 ms
23,364 KB
testcase_19 AC 25 ms
23,820 KB
testcase_20 AC 27 ms
23,664 KB
testcase_21 AC 26 ms
23,400 KB
testcase_22 AC 25 ms
23,604 KB
testcase_23 AC 25 ms
23,820 KB
testcase_24 AC 24 ms
24,036 KB
testcase_25 AC 26 ms
23,664 KB
testcase_26 AC 25 ms
24,228 KB
testcase_27 AC 25 ms
24,012 KB
testcase_28 AC 26 ms
24,048 KB
testcase_29 AC 26 ms
23,388 KB
testcase_30 AC 25 ms
23,676 KB
testcase_31 AC 26 ms
23,628 KB
testcase_32 AC 26 ms
23,988 KB
testcase_33 WA -
testcase_34 AC 25 ms
23,352 KB
testcase_35 AC 25 ms
23,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;


typedef int32_t h_int32;
typedef int64_t h_int64;
typedef uint32_t uh_int32;
typedef uint64_t uh_int64;
typedef h_int64 h_int;

#define REP( i, n ) for(int i = 0; i < ( int )( n ); ++i )
#define REPR( i, n ) for(int i = ( int )( n ); i >= 0; --i )
#define FOR( i, a, n ) for(int i = ( int )( a ); i < ( int )( n ); ++i )
#define FORR( i, a, n ) for(int i = ( int )( n ); i >= ( int )( a ); --i)

#define ALL( x ) x.begin(), x.end()

#define DOUT( x ) cerr << #x << " = " << x << "\n"
#define COUT( x ) cout << ( x ) << "\n"
#define DOUBLECOUT( num, x ) cout << fixed << setprecision( num ) << ( x ) << "\n"

#define INF 999999999
#define PI 3.14159265359

#ifdef _DEBUG
h_int res = 123456789;
#endif

int Ask( h_int num )
{
        cout << "? " << num << endl;
        int n;
#ifdef _DEBUG
        if(num == res ) n = 0;
        else if( num < res) n = 1;
        else if(num > res) n = -1;
        res--;
#else
        cin >> n;
#endif
        return n;
}

signed main()
{
        ios::sync_with_stdio( false );
        cin.tie( 0 );

        h_int r, l = 0;
        int cnt = 0;
        int a = Ask( 100 );
        if( a == 0)
        {
                cout << "! 100" << endl;
                return 0;
        }
        else if( a == -1) r = 99;
        else r = 999999999;
        ++cnt;
        while(r - l > 1)
        {
                h_int m = ( l + r ) / 2;
                a = Ask( m );
                if( a == 0 )
                {
                        cout << "! " << m + cnt << endl;
                        return 0;
                }
                if(a > 0)
                {
                        l = m;
                }
                else
                {
                        r = m;
                }
                --l; --r; ++cnt;
        }
        if( Ask( r ) == 0) cout << "! " << r + cnt + 1 << endl;
        else cout << "! " << l + cnt + 1 << endl;
        return 0;
}
0