結果

問題 No.5017 Tool-assisted Shooting
ユーザー shirokamishirokami
提出日時 2023-07-16 16:10:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 3,177 bytes
コンパイル時間 4,737 ms
コンパイル使用メモリ 321,852 KB
実行使用メモリ 24,480 KB
スコア 20,283
平均クエリ数 159.87
最終ジャッジ日時 2023-07-16 16:10:27
合計ジャッジ時間 12,519 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,676 KB
testcase_01 AC 32 ms
23,652 KB
testcase_02 AC 39 ms
24,336 KB
testcase_03 AC 28 ms
23,388 KB
testcase_04 AC 34 ms
23,544 KB
testcase_05 AC 33 ms
24,276 KB
testcase_06 AC 29 ms
24,372 KB
testcase_07 AC 27 ms
24,048 KB
testcase_08 AC 30 ms
23,844 KB
testcase_09 AC 33 ms
24,048 KB
testcase_10 AC 30 ms
23,628 KB
testcase_11 AC 29 ms
24,036 KB
testcase_12 AC 30 ms
23,400 KB
testcase_13 AC 28 ms
23,844 KB
testcase_14 AC 31 ms
23,628 KB
testcase_15 AC 28 ms
24,036 KB
testcase_16 AC 29 ms
23,424 KB
testcase_17 AC 31 ms
23,412 KB
testcase_18 AC 32 ms
23,544 KB
testcase_19 AC 30 ms
23,424 KB
testcase_20 AC 30 ms
24,036 KB
testcase_21 AC 27 ms
24,036 KB
testcase_22 AC 27 ms
24,324 KB
testcase_23 AC 31 ms
23,628 KB
testcase_24 AC 31 ms
24,024 KB
testcase_25 AC 28 ms
24,252 KB
testcase_26 AC 28 ms
23,544 KB
testcase_27 AC 27 ms
24,048 KB
testcase_28 AC 34 ms
23,388 KB
testcase_29 AC 27 ms
24,036 KB
testcase_30 AC 28 ms
24,120 KB
testcase_31 AC 30 ms
24,336 KB
testcase_32 AC 30 ms
24,036 KB
testcase_33 AC 31 ms
23,424 KB
testcase_34 AC 29 ms
23,604 KB
testcase_35 AC 32 ms
24,348 KB
testcase_36 AC 31 ms
23,436 KB
testcase_37 AC 29 ms
23,424 KB
testcase_38 AC 28 ms
24,036 KB
testcase_39 AC 34 ms
23,664 KB
testcase_40 AC 30 ms
23,856 KB
testcase_41 AC 30 ms
23,544 KB
testcase_42 AC 33 ms
23,532 KB
testcase_43 AC 26 ms
24,480 KB
testcase_44 AC 29 ms
24,048 KB
testcase_45 AC 29 ms
23,856 KB
testcase_46 AC 32 ms
24,048 KB
testcase_47 AC 29 ms
23,544 KB
testcase_48 AC 31 ms
23,436 KB
testcase_49 AC 28 ms
23,832 KB
testcase_50 AC 29 ms
23,676 KB
testcase_51 AC 29 ms
24,036 KB
testcase_52 AC 32 ms
24,048 KB
testcase_53 AC 33 ms
23,832 KB
testcase_54 AC 31 ms
24,408 KB
testcase_55 AC 29 ms
24,036 KB
testcase_56 AC 30 ms
24,276 KB
testcase_57 AC 30 ms
23,652 KB
testcase_58 AC 31 ms
24,060 KB
testcase_59 AC 29 ms
24,264 KB
testcase_60 AC 30 ms
24,348 KB
testcase_61 AC 29 ms
23,376 KB
testcase_62 AC 35 ms
23,544 KB
testcase_63 AC 28 ms
23,400 KB
testcase_64 AC 29 ms
24,264 KB
testcase_65 AC 29 ms
24,036 KB
testcase_66 AC 27 ms
24,336 KB
testcase_67 AC 38 ms
23,376 KB
testcase_68 AC 29 ms
23,832 KB
testcase_69 AC 41 ms
24,396 KB
testcase_70 AC 26 ms
24,036 KB
testcase_71 AC 31 ms
23,544 KB
testcase_72 AC 32 ms
23,424 KB
testcase_73 AC 27 ms
23,640 KB
testcase_74 AC 29 ms
23,856 KB
testcase_75 AC 31 ms
23,868 KB
testcase_76 AC 29 ms
24,384 KB
testcase_77 AC 28 ms
24,384 KB
testcase_78 AC 30 ms
24,324 KB
testcase_79 AC 31 ms
23,244 KB
testcase_80 AC 36 ms
23,436 KB
testcase_81 AC 29 ms
24,336 KB
testcase_82 AC 29 ms
24,396 KB
testcase_83 AC 27 ms
23,532 KB
testcase_84 AC 28 ms
23,616 KB
testcase_85 AC 29 ms
23,844 KB
testcase_86 AC 30 ms
23,532 KB
testcase_87 AC 27 ms
23,388 KB
testcase_88 AC 29 ms
24,336 KB
testcase_89 AC 32 ms
24,024 KB
testcase_90 AC 49 ms
23,664 KB
testcase_91 AC 28 ms
23,388 KB
testcase_92 AC 29 ms
23,436 KB
testcase_93 AC 29 ms
23,640 KB
testcase_94 AC 28 ms
24,012 KB
testcase_95 AC 27 ms
23,544 KB
testcase_96 AC 28 ms
24,048 KB
testcase_97 AC 27 ms
23,640 KB
testcase_98 AC 26 ms
23,544 KB
testcase_99 AC 28 ms
23,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

