| | #include "testlib.h" |
| | #include <bits/stdc++.h> |
| | using namespace std; |
| |
|
| | static const long long COORD_LIMIT = 100000000LL; |
| | static const int MAX_D_PER_WAVE = 2000; |
| | static const int TOTAL_PROBE_LIMIT = 20000; |
| |
|
| | int main(int argc, char* argv[]) { |
| | |
| | registerInteraction(argc, argv); |
| |
|
| | |
| | long long b = inf.readLong(); |
| | int k = inf.readInt(); |
| | int w = inf.readInt(); |
| |
|
| | |
| | vector<pair<long long,long long>> hidden(k); |
| | for (int i = 0; i < k; ++i) { |
| | long long x = ans.readLong(); |
| | long long y = ans.readLong(); |
| | |
| | if (x < -b || x > b || y < -b || y > b) { |
| | quitf(_fail, "Secret deposit (%lld, %lld) is out of bounds [-%lld, %lld].", |
| | x, y, b, b); |
| | } |
| | hidden[i] = {x, y}; |
| | } |
| |
|
| | |
| | cout << b << ' ' << k << ' ' << w << '\n'; |
| | cout.flush(); |
| |
|
| | auto manhattan = [&](const pair<long long,long long>& a, |
| | const pair<long long,long long>& p) -> long long { |
| | return llabs(a.first - p.first) + llabs(a.second - p.second); |
| | }; |
| |
|
| | int wave_count = 0; |
| | int total_probes = 0; |
| |
|
| | while (true) { |
| | |
| |
|
| | |
| | string cmd = ouf.readToken(); |
| | |
| | |
| | |
| | |
| |
|
| | if (cmd == "?") { |
| | |
| | if (wave_count >= w) { |
| | quitp(0.0, "Wave limit exceeded. Max waves: %d. Ratio: 0.0000", w); |
| | } |
| | ++wave_count; |
| |
|
| | |
| | int d = ouf.readInt(); |
| | if (d < 1 || d > MAX_D_PER_WAVE) { |
| | quitp(0.0, "Invalid d=%d in query: must be in [1, %d]. Ratio: 0.0000", |
| | d, MAX_D_PER_WAVE); |
| | } |
| | if (total_probes + d > TOTAL_PROBE_LIMIT) { |
| | quitp(0.0, "Probe limit exceeded. Max probes: %d. Ratio: 0.0000", |
| | TOTAL_PROBE_LIMIT); |
| | } |
| |
|
| | vector<pair<long long,long long>> probes; |
| | probes.reserve(d); |
| | for (int j = 0; j < d; ++j) { |
| | long long sj = ouf.readLong(); |
| | long long tj = ouf.readLong(); |
| | if (sj < -COORD_LIMIT || sj > COORD_LIMIT || |
| | tj < -COORD_LIMIT || tj > COORD_LIMIT) { |
| | quitp(0.0, |
| | "Invalid probe coordinate (%lld, %lld): out of range [-%lld, %lld]. Ratio: 0.0000", |
| | sj, tj, COORD_LIMIT, COORD_LIMIT); |
| | } |
| | probes.push_back({sj, tj}); |
| | } |
| | total_probes += d; |
| |
|
| | |
| | vector<long long> distances; |
| | distances.reserve((size_t)k * (size_t)d); |
| | for (int i = 0; i < k; ++i) { |
| | for (int j = 0; j < d; ++j) { |
| | distances.push_back(manhattan(hidden[i], probes[j])); |
| | } |
| | } |
| | sort(distances.begin(), distances.end()); |
| |
|
| | |
| | for (size_t i = 0; i < distances.size(); ++i) { |
| | if (i) cout << ' '; |
| | cout << distances[i]; |
| | } |
| | cout << '\n'; |
| | cout.flush(); |
| |
|
| | } else if (cmd == "!") { |
| | |
| | vector<pair<long long,long long>> guess(k); |
| | for (int i = 0; i < k; ++i) { |
| | long long x = ouf.readLong(); |
| | long long y = ouf.readLong(); |
| | guess[i] = {x, y}; |
| | } |
| |
|
| | |
| | int found = 0; |
| | vector<bool> used(k, false); |
| | for (int i = 0; i < k; ++i) { |
| | for (int j = 0; j < k; ++j) { |
| | if (!used[j] && guess[i].first == hidden[j].first && |
| | guess[i].second == hidden[j].second) { |
| | used[j] = true; |
| | ++found; |
| | break; |
| | } |
| | } |
| | } |
| |
|
| | double ratio = k == 0 ? 1.0 : (double)found / (double)k; |
| | double unbounded_ratio = max(0.0, ratio); |
| | ratio = max(0.0, min(1.0, ratio)); |
| |
|
| | if (found == k) { |
| | quitp(1.0, "All mineral deposits found. Ratio: 1.0000, RatioUnbounded: 1.0000"); |
| | } else { |
| | quitp(ratio, "Found %d of %d mineral deposits. Ratio: %.4f, RatioUnbounded: %.4f", |
| | found, k, ratio, unbounded_ratio); |
| | } |
| | break; |
| |
|
| | } else { |
| | quitf(_wa, "Invalid command: expected '?' or '!' but got '%s'", cmd.c_str()); |
| | } |
| | } |
| |
|
| | return 0; |
| | } |
| |
|