#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // #include using namespace std; // using namespace atcoder; #define ll long long int #define ull unsigned long long int uniform_real_distribution<> uniform(0.0, 1.0); struct Timer { chrono::system_clock::time_point start; void begin() { start = chrono::system_clock::now(); } double stopwatch() { chrono::system_clock::time_point end = chrono::system_clock::now(); double elapsed = chrono::duration_cast(end - start).count(); elapsed *= 1e-9; // nanoseconds -> seconds return elapsed; } bool yet(double time_limit) { return stopwatch() < time_limit; } double progress(double time_limit) { return stopwatch() / time_limit; } bool annealing_scheduler(double profit, mt19937& engine, double time_limit, double t0, double t1) { assert(0.0 <= t1 && t1 <= t0); if (profit >= 0.0) { return true; } else { double ratio = progress(time_limit); double t = pow(t0, 1.0 - ratio) * pow(t1, ratio); return uniform(engine) < pow(2.0, profit/t); } } }; constexpr double time_limit = 1.95; constexpr int h = 60; constexpr int w = 25; constexpr int w_center = 12; constexpr int max_turn = 1000; constexpr tuple none = {0, 0, 0}; struct Input { bool online_judge = true; array p; array>,max_turn> hpx; int turn = 0; void input(const string& filename) { online_judge = false; ifstream in(filename); assert(in); for (int y = 0; y < w; ++y) { in >> p[y]; } for (int turn = 0; turn < max_turn; ++turn) { int n; in >> n; hpx[turn].resize(n); for (int i = 0; i < n; ++i) { int hi, pi, xi; in >> hi >> pi >> xi; hpx[turn][i] = {hi, pi, xi}; } } } vector> interact() { ++turn; if (online_judge) { int n; cin >> n; assert(n != -1); vector> ret(n); for (int i = 0; i < n; ++i) { int hi, pi, xi; cin >> hi >> pi >> xi; ret[i] = {hi, pi, xi}; } return ret; } else { return hpx[turn - 1]; } } void print(int dy) { assert(-1 <= dy && dy <= 1); if (online_judge) { cout << "LSR"[dy + 1] << endl; } } }; struct State { int offset; int player; array,w>,h> grid; // {temporary HP, initial HP, power} int s; int score; State() { offset = 0; player = w_center; for (int x = 0; x < h; ++x) { fill(grid[x].begin(), grid[x].end(), none); } s = 0; score = 0; } bool move_opponents() { assert(grid[offset][player] == none); if (grid[(offset + 1) % h][player] != none) { // game over return true; } fill(grid[offset].begin(), grid[offset].end(), none); ++offset; offset %= h; return false; } void make_opponents_appear(const vector>& oppenents) { int x = (offset - 1 + h) % h; for (auto [hi, pi, yi] : oppenents) { grid[x][yi] = {hi, hi, pi}; } } bool move_player(int dy) { assert(grid[offset][player] == none); player += dy; player += w; player %= w; return (grid[offset][player] != none); } void attack() { int dx = get_lowest_opponent(player); if (dx == -1) { return; } get<0>(grid[(offset + dx) % h][player]) -= 1 + s / 100; if (get<0>(grid[(offset + dx) % h][player]) <= 0) { // destroy the oppenent score += get<1>(grid[(offset + dx) % h][player]); s += get<2>(grid[(offset + dx) % h][player]); grid[(offset + dx) % h][player] = none; } } int get_lowest_opponent(int y) { for (int dx = 1; dx < h; ++dx) { if (grid[(offset + dx) % h][y] != none) { return dx; } } return -1; } int get_distance(int y0, int y1) { if (y0 < y1) { return min(y1 - y0, y0 + w - y1); } else { return min(y0 - y1, y1 + w - y0); } } int get_dy(int y) { if (y < player) { if (player - y < y + w - player) { return -1; } else { return 1; } } else if (y > player) { if (y - player < player + w - y) { return 1; } else { return -1; } } else { return 0; } } bool can_destroy(int dx, int y) { return (get<0>(grid[(offset + dx) % h][y]) + (1 + s / 100) - 1) / (1 + s / 100) <= dx - get_distance(y, player) - 1; } int greedy() { int best_y = -1; double max_cospa = -INFINITY; int min_d = -1; for (int y = 0; y < w; ++y) { int dx = get_lowest_opponent(y); if (dx == -1) { continue; } if (can_destroy(dx, y)) { int hp = get<1>(grid[(offset + dx) % h][y]), lv = 1 + s / 100; double cospa; if (y == player) { cospa = (double)hp / ((hp + lv - 1) / lv); } else { int d = get_distance(y, player); int cur_hp = get<1>(grid[(offset + dx) % h][player]); int prev_turns = (get<1>(grid[(offset + dx) % h][player]) - get<0>(grid[(offset + dx) % h][player])) / lv; cospa = (double)hp / ((hp + lv - 1) / lv + d + prev_turns); } // = (double)hp / (d + (hp + nec_turns)); if (best_y == -1 || cospa > max_cospa) { best_y = y; max_cospa = cospa; } // int d = get_distance(y, player); // if (best_y == -1 || d < min_d) { // best_y = y; // min_d = d; // } } } return (best_y == -1) ? 0 : get_dy(best_y); } }; struct Solver { Timer timer; Input input; State state; Solver(const Input& input): input(input) { timer.begin(); } void solve() { for (int turn = 0; turn < max_turn; ++turn) { if (state.move_opponents()) { break; } state.make_opponents_appear(input.interact()); int dy = state.greedy(); if (!can_move(dy)) { dy = (dy + 2) % 3 - 1; if (!can_move(dy)) { dy = (dy + 2) % 3 - 1; } } input.print(dy); if (state.move_player(dy)) { break; } state.attack(); } } bool can_move(int dy) { State s = state; if (s.move_player(dy)) { return false; } if (s.move_opponents()) { return false; } return true; } ll score() { return state.score; } }; void multi_test(int cases) { cerr << "cases: " << cases << endl; long long sum_scores = 0.0; for (int seed = 0; seed < cases; ++seed) { string filename = "in/"; filename += '0' + seed / 1000; filename += '0' + (seed / 100) % 10; filename += '0' + (seed / 10) % 10; filename += '0' + seed % 10; filename += ".txt"; Timer timer; timer.begin(); Input input; input.input(filename); Solver solver(input); solver.solve(); cerr << filename << " " << solver.score() << " " << timer.stopwatch() << " sec" << endl; sum_scores += solver.score(); } cerr << "Average Score: " << sum_scores / cases << endl; } int main() { Input input; Solver solver(input); solver.solve(); // int cases = 100; // multi_test(cases); return 0; }