結果
問題 | No.5017 Tool-assisted Shooting |
ユーザー |
![]() |
提出日時 | 2023-06-29 18:14:33 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 6,264 bytes |
コンパイル時間 | 2,306 ms |
コンパイル使用メモリ | 216,828 KB |
実行使用メモリ | 24,384 KB |
スコア | 3,403,437 |
平均クエリ数 | 3962.72 |
最終ジャッジ日時 | 2023-07-16 13:30:48 |
合計ジャッジ時間 | 15,142 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
#include <bits/stdc++.h>using namespace std;using pii = pair<int,int>;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<vector<Enemy*>>& 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<vector<Enemy>> enemies(max_turn + 1);vector field = vector(height, vector<Enemy*>(width, nullptr));vector<int> 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<pii> 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;}