struct enemy_state {
  int hp;
  int power;
};
struct own_state {
  int x = 12;
  int exp = 0;
  int level = 1;
  char action = 'S';
};
int N; // 敵機の数
int turn = 0; // ターン数
own_state own = own_state(); // 自機の状態
vector<vector<enemy_state>> field(25, vector<enemy_state>(60)); // フィールドの初期化
vector<int> enemy_count(25); // いままでに出現した敵の数

void set_field() {
  for (int i = 0; i < N; ++i) {
    int h, p, x;
    cin >> h >> p >> x;
    field[x][59].hp = h;
    field[x][59].power = p;
    enemy_count[x]++;
  }
}

void move_own() {
  // もしその場に居続けて敵を倒せるなら、その場に居続ける
  for (int i = 1; i < 60; i++) {
    if (field[own.x][i].hp > 0) {
      if (field[own.x][i].hp <= own.level * i) {
        own.action = 'S';
        return;
      }
    }
  }

  // 倒すことができる敵の中で、自機から一番近い敵を倒す
  for (int i = 1; i < 25; i++) {
    int x;
    if (i%2 == 1) {
      x = own.x + i;
      x = x % 25;
    } else {
      x = own.x - i;
      if (x < 0) {
        x = 25 + x;
      }
    }
    for (int j = 0; j < 60; j++) {
      if (field[x][j].hp > 0) {
        if (field[x][j].hp <= own.level * i) {
          if (x > own.x) {
            own.action = 'R';
          } else if (x < own.x) {
            own.action = 'L';
          }
          return;
        }
      }
    }
  }
}

void update_field() {
  // 敵を攻撃
  for (int i = 0; i < 60; i++) {
    // 同じ列に敵がいたら、一番手前の敵だけを攻撃
    if (field[own.x][i].hp > 0) {
      field[own.x][i].hp -= own.level;
      if (field[own.x][i].hp <= 0) {
        own.exp += field[own.x][i].power;
        own.level = 1 + own.exp / 100;
        field[own.x][i].hp = 0;
        field[own.x][i].power = 0;
      }
      break;
    }
  }

  // 下に移動
  for (int i = 0; i < 59; i++) {
    for (int j = 0; j < 25; j++) {
      field[j][i] = field[j][i+1];
    }
  }
  for (int i = 0; i < 25; i++) {
    field[i][59].hp = 0;
    field[i][59].power = 0;
  }

  // 自機の移動
  if (own.action == 'S') {
    own.x = own.x;
  } else if (own.action == 'R') {
    own.x = own.x + 1;
    if (own.x == 25) {
      own.x = 0;
    }
  } else if (own.action == 'L') {
    own.x = own.x - 1;
    if (own.x == -1) {
      own.x = 24;
    }
  }
  cout << own.action << endl;

  // ターンを更新
  turn++;
  if (turn == 1000) {
    exit(0);
  }
}

// デバッグ用
void print_field_hp() {
  for (int i = 0; i < 25; i++) {
    for (int j = 0; j < 60; j++) {
      cout << field[i][j].hp << ' ';
    }
    cout << '\n';
  }
}

void print_field_power() {
  for (int i = 0; i < 25; i++) {
    for (int j = 0; j < 60; j++) {
      cout << field[i][j].power << ' ';
    }
    cout << '\n';
  }
}

int main() {
  while (true) {
    cin >> N;
    if (N == -1) { // 終了
      return 0;
    }

    // 敵が出現
    set_field();

    // 移動
    move_own();

    // ターンを更新
    update_field();

  }
}
0