結果

問題 No.5017 Tool-assisted Shooting
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-07-16 17:50:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 534 ms / 2,000 ms
コード長 6,404 bytes
コンパイル時間 3,388 ms
コンパイル使用メモリ 86,384 KB
実行使用メモリ 86,948 KB
スコア 3,594,179
平均クエリ数 3739.81
最終ジャッジ日時 2023-07-16 17:51:43
合計ジャッジ時間 58,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 527 ms
85,036 KB
testcase_01 AC 500 ms
85,772 KB
testcase_02 AC 506 ms
85,088 KB
testcase_03 AC 488 ms
84,516 KB
testcase_04 AC 485 ms
84,260 KB
testcase_05 AC 483 ms
84,304 KB
testcase_06 AC 505 ms
84,996 KB
testcase_07 AC 493 ms
80,644 KB
testcase_08 AC 488 ms
85,136 KB
testcase_09 AC 522 ms
84,392 KB
testcase_10 AC 492 ms
84,600 KB
testcase_11 AC 513 ms
83,600 KB
testcase_12 AC 504 ms
85,064 KB
testcase_13 AC 500 ms
84,768 KB
testcase_14 AC 478 ms
80,664 KB
testcase_15 AC 495 ms
85,420 KB
testcase_16 AC 509 ms
84,364 KB
testcase_17 AC 526 ms
85,696 KB
testcase_18 AC 534 ms
85,652 KB
testcase_19 AC 498 ms
84,404 KB
testcase_20 AC 500 ms
85,020 KB
testcase_21 AC 477 ms
83,816 KB
testcase_22 AC 491 ms
85,712 KB
testcase_23 AC 505 ms
82,796 KB
testcase_24 AC 497 ms
85,396 KB
testcase_25 AC 491 ms
80,136 KB
testcase_26 AC 465 ms
80,608 KB
testcase_27 AC 477 ms
85,152 KB
testcase_28 AC 488 ms
84,952 KB
testcase_29 AC 491 ms
85,552 KB
testcase_30 AC 506 ms
84,952 KB
testcase_31 AC 495 ms
85,128 KB
testcase_32 AC 511 ms
85,140 KB
testcase_33 AC 518 ms
85,208 KB
testcase_34 AC 500 ms
84,180 KB
testcase_35 AC 492 ms
80,440 KB
testcase_36 AC 489 ms
82,628 KB
testcase_37 AC 474 ms
79,924 KB
testcase_38 AC 503 ms
81,624 KB
testcase_39 AC 485 ms
80,024 KB
testcase_40 AC 490 ms
85,188 KB
testcase_41 AC 487 ms
84,612 KB
testcase_42 AC 526 ms
80,900 KB
testcase_43 AC 462 ms
82,444 KB
testcase_44 AC 527 ms
85,508 KB
testcase_45 AC 495 ms
81,952 KB
testcase_46 AC 492 ms
82,468 KB
testcase_47 AC 491 ms
85,068 KB
testcase_48 AC 506 ms
84,768 KB
testcase_49 AC 512 ms
82,560 KB
testcase_50 AC 500 ms
84,992 KB
testcase_51 AC 522 ms
81,724 KB
testcase_52 AC 492 ms
80,108 KB
testcase_53 AC 513 ms
85,376 KB
testcase_54 AC 495 ms
85,744 KB
testcase_55 AC 487 ms
84,992 KB
testcase_56 AC 488 ms
85,132 KB
testcase_57 AC 492 ms
86,476 KB
testcase_58 AC 509 ms
85,320 KB
testcase_59 AC 512 ms
85,088 KB
testcase_60 AC 509 ms
76,536 KB
testcase_61 AC 484 ms
84,656 KB
testcase_62 AC 515 ms
85,092 KB
testcase_63 AC 500 ms
84,916 KB
testcase_64 AC 491 ms
84,772 KB
testcase_65 AC 482 ms
83,672 KB
testcase_66 AC 495 ms
85,224 KB
testcase_67 AC 505 ms
81,776 KB
testcase_68 AC 500 ms
84,832 KB
testcase_69 AC 511 ms
85,372 KB
testcase_70 AC 492 ms
84,932 KB
testcase_71 AC 486 ms
79,536 KB
testcase_72 AC 493 ms
82,320 KB
testcase_73 AC 490 ms
82,696 KB
testcase_74 AC 515 ms
84,840 KB
testcase_75 AC 492 ms
85,464 KB
testcase_76 AC 517 ms
81,092 KB
testcase_77 AC 501 ms
80,300 KB
testcase_78 AC 498 ms
84,760 KB
testcase_79 AC 497 ms
85,356 KB
testcase_80 AC 501 ms
85,436 KB
testcase_81 AC 511 ms
85,436 KB
testcase_82 AC 470 ms
84,780 KB
testcase_83 AC 517 ms
84,892 KB
testcase_84 AC 490 ms
84,392 KB
testcase_85 AC 518 ms
86,948 KB
testcase_86 AC 470 ms
84,740 KB
testcase_87 AC 489 ms
84,652 KB
testcase_88 AC 508 ms
85,816 KB
testcase_89 AC 486 ms
83,440 KB
testcase_90 AC 518 ms
84,936 KB
testcase_91 AC 507 ms
85,176 KB
testcase_92 AC 515 ms
85,064 KB
testcase_93 AC 486 ms
85,132 KB
testcase_94 AC 501 ms
84,840 KB
testcase_95 AC 492 ms
84,868 KB
testcase_96 AC 491 ms
84,900 KB
testcase_97 AC 491 ms
84,712 KB
testcase_98 AC 490 ms
80,424 KB
testcase_99 AC 494 ms
85,288 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 {
                    int 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 = distance(playerX, x) + 1 + board[y][x].h / (1 + sumP / 100);
                            if (turn2 < y) {
                                if (turn2 < best) {
                                    best = turn2;
                                    bestP = board[y][x].p;
                                    bestY = y;
                                    bestX = x;
                                } else if (turn2 == best && board[y][x].p > bestP) {
                                    best = turn2;
                                    bestP = board[y][x].p;
                                    bestY = y;
                                    bestX = x;
                                }
                            }
                            break;
                        }
                    }
                    res.append("#" + Utils.toString("turn", turn, "best", best)).append("\n");
                    res.append("#" + Utils.toString("x", bestX)).append("\n");
                    res.append("#" + Utils.toString("y", bestY)).append("\n");
                    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;
                        res.append("#" + Utils.toString("turn", turn, "H", board[y][playerX].h, "sumP", sumP, "score", score)).append("\n");
                        board[y][playerX] = null;
                    } else {
                        res.append("#" + Utils.toString("turn", turn, "H", board[y][playerX].h, "sumP", sumP, "score", score)).append("\n");
                    }
                    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