107002024-04-09 23:11:25mraronA válaszadás nehézségeicpp17Elfogadva 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());
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask1100/100
1Elfogadva2.326s1812 KiB
2Elfogadva2.301s2136 KiB
3Elfogadva2.28s2344 KiB
4Elfogadva2.319s2548 KiB
5Elfogadva2.28s2516 KiB
6Elfogadva2.352s2516 KiB
7Elfogadva2.319s2520 KiB
8Elfogadva2.332s2648 KiB
9Elfogadva2.331s2860 KiB
10Elfogadva2.322s3092 KiB
11Elfogadva2.4s3156 KiB
12Elfogadva2.355s3156 KiB
13Elfogadva2.344s3152 KiB
14Elfogadva2.296s3160 KiB
15Elfogadva2.375s3288 KiB
16Elfogadva2.374s3368 KiB
17Elfogadva2.367s3400 KiB
18Elfogadva2.303s3608 KiB
19Elfogadva2.312s3540 KiB
20Elfogadva2.349s3572 KiB
21Elfogadva2.339s3676 KiB
22Elfogadva2.316s3624 KiB
23Elfogadva2.311s3652 KiB
24Elfogadva2.315s3620 KiB
25Elfogadva2.395s3616 KiB
26Elfogadva2.354s3624 KiB
27Elfogadva2.375s3624 KiB
28Elfogadva2.305s3620 KiB
29Elfogadva2.391s3628 KiB
30Elfogadva2.338s3624 KiB
31Elfogadva2.336s3752 KiB
32Elfogadva2.29s3752 KiB
33Elfogadva2.397s3764 KiB
34Elfogadva2.341s3760 KiB
35Elfogadva2.342s3760 KiB
36Elfogadva2.332s3888 KiB