結果
問題 | No.5017 Tool-assisted Shooting |
ユーザー |
![]() |
提出日時 | 2023-07-16 20:50:42 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 466 ms / 2,000 ms |
コード長 | 5,779 bytes |
コンパイル時間 | 3,177 ms |
コンパイル使用メモリ | 76,604 KB |
実行使用メモリ | 81,768 KB |
スコア | 3,830,033 |
平均クエリ数 | 992.53 |
最終ジャッジ日時 | 2023-07-16 20:51:38 |
合計ジャッジ時間 | 53,993 ms |
ジャッジサーバーID (参考情報) |
judge17 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
import java.util.Arrays;import java.util.Scanner;public final class Main {private static final int maxTurn = 1000;private static final int Y = 60;private static final int X = 25;public static final void main(final String[] args) {new Main().run();}private void run() {Enemy[][] board = new Enemy[Y + 1][X];int playerX = 12;int sumP = 0;int score = 0;try (final Scanner in = new Scanner(System.in)) {for (int turn = 0; turn < maxTurn; turn++) {StringBuilder res = new StringBuilder();for (int x = 0; x < X; x++) {for (int y = 0; y < Y; y++) {board[y][x] = board[y + 1][x];}board[Y][x] = null;}int n = in.nextInt();if (n < 0) {break;}for (int i = 0; i < n; i++) {int h = in.nextInt();int p = in.nextInt();int x = in.nextInt();board[Y - 1][x] = new Enemy(h, p);}if (isUnderAttack(board, playerX)) {res.append("S").append("\n");} else {double best = -(int) 1e9;int bestP = (int) 1e9;int bestY = (int) 1e9;int bestX = (int) 1e9;for (int x = 0; x < 25; x++) {for (int y = 0; y < 60; y++) {if (board[y][x] == null) {continue;}final int turn2 = Math.max(0, distance(playerX, x) - 1) + (board[y][x].h % (1 + sumP / 100) == 0 ? 0 : 1) + board[y][x].h/ (1 + sumP / 100);if (turn2 < y) {final double evaluation = (turn < 800 ? board[y][x].p : board[y][x].h) / (double) turn2;if (evaluation > best) {best = evaluation;bestP = board[y][x].p;bestY = y;bestX = x;}}break;}}if (board[0][playerX] == null && board[1][playerX] == null && playerX == bestX) {res.append("S").append("\n");} else if (board[0][(playerX - 1 + 25) % 25] == null && board[1][(playerX - 1 + 25) % 25] == null && distance((playerX - 1 + 25)% 25, bestX) < distance((playerX + 1) % 25, bestX)) {res.append("L").append("\n");playerX = (playerX - 1 + 25) % 25;} else if (board[0][(playerX + 1) % 25] == null && board[1][(playerX + 1) % 25] == null && distance((playerX - 1 + 25) % 25,bestX) > distance((playerX + 1) % 25, bestX)) {res.append("R").append("\n");playerX = (playerX + 1) % 25;} else {if (board[0][playerX] == null && board[1][playerX] == null) {res.append("S").append("\n");} else if (board[0][(playerX - 1 + 25) % 25] == null && board[1][(playerX - 1 + 25) % 25] == null) {res.append("L").append("\n");playerX = (playerX - 1 + 25) % 25;} else if (board[0][(playerX + 1) % 25] == null && board[1][(playerX + 1) % 25] == null) {res.append("R").append("\n");playerX = (playerX + 1) % 25;} else {res.append("S").append("\n");}}}int level = 1 + sumP / 100;for (int y = 0; y < 60; y++) {if (board[y][playerX] == null) {continue;}board[y][playerX].h -= level;if (board[y][playerX].h <= 0) {sumP += board[y][playerX].p;score += board[y][playerX].h0;board[y][playerX] = null;} else {}break;}System.out.println(res.toString().trim());System.out.flush();}}}private boolean isUnderAttack(Enemy[][] board, int x) {for (int y = 0; y < 60; y++) {if (board[y][x] == null) {continue;}if (board[y][x].h != board[y][x].h0) {if (board[y][x].h < y) {return true;}}break;}return false;}private int distance(int x, int x2) {return Math.min(Math.abs(x - x2), Math.abs((x + 25) - x2));}}class Enemy {int h;int h0;int p;Enemy(int h, int p) {this.h = h;this.h0 = h;this.p = p;}}class Utils {private Utils() {}public static final void debug(Object... o) {System.err.println(toString(o));System.err.flush();}public static final String toString(Object... o) {return Arrays.deepToString(o);}public static boolean isValid(int v, int min, int minUpper) {return v >= min && v < minUpper;}}