結果

問題 No.5017 Tool-assisted Shooting
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-07-16 17:43:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 550 ms / 2,000 ms
コード長 6,405 bytes
コンパイル時間 2,538 ms
コンパイル使用メモリ 82,724 KB
実行使用メモリ 87,220 KB
スコア 335,399
平均クエリ数 3706.49
最終ジャッジ日時 2023-07-16 17:44:11
合計ジャッジ時間 57,494 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 483 ms
83,824 KB
testcase_01 AC 499 ms
83,636 KB
testcase_02 AC 485 ms
84,952 KB
testcase_03 AC 495 ms
84,436 KB
testcase_04 AC 484 ms
78,192 KB
testcase_05 AC 486 ms
83,820 KB
testcase_06 AC 499 ms
83,272 KB
testcase_07 AC 487 ms
85,404 KB
testcase_08 AC 510 ms
83,960 KB
testcase_09 AC 379 ms
80,476 KB
testcase_10 AC 478 ms
80,340 KB
testcase_11 AC 497 ms
85,184 KB
testcase_12 AC 484 ms
86,084 KB
testcase_13 AC 518 ms
85,336 KB
testcase_14 AC 495 ms
85,424 KB
testcase_15 AC 519 ms
85,996 KB
testcase_16 AC 459 ms
85,472 KB
testcase_17 AC 488 ms
85,700 KB
testcase_18 AC 482 ms
84,736 KB
testcase_19 AC 489 ms
84,532 KB
testcase_20 AC 528 ms
82,676 KB
testcase_21 AC 374 ms
79,568 KB
testcase_22 AC 485 ms
85,200 KB
testcase_23 AC 514 ms
83,260 KB
testcase_24 AC 494 ms
83,404 KB
testcase_25 AC 506 ms
85,488 KB
testcase_26 AC 491 ms
85,128 KB
testcase_27 AC 502 ms
84,980 KB
testcase_28 AC 456 ms
83,756 KB
testcase_29 AC 489 ms
82,032 KB
testcase_30 AC 486 ms
84,404 KB
testcase_31 AC 489 ms
85,124 KB
testcase_32 AC 502 ms
85,564 KB
testcase_33 AC 445 ms
80,268 KB
testcase_34 AC 506 ms
85,204 KB
testcase_35 AC 495 ms
85,548 KB
testcase_36 AC 485 ms
85,208 KB
testcase_37 AC 474 ms
84,160 KB
testcase_38 AC 490 ms
83,356 KB
testcase_39 AC 503 ms
84,992 KB
testcase_40 AC 490 ms
84,780 KB
testcase_41 AC 478 ms
83,516 KB
testcase_42 AC 508 ms
84,440 KB
testcase_43 AC 482 ms
84,640 KB
testcase_44 AC 505 ms
83,832 KB
testcase_45 AC 483 ms
85,076 KB
testcase_46 AC 508 ms
84,756 KB
testcase_47 AC 483 ms
78,092 KB
testcase_48 AC 486 ms
85,080 KB
testcase_49 AC 483 ms
82,272 KB
testcase_50 AC 476 ms
83,376 KB
testcase_51 AC 550 ms
85,660 KB
testcase_52 AC 278 ms
77,052 KB
testcase_53 AC 494 ms
84,968 KB
testcase_54 AC 496 ms
85,404 KB
testcase_55 AC 469 ms
85,064 KB
testcase_56 AC 499 ms
85,304 KB
testcase_57 AC 493 ms
84,540 KB
testcase_58 AC 518 ms
85,128 KB
testcase_59 AC 494 ms
85,724 KB
testcase_60 AC 495 ms
84,940 KB
testcase_61 AC 493 ms
85,736 KB
testcase_62 AC 465 ms
80,036 KB
testcase_63 AC 496 ms
85,304 KB
testcase_64 AC 297 ms
79,180 KB
testcase_65 AC 496 ms
84,972 KB
testcase_66 AC 490 ms
84,800 KB
testcase_67 AC 493 ms
82,964 KB
testcase_68 AC 498 ms
80,268 KB
testcase_69 AC 465 ms
80,272 KB
testcase_70 AC 520 ms
85,328 KB
testcase_71 AC 489 ms
83,188 KB
testcase_72 AC 491 ms
87,220 KB
testcase_73 AC 498 ms
85,396 KB
testcase_74 AC 482 ms
86,508 KB
testcase_75 AC 485 ms
80,956 KB
testcase_76 AC 494 ms
84,932 KB
testcase_77 AC 515 ms
80,476 KB
testcase_78 AC 490 ms
84,460 KB
testcase_79 AC 500 ms
85,444 KB
testcase_80 AC 500 ms
85,072 KB
testcase_81 AC 507 ms
85,492 KB
testcase_82 AC 501 ms
84,680 KB
testcase_83 AC 512 ms
84,028 KB
testcase_84 AC 503 ms
84,732 KB
testcase_85 AC 496 ms
84,060 KB
testcase_86 AC 400 ms
81,480 KB
testcase_87 AC 500 ms
84,952 KB
testcase_88 AC 482 ms
81,548 KB
testcase_89 AC 491 ms
84,436 KB
testcase_90 AC 482 ms
80,224 KB
testcase_91 AC 499 ms
84,480 KB
testcase_92 AC 484 ms
84,364 KB
testcase_93 AC 530 ms
84,676 KB
testcase_94 AC 465 ms
84,368 KB
testcase_95 AC 486 ms
85,152 KB
testcase_96 AC 426 ms
82,896 KB
testcase_97 AC 484 ms
80,400 KB
testcase_98 AC 495 ms
83,064 KB
testcase_99 AC 493 ms
82,704 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