結果

問題 No.1830 Balanced Majority
ユーザー milanis48663220milanis48663220
提出日時 2022-02-04 21:54:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,208 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 123,604 KB
実行使用メモリ 35,908 KB
平均クエリ数 1.42
最終ジャッジ日時 2023-09-02 04:47:43
合計ジャッジ時間 5,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 25 ms
23,400 KB
testcase_03 AC 25 ms
24,084 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    map<int, ll> memo;
    auto ask_sum = [&](int k) -> ll{
        if(memo.count(k)) return memo[k];
        cout << "? " << k << endl;
        int ans; cin >> ans;
        memo[k] = ans-(k-ans);
        return ans-(k-ans);
    };
    auto verify = [&](int l, int r){
        cout << "! " << l << ' ' << r << endl;
    };
    if(ask_sum(1) == ask_sum(n-1)){
        verify(1, n-1);
        return 0;
    }
    auto find_zero = [&](){
        int l = 1, r = n-1;
        while(true){
            int x = (l+r)/2;
            if(ask_sum(x) == 0) return x;
            if(ask_sum(l)*ask_sum(x) < 0){
                x = r;
            }else{
                assert(ask_sum(x)*ask_sum(r) < 0);
                l = x;
            }
        }
    };
    int idx = find_zero();
    if(idx == n/2){
        verify(1, n/2);
    }else if(idx > n/2){
        verify(2, idx);
    }else{
        verify(idx, n-1);
    }
}
0