#include #include #include #include #include #include #include using namespace std; using pii = pair; // implemented by contestant void init(int R, int C, int N, int E, vector a, vector b, vector x, vector y); void newRound(); void playTurn(int symbol); // fail with error message void error(string s) { cout << "Error: " << s << endl; exit(1); } // private data namespace grader { bool token = false; const pii DISCARD = {-1,-1}; vector ops; } void place(int r, int c) { if (!grader::token) error("forbidden call to function 'place'."); if (r < 0) error("row id is not valid"); if (c < 0) error("col id is not valid"); grader::ops.push_back({r,c}); grader::token = false; } void discard() { if (!grader::token) error("forbidden call to function 'discard'."); grader::ops.push_back(grader::DISCARD); grader::token = false; } int main(int argc, char** argv) { // constants const int nbRounds = 100; const int nbTurns = 1000; // read input int R, C, N, E; cin >> R >> C >> N >> E; vector a(N), b(E), x(E), y(E); for (int iSymbol=0; iSymbol> a[iSymbol]; for (int iBonus=0; iBonus> b[iBonus] >> x[iBonus] >> y[iBonus]; // validator for (int iSymbol=0; iSymbol y[iBonus]) error("x[iBonus] > y[iBonus]"); } // random generator mt19937 generator(42); if (argc == 2) generator.seed(atoi(argv[1])); uniform_int_distribution distribution(0, N-1); // initialize solution grader::token = false; init(R, C, N, E, a, b, x, y); double average_score = 0; for (int iRound=0; iRound s(nbTurns); grader::ops.clear(); grader::token = false; newRound(); for (int iTurn=0; iTurn grid; for (int iTurn=0; iTurn= R) error("row id is not valid"); if (p.second < 0 || p.second >= C) error("column id is not valid."); if (grid.count(p)) error("cannot place a symbol on a non-empty square."); grid[p] = s[iTurn]; delta += a[s[iTurn]]; } score_online += delta; } // grade solution: bonus points long long int score_bonus = 0; int bonus_pairs = 0; map bonus; for (auto it: grid) { vector neighbours = { {it.first.first-1, it.first.second}, {it.first.first+1, it.first.second}, {it.first.first, it.first.second-1}, {it.first.first, it.first.second+1} }; for (auto n: neighbours) if (grid.count(n)) bonus[{min(it.second, grid[n]), max(it.second, grid[n])}]++; } for (int iBonus=0; iBonus