結果

問題 No.5017 Tool-assisted Shooting
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-07-16 20:59:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 441 ms / 2,000 ms
コード長 5,779 bytes
コンパイル時間 4,476 ms
コンパイル使用メモリ 76,120 KB
実行使用メモリ 82,504 KB
スコア 3,719,912
平均クエリ数 992.53
最終ジャッジ日時 2023-07-16 21:00:45
合計ジャッジ時間 50,296 ms
ジャッジサーバーID
(参考情報)
judge13 / judge17
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 405 ms
79,964 KB
testcase_01 AC 410 ms
79,480 KB
testcase_02 AC 405 ms
80,304 KB
testcase_03 AC 441 ms
80,352 KB
testcase_04 AC 402 ms
80,040 KB
testcase_05 AC 408 ms
79,524 KB
testcase_06 AC 421 ms
80,088 KB
testcase_07 AC 420 ms
79,840 KB
testcase_08 AC 410 ms
80,060 KB
testcase_09 AC 419 ms
80,212 KB
testcase_10 AC 410 ms
80,408 KB
testcase_11 AC 408 ms
80,872 KB
testcase_12 AC 405 ms
82,504 KB
testcase_13 AC 398 ms
80,488 KB
testcase_14 AC 416 ms
80,176 KB
testcase_15 AC 405 ms
79,716 KB
testcase_16 AC 418 ms
79,548 KB
testcase_17 AC 399 ms
80,252 KB
testcase_18 AC 411 ms
80,220 KB
testcase_19 AC 409 ms
80,400 KB
testcase_20 AC 420 ms
80,188 KB
testcase_21 AC 427 ms
79,460 KB
testcase_22 AC 411 ms
80,244 KB
testcase_23 AC 392 ms
80,528 KB
testcase_24 AC 425 ms
79,968 KB
testcase_25 AC 412 ms
80,276 KB
testcase_26 AC 411 ms
79,856 KB
testcase_27 AC 406 ms
79,652 KB
testcase_28 AC 398 ms
80,336 KB
testcase_29 AC 404 ms
80,192 KB
testcase_30 AC 417 ms
79,712 KB
testcase_31 AC 393 ms
80,024 KB
testcase_32 AC 408 ms
80,640 KB
testcase_33 AC 424 ms
80,644 KB
testcase_34 AC 406 ms
80,620 KB
testcase_35 AC 424 ms
80,348 KB
testcase_36 AC 391 ms
80,204 KB
testcase_37 AC 415 ms
80,844 KB
testcase_38 AC 409 ms
80,608 KB
testcase_39 AC 417 ms
80,160 KB
testcase_40 AC 419 ms
79,880 KB
testcase_41 AC 407 ms
80,756 KB
testcase_42 AC 408 ms
78,060 KB
testcase_43 AC 410 ms
80,372 KB
testcase_44 AC 422 ms
80,176 KB
testcase_45 AC 258 ms
74,812 KB
testcase_46 AC 422 ms
80,936 KB
testcase_47 AC 408 ms
80,344 KB
testcase_48 AC 431 ms
79,904 KB
testcase_49 AC 417 ms
79,816 KB
testcase_50 AC 425 ms
79,580 KB
testcase_51 AC 418 ms
80,308 KB
testcase_52 AC 419 ms
79,932 KB
testcase_53 AC 420 ms
80,052 KB
testcase_54 AC 421 ms
80,152 KB
testcase_55 AC 420 ms
79,924 KB
testcase_56 AC 406 ms
80,136 KB
testcase_57 AC 406 ms
79,784 KB
testcase_58 AC 388 ms
80,308 KB
testcase_59 AC 417 ms
79,796 KB
testcase_60 AC 416 ms
79,568 KB
testcase_61 AC 401 ms
80,544 KB
testcase_62 AC 410 ms
79,920 KB
testcase_63 AC 423 ms
80,272 KB
testcase_64 AC 402 ms
80,092 KB
testcase_65 AC 400 ms
77,276 KB
testcase_66 AC 402 ms
79,992 KB
testcase_67 AC 419 ms
80,500 KB
testcase_68 AC 416 ms
79,628 KB
testcase_69 AC 414 ms
79,612 KB
testcase_70 AC 402 ms
80,108 KB
testcase_71 AC 415 ms
80,340 KB
testcase_72 AC 417 ms
81,792 KB
testcase_73 AC 413 ms
79,540 KB
testcase_74 AC 422 ms
80,264 KB
testcase_75 AC 398 ms
80,192 KB
testcase_76 AC 412 ms
80,368 KB
testcase_77 AC 418 ms
80,028 KB
testcase_78 AC 396 ms
80,328 KB
testcase_79 AC 405 ms
81,084 KB
testcase_80 AC 404 ms
77,612 KB
testcase_81 AC 416 ms
80,008 KB
testcase_82 AC 425 ms
80,352 KB
testcase_83 AC 405 ms
80,592 KB
testcase_84 AC 404 ms
79,948 KB
testcase_85 AC 412 ms
79,916 KB
testcase_86 AC 399 ms
79,836 KB
testcase_87 AC 414 ms
80,668 KB
testcase_88 AC 398 ms
80,180 KB
testcase_89 AC 400 ms
80,256 KB
testcase_90 AC 408 ms
80,624 KB
testcase_91 AC 420 ms
80,340 KB
testcase_92 AC 421 ms
80,620 KB
testcase_93 AC 403 ms
80,324 KB
testcase_94 AC 408 ms
79,928 KB
testcase_95 AC 414 ms
80,636 KB
testcase_96 AC 408 ms
80,336 KB
testcase_97 AC 407 ms
80,460 KB
testcase_98 AC 409 ms
80,080 KB
testcase_99 AC 403 ms
79,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 < 700 ? 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;
    }
}
0