#include using namespace std; using pii = pair; constexpr int width = 25; // フィールドの幅 constexpr int height = 60; // フィールドの高さ constexpr int max_turn = 1000; // ゲームの最大ターン数 constexpr int level_up = 100; // レベルアップに必要なパワー値 constexpr int INF = (int)1e9; constexpr int testcase = 0; bool submit = true; void read_input(){ std::stringstream ss; std::string num = std::to_string(testcase); int siz = num.size(); for(int i = 0; i < 4 - siz; i++) num = '0' + num; ss << "in/" << num << ".txt"; FILE *in = freopen(ss.str().c_str(), "r", stdin); } void file_output(){ std::stringstream ss; std::string num = std::to_string(testcase); int siz = num.size(); for(int i = 0; i < 4 - siz; i++) num = '0' + num; ss << "out/" << num << ".txt"; FILE *out = freopen(ss.str().c_str(), "w", stdout); } // 敵機の情報 struct Enemy { int init_hp; int h, p; int x, y; Enemy(int h, int p, int x) : h(h), p(p), x(x) { init_hp = h; y = height - 1; } }; // 自機の情報 struct Player { int x, y; int score; int power, level; Player(int x, int y) : x(x), y(y) { score = 0; power = 0; level = 1; } void destroy_enemy(Enemy* e) { score += e->init_hp; power += e->p; level = 1 + power / level_up; } bool try_move(vector>& field ,char c) { if(c == 'L') { int nx = (x - 1 + width) % width; if(field[y][nx]) return false; else if(field[y+1][nx]) return false; else if(field[y+2][nx] && field[y+2][(nx-1+width)%width] && field[y+2][(nx+1)%width]) return false; else return true; } else if(c == 'R') { int nx = (x + 1) % width; if(field[y][nx]) return false; else if(field[y+1][nx]) return false; else if(field[y+2][nx] && field[y+2][(nx-1+width)%width] && field[y+2][(nx+1)%width]) return false; else return true; } else if(c == 'S') { if(field[y+1][x]) return false; else if(field[y+2][x] && field[y+2][(x-1+width)%width] && field[y+2][(x+1)%width]) return false; return true; } else return false; } void apply_move(char c) { std::cout << c << std::endl; std::cout << "# " << c << std::endl; if(c == 'L') { x = (x - 1 + width) % width; } else if(c == 'R') { x = (x + 1) % width; } } }; int main(){ if(!submit) { read_input(); file_output(); } Player player(12, 0); vector> enemies(max_turn + 1); vector field = vector(height, vector(width, nullptr)); vector P(width); if(!submit) { for(int i = 0; i < width; i++) cin >> P[i]; } for(int T = 1; T <= max_turn; T++) { // 敵機の移動 for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { if(!field[y][x]) continue; field[y][x]->y -= 1; if(y == 0) { field[y][x] = nullptr; } else { field[y-1][x] = field[y][x]; field[y][x] = nullptr; if(y - 1 == player.y && x == player.x) { std::cerr << "turn = " << T << endl; std::cerr << "score = " << player.score << endl; return 0; } } } } // 入力の受け取り int n; cin >> n; if(n == -1) return 0; for(int i = 0; i < n; i++) { int h, p, x; cin >> h >> p >> x; enemies[T].emplace_back(h, p, x); } for(auto& enemy : enemies[T]) { field[height-1][enemy.x] = &enemy; } // 自機の移動 // 敵機を倒せない列には移動しない vector front_enemy(width, {-1, -1}); for(int x = 0; x < width; x++) { int dx1 = abs(x - player.x); int dx2 = abs(x - (player.x - width)); int dx = max(1, min(dx1, dx2)); for(int y = 0; y < height; y++) { if(!field[y][x]) continue; int des = dx - 1 + (field[y][x]->h + player.level - 1) / player.level; if(y >= des) { front_enemy[x] = {y, des}; } break; } } // 一番早く倒せる敵を探す Enemy* near_enemy = nullptr; int min_dist = INF; for(int x = 0; x < width; x++) { int y = front_enemy[x].first; if(y == -1) continue; int dist = front_enemy[x].second; if(dist < min_dist) { min_dist = dist; near_enemy = field[y][x]; } } // 倒せる敵がいない場合 if(!near_enemy) { if(player.try_move(field, 'S')) { player.apply_move('S'); } else if(player.try_move(field, 'L')) { player.apply_move('S'); } else if(player.try_move(field, 'R')) { player.apply_move('R'); } else player.apply_move('S'); } // 同列に倒せる敵がいるならとどまる else if(near_enemy->x == player.x) { player.apply_move('S'); } // 敵が左にいる場合 else if(near_enemy->x < player.x) { int ex = near_enemy->x, px = player.x; int left = px - ex, right = ex - (px - width); if(left < right) { if(player.try_move(field, 'L')) { player.apply_move('L'); } else if(player.try_move(field, 'S')) { player.apply_move('S'); } else player.apply_move('R'); } else { if(player.try_move(field, 'R')) { player.apply_move('R'); } else if(player.try_move(field, 'S')) { player.apply_move('S'); } else player.apply_move('L'); } } // 敵が右にいる場合 else { int ex = near_enemy->x, px = player.x; int left = px + width - ex, right = ex - px; if(left < right) { if(player.try_move(field, 'L')) { player.apply_move('L'); } else if(player.try_move(field, 'S')) { player.apply_move('S'); } else player.apply_move('R'); } else { if(player.try_move(field, 'R')) { player.apply_move('R'); } else if(player.try_move(field, 'S')) { player.apply_move('S'); } else player.apply_move('L'); } } if(near_enemy) { cout << "# " << near_enemy->x << " " << near_enemy->y << endl; cout << "# hp = " << near_enemy->h << endl; } // 自機の攻撃 int px = player.x, py = player.y + 1; while(py < height) { if(field[py][px]) { field[py][px]->h -= player.level; if(field[py][px]->h <= 0) { player.destroy_enemy(field[py][px]); field[py][px] = nullptr; } break; } py++; } } std::cerr << "turn = " << max_turn + 1 << endl; std::cerr << "score = " << player.score << endl; return 0; }