結果

問題 No.5017 Tool-assisted Shooting
ユーザー allegrogikenallegrogiken
提出日時 2023-07-16 18:48:17
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 4,652 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 101,996 KB
実行使用メモリ 24,336 KB
スコア 3,994,308
平均クエリ数 1000.00
最終ジャッジ日時 2023-07-16 18:49:20
合計ジャッジ時間 15,172 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
24,300 KB
testcase_01 AC 78 ms
24,324 KB
testcase_02 AC 93 ms
23,796 KB
testcase_03 AC 75 ms
23,412 KB
testcase_04 AC 74 ms
23,652 KB
testcase_05 AC 75 ms
24,216 KB
testcase_06 AC 75 ms
23,412 KB
testcase_07 AC 72 ms
23,352 KB
testcase_08 AC 73 ms
24,252 KB
testcase_09 AC 77 ms
24,276 KB
testcase_10 AC 76 ms
23,472 KB
testcase_11 AC 74 ms
24,024 KB
testcase_12 AC 78 ms
23,328 KB
testcase_13 AC 76 ms
23,496 KB
testcase_14 AC 76 ms
23,628 KB
testcase_15 AC 77 ms
24,180 KB
testcase_16 AC 76 ms
24,204 KB
testcase_17 AC 76 ms
24,216 KB
testcase_18 AC 74 ms
23,388 KB
testcase_19 AC 78 ms
24,264 KB
testcase_20 AC 75 ms
23,328 KB
testcase_21 AC 76 ms
23,376 KB
testcase_22 AC 77 ms
23,784 KB
testcase_23 AC 74 ms
23,376 KB
testcase_24 AC 75 ms
23,592 KB
testcase_25 AC 75 ms
23,484 KB
testcase_26 AC 73 ms
23,616 KB
testcase_27 AC 74 ms
24,324 KB
testcase_28 AC 75 ms
24,312 KB
testcase_29 AC 76 ms
23,616 KB
testcase_30 AC 80 ms
24,300 KB
testcase_31 AC 75 ms
23,580 KB
testcase_32 AC 84 ms
23,472 KB
testcase_33 AC 76 ms
23,964 KB
testcase_34 AC 76 ms
24,228 KB
testcase_35 AC 76 ms
23,580 KB
testcase_36 AC 74 ms
23,832 KB
testcase_37 AC 76 ms
23,988 KB
testcase_38 AC 75 ms
23,424 KB
testcase_39 AC 76 ms
23,844 KB
testcase_40 AC 75 ms
23,844 KB
testcase_41 AC 75 ms
23,328 KB
testcase_42 AC 78 ms
23,796 KB
testcase_43 AC 76 ms
23,964 KB
testcase_44 AC 77 ms
23,352 KB
testcase_45 AC 77 ms
23,460 KB
testcase_46 AC 77 ms
23,496 KB
testcase_47 AC 75 ms
23,784 KB
testcase_48 AC 76 ms
23,340 KB
testcase_49 AC 74 ms
24,000 KB
testcase_50 AC 77 ms
24,216 KB
testcase_51 AC 76 ms
23,592 KB
testcase_52 AC 76 ms
24,036 KB
testcase_53 AC 76 ms
24,012 KB
testcase_54 AC 76 ms
23,532 KB
testcase_55 AC 76 ms
24,324 KB
testcase_56 AC 75 ms
23,304 KB
testcase_57 AC 74 ms
24,336 KB
testcase_58 AC 77 ms
23,976 KB
testcase_59 AC 76 ms
24,060 KB
testcase_60 AC 89 ms
24,312 KB
testcase_61 AC 78 ms
23,400 KB
testcase_62 AC 75 ms
24,036 KB
testcase_63 AC 75 ms
24,024 KB
testcase_64 AC 76 ms
23,328 KB
testcase_65 AC 78 ms
24,036 KB
testcase_66 AC 75 ms
23,640 KB
testcase_67 AC 74 ms
24,228 KB
testcase_68 AC 76 ms
23,376 KB
testcase_69 AC 74 ms
23,472 KB
testcase_70 AC 75 ms
24,264 KB
testcase_71 AC 77 ms
23,820 KB
testcase_72 AC 74 ms
23,844 KB
testcase_73 AC 76 ms
23,616 KB
testcase_74 AC 73 ms
24,036 KB
testcase_75 AC 76 ms
24,264 KB
testcase_76 AC 76 ms
24,000 KB
testcase_77 AC 76 ms
24,216 KB
testcase_78 AC 76 ms
24,216 KB
testcase_79 AC 74 ms
23,484 KB
testcase_80 AC 76 ms
24,324 KB
testcase_81 AC 76 ms
24,060 KB
testcase_82 AC 74 ms
23,796 KB
testcase_83 AC 75 ms
23,520 KB
testcase_84 AC 76 ms
24,312 KB
testcase_85 AC 76 ms
24,048 KB
testcase_86 AC 75 ms
23,976 KB
testcase_87 AC 75 ms
23,604 KB
testcase_88 AC 75 ms
24,012 KB
testcase_89 AC 74 ms
23,652 KB
testcase_90 AC 77 ms
23,364 KB
testcase_91 AC 76 ms
23,340 KB
testcase_92 AC 73 ms
24,300 KB
testcase_93 AC 74 ms
23,496 KB
testcase_94 AC 74 ms
24,036 KB
testcase_95 AC 75 ms
23,580 KB
testcase_96 AC 77 ms
24,288 KB
testcase_97 AC 77 ms
23,412 KB
testcase_98 AC 74 ms
24,252 KB
testcase_99 AC 74 ms
23,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main() { runSolver(); }

