Submission #1274369

#TimeUsernameProblemLanguageResultExecution timeMemory
1274369oswaldzzMađioničar (COI22_madionicar)C++20
100 / 100
492 ms444 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl endl
#define hehe ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)  ;

// const int mod = 998244353;
const int mod = 1e9+7;
const int M = 2e5+5;

int gas(int a, int b){
    cout << "? " << a << ' ' << b << nl;
    cout.flush();
    int x;
    if(!(cin >> x)){ 
        exit(0);
    }
    return x;
}

void solve(){
    int n; cin >> n;
    if(n == 1){    
        cout << "! " << 1 << nl;
        return;
    }

    int ans = 1;
    int l = 1;
    int r = 3;
    while(r <= n){
        if(l <= 0) { l++; r++; }
        else{
            if(gas(l,r)){
                ans = max(ans, r - l + 1);
                l--; r++;
            }
            else{
                l++;r++;
            }
        }
    }

    l = 1, r = 2;
    while(r <= n){
        if(l <= 0) { l++; r++; }
        else{
            if(gas(l,r)){
                ans = max(ans, r-l+1);
                l--; r++;
            }
            else{
                l++, r++;
            }
        }
    }

    cout << "! " << ans << nl;
}

signed main(){
    hehe
    // int t; cin >> t;
    int t = 1;
    while(t--){
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...