#ifndef hari64 #include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define debug(...) #else #include "util/viewer.hpp" #define debug(...) viewer::_debug(__LINE__, #__VA_ARGS__, __VA_ARGS__) #endif // clang-format off using namespace std; using ll = long long; using ld = long double; using pii = pair; using pll = pair; template using vc = vector; template using vvc = vector>; template using vvvc = vector>; using vi = vc; using vl = vc; using vpi = vc; using vpl = vc; #define ALL(x) begin(x), end(x) #define RALL(x) (x).rbegin(), (x).rend() constexpr int INF = 1001001001; constexpr long long INFll = 1001001001001001001; template bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } // clang-format on struct Enemy { int h, p; int x, y; int initH; Enemy(int h, int p, int x) : h(h), p(p), x(x), y(59) { initH = h; } }; constexpr int H = 60; constexpr int W = 25; vvc GRID(W); int NOW_X; int LEVEL; int POWER_SUM; int SCORE; void update(vvc& g) { for (int x = 0; x < W; x++) { if (g[x].empty()) continue; for (auto& e : g[x]) { e.y--; } if (g[x].back().y == -1) { g[x].pop_back(); } assert(g[x].empty() || g[x].back().y != -1); } } tuple simulate(vector& enemy) { string moves = ""; int score = 0; int score2 = 0; int nowX = NOW_X; int level = LEVEL; int powerSum = POWER_SUM; int totalTurn = 0; int enemyIndex = 0; auto grid = GRID; // for (int x = 0; x < W; x++) { // set check; // for (auto& e : grid[x]) { // check.insert(e.y); // } // assert(check.size() == grid[x].size()); // } while (true) { totalTurn++; if (totalTurn > 1000) break; string move = "S"; if (nowX < enemy[enemyIndex]) { if (enemy[enemyIndex] - nowX < 12) { move = "R"; } else { move = "L"; } } else if (nowX > enemy[enemyIndex]) { if (nowX - enemy[enemyIndex] < 12) { move = "L"; } else { move = "R"; } } if (enemyIndex <= 1) { moves += move; } if (move == "L") nowX = (25 + nowX - 1) % 25; if (move == "R") nowX = (25 + nowX + 1) % 25; if (move == "S") nowX = nowX; if (grid[nowX].empty()) continue; if (grid[nowX].back().y == 1 || grid[nowX].back().y == 0) { return {-INF, -INF, "S"}; } grid[nowX].back().h -= level; score2 += grid[nowX].back().initH; if (grid[nowX].back().h <= 0) { score += grid[nowX].back().initH; powerSum += grid[nowX].back().p; level = 1 + powerSum / 100; grid[nowX].pop_back(); while (enemyIndex < int(enemy.size()) && grid[enemy[enemyIndex]].empty()) { enemyIndex++; } if (enemyIndex >= int(enemy.size())) break; } update(grid); } return {score / totalTurn, score2, moves}; } string solve() { int bestScore = -1; string bestMove = ""; if (LEVEL <= 150) { for (int e1 = 0; e1 < W; e1++) { if (GRID[e1].empty()) continue; vi enemies = {e1}; auto [score, _, move] = simulate(enemies); if (chmax(bestScore, score)) { bestMove = move; } } } else { for (int e1 = 0; e1 < W; e1++) { if (GRID[e1].empty()) continue; for (int e2 = 0; e2 < W; e2++) { if (GRID[e2].empty()) continue; vi enemies = {e1, e2}; auto [score, _, move] = simulate(enemies); if (chmax(bestScore, score)) { bestMove = move; } } } } if (bestScore == -1) { debug("Game Over!"); } assert(!bestMove.empty()); // debug(bestScore, bestMove); return bestMove; } int main() { cin.tie(0); ios::sync_with_stdio(false); #ifdef hari64 for (int _ = 0; _ < W; _++) { int p; cin >> p; assert(1 <= p && p <= 8); } #endif NOW_X = 12; LEVEL = 1; POWER_SUM = 0; SCORE = 0; const int NUM_OF_TURNS = 1000; string moves = ""; vector ans; for (int i = 0; i < NUM_OF_TURNS; i++) { // debug(i); update(GRID); int n; cin >> n; if (n == -1) break; for (int i = 0; i < n; i++) { int h, p, x; cin >> h >> p >> x; assert(GRID[x].empty() || GRID[x].front().y < 59); GRID[x].insert(GRID[x].begin(), Enemy(h, p, x)); } string s; if (i <= 5) { s = "S"; } else if (i <= 40) { if (moves.size() == 0) { moves = solve(); } s = string(1, moves[0]); moves.erase(moves.begin()); } else { s = string(1, solve()[0]); } #ifndef hari64 cout << s << endl; flush(cout); #endif ans.push_back(s); if (s == "L") NOW_X = (25 + NOW_X - 1) % 25; if (s == "R") NOW_X = (25 + NOW_X + 1) % 25; if (s == "S") NOW_X = NOW_X; if (GRID[NOW_X].empty()) continue; GRID[NOW_X].back().h -= LEVEL; if (GRID[NOW_X].back().h <= 0) { SCORE += GRID[NOW_X].back().initH; POWER_SUM += GRID[NOW_X].back().p; LEVEL = 1 + POWER_SUM / 100; GRID[NOW_X].pop_back(); } } debug(SCORE, LEVEL, POWER_SUM, NOW_X); #ifdef hari64 for (auto s : ans) { cout << s << endl; } #endif return 0; }