File size: 2,684 Bytes
5fed0fc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#include "testlib.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int n = 0, a[100010];
int check(int w){
int L = 1, S = 0;
for(int i = 1; i <= n; i++){
if(a[i] > w)return 0;
if(S+a[i] <= w)S += a[i];
else S = a[i], L++;
}
return L;
}
int main(int argc, char *argv[]) {
/*
* inf: input
* ouf: player output
* ans: standard output
*/
registerInteraction(argc, argv);
int t = 1;
cout.flush();
cout<<t<<endl;
cout.flush();
int sumn = 0;
int l = 0, r = 0;
string op = ouf.readWord();
if(op == "!"){
int w = ouf.readInt();
quitf(_wa, "Wrong guess");
}
else if(op == "?"){
n = ouf.readInt(1, 100000);
sumn += n;
int maxa = 0;
for(int i = 1; i <= n; i++){
a[i] = ouf.readInt(1, 100000);
maxa = max(maxa, a[i]);
}
if(maxa >= 50000){
cout<<0<<endl;
cout.flush();
l = 1, r = maxa-1;
}
else{
int L1 = check(100000);
int L2 = check(maxa);
int L = min(L2, L1+1);
cout<<L<<endl;
cout.flush();
l = maxa-1, r = 100000;
int ansl = 0, ansr = 0;
while(l < r){
int mid = (l+r)/2;
if(check(mid) <= L){
ansl = mid;
r = mid;
}
else l = mid+1;
}
l = maxa-1, r = 100000;
while(l < r){
int mid = (l+r)/2;
if(check(mid) >= L){
ansr = mid;
l = mid+1;
}
else r = mid;
}
l = ansl, r = ansr;
}
}
else{
quitf(_wa, "Invalid operation");
}
int chosen = l+inf.readInt()%(r-l+1);
op = ouf.readWord();
if(op == "!"){
int w = ouf.readInt();
if(l == r && l == w){
double score = (200000.0-1.0*sumn)/(200000.0-23867.0);
score = min(score, 1.0);
score = max(score, 0.0);
quitp(score, "Ratio: %.3lf", score);
}
else quitf(_wa, "Wrong guess");
}
else if(op == "?"){
n = ouf.readInt(1, 100000);
sumn += n;
for(int i = 1; i <= n; i++){
a[i] = ouf.readInt(1, 100000);
}
cout<<check(chosen)<<endl;
cout.flush();
}
else{
quitf(_wa, "Invalid operation");
}
op = ouf.readWord();
if(op == "!"){
int w = ouf.readInt();
if(w == chosen){
double score = (210000.0-1.0*sumn)/(210000.0-23867.0);
double unbounded_score = max(0.0, score);
score = min(score, 1.0);
score = max(score, 0.0);
quitp(score, "Ratio: %.3lf, RatioUnbounded: %.3lf", score, unbounded_score);
}
else quitf(_wa, "Wrong guess");
}
else if(op == "?"){
quitf(_wa, "Too many queries");
}
else{
quitf(_wa, "Invalid operation");
}
} |