Submission #1208495

#TimeUsernameProblemLanguageResultExecution timeMemory
1208495FatonimMađioničar (COI22_madionicar)C++20
38 / 100
453 ms432 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef ONPC
#include "debug.h"
#else
#define dbg(...)
#endif

#define ll long long
#define int long long
#define ld long double
#define pi pair<int, int>
#define sz(a) ((int)(a.size()))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(n) ((n) * (n))
#define divup(a, b) (((a) + (b)-1) / (b))
#define popcount(n) __builtin_popcountll(n)
#define clz(n) __builtin_clzll(n)
#define Fixed(a) cout << fixed << setprecision(12) << a;

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

const int mod = 998244353; // 998244353 1e9 + 7
const ll inf = (ll)(1e18) + 7;
const ld eps = 1e-9;

const int B = 32;
const int N = 1000 + 3;
const int logn = 20;
const int maxn = 2e5 + 7;
/////////////////////////solve/////////////////////////

int qr = 0;

bool ask(int l, int r) {
    ++qr;
    if (qr > 190000) {
        return 0;
    }
    cout << "? " << l + 1 << ' ' << r + 1 << endl;
    bool res;
    cin >> res;
    return res;
}

void answer(int ans) {
    cout << "! " << ans << endl;
    exit(0);
}

void solve() {
    int n;
    cin >> n;

    int ans = 0;
    int len = 0;
    for (int i = 0; i < n; ++i) {
        while (i - len - 1 >= 0 && i + len + 1 < n && ask(i - len - 1, i + len + 1)) ++len;
    }
    ans = max(ans, len * 2 + 1);
    len = 0;
    for (int i = 1; i < n; ++i) {
        while (i - len - 1 >= 0 && i + len < n && ask(i - len - 1, i + len)) ++len;
    }
    ans = max(ans, len * 2);

    answer(ans);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    // #ifdef ONPC
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("error.txt", "w", stderr);
    // #endif

    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...