#include "strategies.h" #include "validation.h" // This interactor follows these steps: // - Read the .in file: // - Read n, the size of the kingdom // - Read the name of the strategy // - Depending on the strategy, read its parameters // - Write n to the submission // - In a loop: // - Read the operation from the submission (? or !) // - In case of a query (?), also read x and y and write back the height from the strategy // - If the submission has used more than `abortq` queries, abort // - In case of an answer (!), validate the given answer and check the number of queries used using namespace std; typedef long long ll; int main(int argc, char** argv) { // Set up the input and answer streams. ifstream in(argv[1]); OutputValidator v(argc, argv); int n; string strategy_name; Strategy* strategy = nullptr; in >> n >> strategy_name; int maxq = 10 * n + 100; int abortq = 120'000; // = max(n) * 12 if(strategy_name == "fixed") { vector> grid(n, vector(n)); for(int y = 0; y < n; y++) { for(int x = 0; x < n; x++) { in >> grid[y][x]; } } strategy = new FixedStrategy(grid); } else if(strategy_name == "spiral") { string inout; in >> inout; strategy = new SpiralStrategy(n, inout == "in"); } else if(strategy_name == "double-spiral") { strategy = new DoubleSpiralStrategy(n); } else if(strategy_name == "hill") { int x, y; in >> x >> y; strategy = new HillStrategy(n, x - 1, y - 1); } else if(strategy_name == "zigzag") { int x, y; in >> x >> y; strategy = new ZigZagStrategy(n, x - 1, y - 1); } else if(strategy_name == "sparse-zigzag") { int x, y, g, m; in >> x >> y >> g >> m; strategy = new SparseZigZagStrategy(n, x - 1, y - 1, g, m); } else if(strategy_name == "sparse-diagonal-zigzag") { int x, y, g, m; in >> x >> y >> g >> m; strategy = new SparseDiagonalZigZagStrategy(n, x - 1, y - 1, g, m); } else if(strategy_name == "sparse-spiral") { int x, y, g, m; string inout; in >> x >> y >> g >> m >> inout; strategy = new SparseSpiralStrategy(n, x - 1, y - 1, g, m, inout == "in"); } else { cerr << "Unknown strategy: " << strategy_name << endl; exit(1); } ll answer = strategy->answer(); cout << n << endl; // Interactions. int queries = 0; while(true) { auto op = v.read_string("op", 1, 1, "?!"); v.space(); if(op == "?") { // Answer query. queries += 1; if(queries > abortq) { v.WA("Used more than ", abortq, " queries (aborted)"); } int x = v.read_integer("x", 1, n); v.space(); int y = v.read_integer("y", 1, n); v.newline(); cout << strategy->get(x - 1, y - 1) << endl; } else if(op == "!") { ll team_ans = v.read_integer("team_ans", answer, answer); v.newline(); if(queries > maxq) { v.WA("Used ", queries, " queries, only ", maxq, " allowed"); } cerr << "Used " << queries << " queries" << endl; break; } else { v.WA("Unknown op ", op); } } }