#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #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_oppenents_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; 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; } }; 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_oppenents_appear(input.interact()); int dy = 0; 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; }