結果

問題 No.5017 Tool-assisted Shooting
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-07-16 17:23:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 6,905 bytes
コンパイル時間 3,676 ms
コンパイル使用メモリ 80,028 KB
実行使用メモリ 74,340 KB
スコア 0
平均クエリ数 9.01
最終ジャッジ日時 2023-07-16 17:23:45
合計ジャッジ時間 23,407 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 WA -
testcase_84 WA -
testcase_85 WA -
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;
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) {
                                int count = 0;
                                for (int y2 = y; y2 < Y; y2++) {
                                    if (board[y2][x] != null) {
                                        count += board[y2][x].p;
                                    }
                                }
                                final int evaluation = turn2 * -10000 + count * 10;
                                if (evaluation > best) {
                                    best = evaluation;
                                    bestP = board[y][x].p;
                                    bestY = y;
                                    bestX = x;
                                } else if (evaluation == best && board[y][x].p > bestP) {
                                    best = evaluation;
                                    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;
                        }
                    }
                }
                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());
                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