// ----------------------------------------------

void problem() {
  enum TURNS = 1000;
  enum AREA_Y = 60;
  enum AREA_X = 25;

  auto enemy_h = new int[][](TURNS + AREA_Y, AREA_X);
  auto enemy_s = new int[][](TURNS + AREA_Y, AREA_X);
  auto enemy_p = new int[][](TURNS + AREA_Y, AREA_X);

  int[2] calcDistance(int cur, int goal) {
    if (cur == goal) return [0, 0];

    if (cur < goal) {
      const d1 = goal - cur;
      const d2 = AREA_X + cur - goal;
      return d1 <= d2 ? [d1, 1] : [d2, -1];
    } else {
      const d1 = cur - goal;
      const d2 = AREA_X - cur + goal;
      return d1 <= d2 ? [d1, -1] : [d2, 1];
    }
  }

  long score, exp;
  long power = 1;
  int cur = 12, target = -1, targetY;

  foreach(y; 0..TURNS) {
    const N = scan!int;
    if (N == -1) break;

    foreach(_; 0..N) {
      auto H = scan!int;
      auto P = scan!int;
      auto X = scan!int;

      enemy_h[AREA_Y + y][X] = H;
      enemy_s[AREA_Y + y][X] = H;
      enemy_p[AREA_Y + y][X] = P;
    }

    if (target == -1 || target != cur) {
      long best = -1;

      foreach(x; 0..AREA_X) {
        const calced = calcDistance(cur, x);
        const dist = max(0, calced[0] - 1);
        foreach(dy; y + 1..y + AREA_Y) {
          const hp = enemy_h[dy][x];
          if (hp <= 0) continue;

          if (dy - y + 1 <= dist) continue;

          // 最短で行っても倒せない
          const attacks = 1 + (hp + power - 1) / power;
          if (attacks > dy - y - dist) break;

          // 途中でぶつかる
          bool canWalk = true;
          foreach(offset; 0..2) {
            auto simX = cur;
            auto simY = y + offset;
            while(simX != x) {
              if (enemy_h[simY][simX] > 0) {
                canWalk = false;
                break;
              }
              simY++;
              simX += calced[1];
              simX = (simX + AREA_X) % AREA_X;
            }
          }
          if (!canWalk) break;
          
          const perf = enemy_p[dy][x] * 1_000_000 / max(1, (attacks + dist)^^2);
          if (chmax(best, perf)) {
            target = x;
            targetY = dy;
          }

          break;
        }
      }
    }
    
    if (target == -1) {
      "S".writeln;
    } else {
      deb([cur, y], [target, targetY - y, enemy_h[targetY][target], enemy_p[targetY][target]]);

      if (enemy_h[y][cur] > 0) {
        "CRASH!".deb;
        return;
      }

      auto d = calcDistance(cur, target);
      // d.deb;
      writeln(d[1] == -1 ? "L" : d[1] == 0 ? "S" : "R");
      cur += d[1];
      cur = (cur + AREA_X) % AREA_X;

      if (cur == target) {
        enemy_h[targetY][target] -= power;
        if (enemy_h[targetY][target] <= 0) {
          score += enemy_s[targetY][target];
          exp += enemy_p[targetY][target];
          power = 1 + (exp / 100);
          target = -1;
        }
      }
    }
    stdout.flush;
  }

  score.deb;
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop, std.random;
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug { write("#"); writeln(t); }}
T[] divisors(T)(T n) { T[] ret; for (T i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  problem();
}
enum YESNO = [true: "Yes", false: "No"];
0