107002024-04-09 23:11:25mraronA válaszadás nehézségeicpp17Accepted 100/1002.4s3888 KiB
#include "AdamEsEva.h"
#include <vector>
#include <utility>
#include <iostream>
#include <cassert>
using namespace std;
using ll = long long ;

const int K=67;

struct Response {
    ll guess;
    ll resp;
};

vector<pair<ll, ll>> calcIntervals(vector<Response>& history) {
    vector<pair<ll,ll>> res(K+1, make_pair(1LL, (ll)1e18));
    for(int lieAfter=1;lieAfter<=K;++lieAfter) {
        ll& L=res[lieAfter].first;
        ll& R=res[lieAfter].second;
        for(int j=0;j<(int)history.size();++j) {
            int lie = j>=lieAfter;
            if(history[j].resp^lie) {
                L=max(L, history[j].guess);
            }else {
                R=min(R, history[j].guess-1);
            }
        }
    }
    return res;
}

__int128 getHypothetical(vector<pair<ll,ll>>& ivs, int ind, ll x, ll resp) {
    __int128 res=0;
    for(int lieAfter=1;lieAfter<=K;++lieAfter) {
        ll L=ivs[lieAfter].first, R=ivs[lieAfter].second;
        int lie = ind>=lieAfter;
        if(resp^lie) {
            L=max(L, x);
        }else {
            R=min(R, x-1);
        }
        if(L<=R) res+=R-L+1;
    }
    return res;
}

ll deduce(vector<Response>& history) {
    ll ans=-1;
    for(int lieAfter=1;lieAfter<=history.size();++lieAfter) {
        long long L=1, R=ll(1e18);
        for(int j=0;j<(int)history.size();++j) {
            int lie = j>=lieAfter;
            if(history[j].resp^lie) {
                L=max(L, history[j].guess);
            }else {
                R=min(R, history[j].guess-1);
            }
        }
        if(L<=R) {
            assert(L==R);
            assert(ans==-1);
            ans=L;
        }
    }        
    assert(ans!=-1);
    return ans;
}

ll calc(vector<Response>& history) {
    ll L=1, R=ll(1e18)+1;
    auto ivs = calcIntervals(history);
    auto f=[&](ll x) -> __int128 {
        __int128 egyik = getHypothetical(ivs, history.size(), x, 0);
        __int128 masik = getHypothetical(ivs, history.size(), x, 1);
        return egyik-masik;
    };

    __int128 dR = f(R);
    while(L+1<R) {
        ll mid=(L+R)/2;
        auto val = f(mid);
        if((val>0 && dR>0) || (val<0 && dR<0)) {
            R=mid;
        }else {
            L=mid;
        }
    }
    return L;
}

ll search() {
    vector<Response> history;
    for(int i=0;i<K;++i) {
        ll to_ask = calc(history);
        history.push_back({to_ask, ask(to_ask)});
    }
    return deduce(history);
}

void new_game() {
    answer(search());
}
SubtaskSumTestVerdictTimeMemory
subtask1100/100
1Accepted2.326s1812 KiB
2Accepted2.301s2136 KiB
3Accepted2.28s2344 KiB
4Accepted2.319s2548 KiB
5Accepted2.28s2516 KiB
6Accepted2.352s2516 KiB
7Accepted2.319s2520 KiB
8Accepted2.332s2648 KiB
9Accepted2.331s2860 KiB
10Accepted2.322s3092 KiB
11Accepted2.4s3156 KiB
12Accepted2.355s3156 KiB
13Accepted2.344s3152 KiB
14Accepted2.296s3160 KiB
15Accepted2.375s3288 KiB
16Accepted2.374s3368 KiB
17Accepted2.367s3400 KiB
18Accepted2.303s3608 KiB
19Accepted2.312s3540 KiB
20Accepted2.349s3572 KiB
21Accepted2.339s3676 KiB
22Accepted2.316s3624 KiB
23Accepted2.311s3652 KiB
24Accepted2.315s3620 KiB
25Accepted2.395s3616 KiB
26Accepted2.354s3624 KiB
27Accepted2.375s3624 KiB
28Accepted2.305s3620 KiB
29Accepted2.391s3628 KiB
30Accepted2.338s3624 KiB
31Accepted2.336s3752 KiB
32Accepted2.29s3752 KiB
33Accepted2.397s3764 KiB
34Accepted2.341s3760 KiB
35Accepted2.342s3760 KiB
36Accepted2.332s3888 KiB