| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "testlib.h" |
| | #include <bits/stdc++.h> |
| | using namespace std; |
| |
|
| | static const long long MAX_Q = 200000LL; |
| |
|
| | |
| | static double score_from_queries(long long q) { |
| | if (q <= 1) return 100.0; |
| |
|
| | const double t = log10((double)q); |
| | const double t1 = 0.0; |
| | const double t2 = 4.0; |
| | const double t3 = log10(20000.0); |
| | const double t4 = log10(50000.0); |
| | const double t5 = log10(200000.0); |
| |
|
| | auto lerp = [](double a, double b, double x, double xa, double xb) { |
| | if (xa == xb) return a; |
| | double w = (x - xa) / (xb - xa); |
| | return a + (b - a) * w; |
| | }; |
| |
|
| | if (t <= t2) return lerp(100.0, 95.0, t, t1, t2); |
| | else if (t <= t3) return lerp(95.0, 60.0, t, t2, t3); |
| | else if (t <= t4) return lerp(60.0, 30.0, t, t3, t4); |
| | else if (t <= t5) return max(0.0, lerp(30.0, 0.0, t, t4, t5)); |
| | else return 0.0; |
| | } |
| |
|
| | int main(int argc, char* argv[]) { |
| | registerInteraction(argc, argv); |
| |
|
| | |
| | long long n = inf.readLong(1LL, 1000000000LL, "n"); |
| | long long s = inf.readLong(1LL, n, "s"); |
| |
|
| | long long pos = s; |
| | long long qcnt = 0; |
| |
|
| | |
| | unordered_map<long long, long long> label; |
| | label.reserve(1 << 16); |
| | label.max_load_factor(0.7f); |
| |
|
| | |
| | unordered_set<long long> used; |
| | used.reserve(1 << 16); |
| | used.max_load_factor(0.7f); |
| |
|
| | |
| | label[s] = s; |
| | used.insert(s); |
| |
|
| | |
| | auto take_random_unused_number = [&]() -> long long { |
| | while (true) { |
| | long long r = rnd.next(1LL, n); |
| | if (!used.count(r)) { |
| | used.insert(r); |
| | return r; |
| | } |
| | } |
| | }; |
| |
|
| | auto tell = [&](long long v) { |
| | cout << v << '\n' << flush; |
| | }; |
| |
|
| | while (true) { |
| | string cmd = ouf.readWord(); |
| |
|
| |
|
| | if (cmd == "walk") { |
| | long long x = ouf.readLong(0LL, 1000000000LL, "x"); |
| | |
| | long long step = (n == 1 ? 0 : (x % n)); |
| | pos = ((pos - 1 + step) % n) + 1; |
| |
|
| | if (!label.count(pos)) { |
| | long long val = take_random_unused_number(); |
| | label[pos] = val; |
| | } |
| |
|
| | ++qcnt; |
| | if (qcnt > MAX_Q) { |
| | quitf(_wa, "Too many queries: %lld (max %lld)", qcnt, MAX_Q); |
| | } |
| |
|
| | tell(label[pos]); |
| |
|
| | } else if (cmd == "guess") { |
| | long long g = ouf.readLong(1LL, 1000000000LL, "n_guess"); |
| | bool ok = (g == n); |
| |
|
| | if (!ok) { |
| | quitp(0.0, "Wrong answer. hidden n=%lld, your guess=%lld, queries=%lld", n, g, qcnt); |
| | } else { |
| | double score = score_from_queries(qcnt); |
| | double part = max(0.0, min(100.0, score)) / 100.0; |
| | double unbounded_part = max(0.0, score) / 100.0; |
| | |
| | quitp(part, "OK. n=%lld, queries=%lld, Ratio: %.4f, RatioUnbounded: %.4f", n, qcnt, part, unbounded_part); |
| | } |
| |
|
| | } else { |
| | quitf(_wa, "Unknown command: '%s' (expected 'walk' or 'guess')", cmd.c_str()); |
| | } |
| | } |
| | } |
| |
|