107202024-04-10 16:26:40peti1234A válaszadás nehézségeicpp17Wrong answer 0/1008ms4380 KiB
#include <bits/stdc++.h>
#include "AdamEsEva.h"

using namespace std;
const long long maxval=1e18, cel=67, speckerd=4; // hogy ne csorduljon tul
int kerddb;
long long kezd[cel+1], veg[cel+1];

void process(long long a) {
    if (a>maxval) {
        a=1;
    }
    bool res=ask(a);
    for (int i=1; i<=cel; i++) {
        if (i>=kerddb) {
            if (res) kezd[i]=max(kezd[i], a);
            else veg[i]=min(veg[i], a-1);
        } else {
            if (res) veg[i]=min(veg[i], a-1);
            else kezd[i]=max(kezd[i], a);
        }
    }
}

long long calc(long long a) {
    long long sum=0;

    for (int i=1; i<=kerddb; i++) {
        long long s=veg[i]-max(kezd[i], a);
        if (s>=0) sum+=s+1;
    }
    for (int i=kerddb+1; i<=cel; i++) {
        long long s=min(veg[i], a-1)-kezd[i];
        if (s>=0) sum+=s+1;
    }
    return sum;
}

void new_game() {
    kerddb=0;
    for (int i=1; i<=cel; i++) {
        kezd[i]=1, veg[i]=maxval;
    }

    for (int i=1; i<=speckerd; i++) {
        process((kezd[cel]+veg[cel])/2);
    }

    for (int j=speckerd+1; j<=cel; j++) {
        long long sum=0;
        for (int i=1; i<=cel; i++) {
            if (kezd[i]<=veg[i]) {
                sum+=veg[i]-kezd[i]+1;
            }
        }
        long long fel=sum/2;
        long long lo=1, hi=maxval+1, mid, vallo=calc(lo), valhi=calc(hi), valmid;
        while (hi-lo>1) {
            mid=(hi+lo+1)/2;
            valmid=calc(mid);
            if ((valmid<=fel && vallo<=fel) || (valmid>fel && vallo>fel)) {
                lo=mid;
                vallo=valmid;
            } else {
                hi=mid;
                valhi=valmid;
            }
        }
        if (abs(valhi-fel)<abs(vallo-fel)) process(hi);
        else process(lo);
    }

    long long sum=0, res=0;
    for (int j=1; j<=cel; j++) {
        if (kezd[j]<=veg[j]) {
            res=kezd[j];
            sum+=veg[j]-kezd[j]+1;
        }
    }
    answer(res);
}
SubtaskSumTestVerdictTimeMemory
subtask10/100
1Wrong answer4ms1884 KiB
2Wrong answer4ms2120 KiB
3Wrong answer4ms2284 KiB
4Wrong answer4ms2496 KiB
5Wrong answer4ms2744 KiB
6Wrong answer4ms2916 KiB
7Wrong answer4ms3168 KiB
8Wrong answer4ms3384 KiB
9Wrong answer4ms3552 KiB
10Wrong answer4ms3796 KiB
11Wrong answer4ms4008 KiB
12Wrong answer4ms4060 KiB
13Wrong answer4ms4064 KiB
14Wrong answer4ms4064 KiB
15Wrong answer4ms4060 KiB
16Wrong answer4ms4096 KiB
17Wrong answer4ms4212 KiB
18Wrong answer4ms4136 KiB
19Wrong answer4ms4140 KiB
20Wrong answer4ms4132 KiB
21Wrong answer4ms4280 KiB
22Wrong answer4ms4380 KiB
23Wrong answer4ms4232 KiB
24Wrong answer4ms4232 KiB
25Wrong answer4ms4236 KiB
26Wrong answer4ms4240 KiB
27Wrong answer4ms4240 KiB
28Wrong answer4ms4236 KiB
29Wrong answer4ms4236 KiB
30Wrong answer4ms4236 KiB
31Wrong answer4ms4348 KiB
32Wrong answer4ms4232 KiB
33Wrong answer4ms4236 KiB
34Wrong answer4ms4236 KiB
35Wrong answer8ms4236 KiB
36Wrong answer4ms4364 KiB