#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using lint = long long int; using P = pair; using PL = pair; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 1e9; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} templatevoid chmax(T &a, const T &b) { if (avoid chmin(T &a, const T &b) { if (b dx = {-1, -1, 0, 0, 1, 1}; vector dy = {-1, 0, -1, 1, 0, 1}; struct Enemy { int x, y = 59, h, p, init_h; }; struct State { int x, y, p; unordered_set defeated_enemy; int best_move = INF; int sumh = 0; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //vector P(25); //REP(i, 25) cin >> P[i]; vector enemy_cnt(25); int enemy_s = 0; vector enemy; int cur_x = 12; int cur_power = 100; int score_sum = 0; FOR(turn, 1, 1001) { cerr << turn << " " << cur_x << " " << cur_power << " " << score_sum << endl; FOR(i, enemy_s, enemy.size()) { enemy[i].y--; if(enemy[i].y == -1) enemy_s++; } int n; cin >> n; if(n == -1) return 0; REP(i, n) { Enemy e; cin >> e.h >> e.p >> e.x; e.init_h = e.h; enemy.push_back(e); } REP(i, n) enemy_cnt[enemy[i].x]++; //倒した敵の集合->状態 を管理してループを回す //k体の敵を最速で倒せる状態を求める double min_value = INF; int best_move = 0; vector states; states.push_back({cur_x, 0, cur_power, {}, INF, 0}); int ptr = 0; while(ptr < states.size()) { State st = states[ptr++]; vector> is_enemy(25, vector(60)); FOR(i, enemy_s, enemy.size()) if(enemy[i].h > 0 && !st.defeated_enemy.count(i)) is_enemy[enemy[i].x][enemy[i].y] = true; //ある敵のみを倒すことを考えて移動した場合を考える //倒した敵の集合を管理 //その敵に相対することのできる位置までの最小距離をDPで求める //その敵を倒せるかどうかを判定 vector> dp(25, vector(60, INF)); vector> dpd(25, vector(60, INF)); dp[st.x][st.y] = 0; dpd[st.x][st.y] = 0; FOR(j, st.y, 59) REP(i, 25) if(dp[i][j] != INF) for(int d : {-1, 1, 0}) { int x = (i + d + 25) % 25; int y = j + 1; if(is_enemy[x][y] || is_enemy[x][y-1]) continue; dp[x][y] = dp[i][j] + 1; if(i == cur_x && j == 0) dpd[x][y] = d; else dpd[x][y] = dpd[i][j]; } FOR(i, enemy_s, enemy.size()) { if(enemy[i].h <= 0) continue; if(st.defeated_enemy.count(i)) continue; int x = enemy[i].x; int y = enemy[i].y; int miny = INF; while(true) { y--; if(y == -1) break; if(is_enemy[x][y]) break; if(dp[x][y] != INF) miny = y; } if(miny == INF) continue; int dist = enemy[i].y - miny; int need_turn = enemy[i].h / (st.p / 100) + (enemy[i].h % (st.p/100) != 0); if(need_turn > dist) continue; double value = 0; value = -(double)(st.p + enemy[i].p - cur_power) / (miny+need_turn+1) - st.defeated_enemy.size()*10000; if(turn > 900) value = -(double)(st.sumh + enemy[i].h) / (miny+need_turn+1) - st.defeated_enemy.size()*10000; if(value < min_value) { min_value = value; if(st.best_move == INF) best_move = dpd[x][miny]; else best_move = st.best_move; } if(st.defeated_enemy.size() == 0) { //状態の追加 State nst; nst.x = x; nst.y = miny + need_turn; nst.p = st.p + enemy[i].p; for(int j : st.defeated_enemy) nst.defeated_enemy.insert(j); nst.defeated_enemy.insert(i); nst.best_move = st.best_move; nst.sumh = st.sumh + enemy[i].init_h; if(st.best_move == INF) nst.best_move = dpd[x][miny]; states.push_back(nst); } } } if(best_move == 0) cout << "S" << endl; else if(best_move == -1) cout << "L" << endl; else cout << "R" << endl; cout.flush(); cur_x = (cur_x + best_move + 25) % 25; //update int min_y = INF; int damage_enemy = -1; FOR(i, enemy_s, enemy.size()) { if(enemy[i].x == cur_x && enemy[i].y >= 0 && enemy[i].y < min_y && enemy[i].h > 0) { min_y = enemy[i].y; damage_enemy = i; } } if(damage_enemy != -1) { enemy[damage_enemy].h -= (cur_power/100); if(enemy[damage_enemy].h <= 0) { cur_power += enemy[damage_enemy].p; score_sum += enemy[damage_enemy].init_h; } } } cerr << score_sum << endl; }