10721 | 2024-04-10 16:26:55 | peti1234 | A válaszadás nehézségei | cpp17 | Accepted 100/100 | 1.284s | 3796 KiB |
#include <bits/stdc++.h>
#include "AdamEsEva.h"
using namespace std;
const long long maxval=1e18, cel=67, speckerd=4; // hogy ne csorduljon tul
bool test=0;
long long valasz, igazdb, kerddb;
long long kezd[cel+1], veg[cel+1];
void process(long long a) {
if (a>maxval) {
a=1;
}
kerddb++;
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);
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 100/100 | ||||||
1 | Accepted | 1.212s | 1880 KiB | ||||
2 | Accepted | 1.23s | 2056 KiB | ||||
3 | Accepted | 1.161s | 2396 KiB | ||||
4 | Accepted | 1.22s | 2600 KiB | ||||
5 | Accepted | 1.241s | 2564 KiB | ||||
6 | Accepted | 1.241s | 2696 KiB | ||||
7 | Accepted | 1.235s | 2776 KiB | ||||
8 | Accepted | 1.235s | 2780 KiB | ||||
9 | Accepted | 1.228s | 2904 KiB | ||||
10 | Accepted | 1.235s | 2992 KiB | ||||
11 | Accepted | 1.192s | 3116 KiB | ||||
12 | Accepted | 1.195s | 3124 KiB | ||||
13 | Accepted | 1.268s | 3104 KiB | ||||
14 | Accepted | 1.228s | 3100 KiB | ||||
15 | Accepted | 1.274s | 3104 KiB | ||||
16 | Accepted | 1.194s | 3232 KiB | ||||
17 | Accepted | 1.276s | 3316 KiB | ||||
18 | Accepted | 1.225s | 3312 KiB | ||||
19 | Accepted | 1.246s | 3312 KiB | ||||
20 | Accepted | 1.284s | 3312 KiB | ||||
21 | Accepted | 1.281s | 3476 KiB | ||||
22 | Accepted | 1.246s | 3396 KiB | ||||
23 | Accepted | 1.277s | 3396 KiB | ||||
24 | Accepted | 1.268s | 3392 KiB | ||||
25 | Accepted | 1.273s | 3396 KiB | ||||
26 | Accepted | 1.202s | 3524 KiB | ||||
27 | Accepted | 1.276s | 3568 KiB | ||||
28 | Accepted | 1.266s | 3552 KiB | ||||
29 | Accepted | 1.266s | 3564 KiB | ||||
30 | Accepted | 1.195s | 3540 KiB | ||||
31 | Accepted | 1.195s | 3532 KiB | ||||
32 | Accepted | 1.246s | 3536 KiB | ||||
33 | Accepted | 1.18s | 3776 KiB | ||||
34 | Accepted | 1.253s | 3796 KiB | ||||
35 | Accepted | 1.2s | 3792 KiB | ||||
36 | Accepted | 1.208s | 3776 KiB |