結果

問題 No.5017 Tool-assisted Shooting
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-07-16 20:50:42
言語 Java21
(openjdk 21)
結果
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
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 459 ms
79,992 KB
testcase_01 AC 449 ms
79,876 KB
testcase_02 AC 438 ms
80,636 KB
testcase_03 AC 461 ms
80,264 KB
testcase_04 AC 429 ms
80,444 KB
testcase_05 AC 460 ms
79,740 KB
testcase_06 AC 429 ms
79,592 KB
testcase_07 AC 438 ms
77,860 KB
testcase_08 AC 445 ms
78,160 KB
testcase_09 AC 429 ms
79,868 KB
testcase_10 AC 431 ms
79,836 KB
testcase_11 AC 420 ms
79,788 KB
testcase_12 AC 422 ms
80,352 KB
testcase_13 AC 455 ms
79,360 KB
testcase_14 AC 437 ms
77,324 KB
testcase_15 AC 426 ms
79,356 KB
testcase_16 AC 454 ms
80,100 KB
testcase_17 AC 436 ms
80,320 KB
testcase_18 AC 441 ms
80,256 KB
testcase_19 AC 434 ms
79,776 KB
testcase_20 AC 429 ms
79,940 KB
testcase_21 AC 404 ms
79,496 KB
testcase_22 AC 408 ms
79,600 KB
testcase_23 AC 386 ms
80,756 KB
testcase_24 AC 422 ms
79,860 KB
testcase_25 AC 429 ms
80,208 KB
testcase_26 AC 396 ms
79,720 KB
testcase_27 AC 389 ms
79,388 KB
testcase_28 AC 389 ms
80,456 KB
testcase_29 AC 407 ms
78,388 KB
testcase_30 AC 416 ms
77,968 KB
testcase_31 AC 393 ms
79,668 KB
testcase_32 AC 396 ms
77,568 KB
testcase_33 AC 427 ms
79,908 KB
testcase_34 AC 398 ms
79,992 KB
testcase_35 AC 400 ms
80,472 KB
testcase_36 AC 426 ms
80,264 KB
testcase_37 AC 402 ms
79,768 KB
testcase_38 AC 394 ms
81,140 KB
testcase_39 AC 435 ms
80,140 KB
testcase_40 AC 401 ms
79,984 KB
testcase_41 AC 395 ms
80,204 KB
testcase_42 AC 402 ms
79,540 KB
testcase_43 AC 418 ms
77,896 KB
testcase_44 AC 452 ms
77,076 KB
testcase_45 AC 279 ms
74,532 KB
testcase_46 AC 445 ms
80,332 KB
testcase_47 AC 432 ms
80,156 KB
testcase_48 AC 403 ms
79,832 KB
testcase_49 AC 410 ms
80,272 KB
testcase_50 AC 431 ms
80,728 KB
testcase_51 AC 417 ms
80,020 KB
testcase_52 AC 433 ms
78,348 KB
testcase_53 AC 405 ms
80,032 KB
testcase_54 AC 406 ms
77,956 KB
testcase_55 AC 441 ms
79,556 KB
testcase_56 AC 406 ms
80,440 KB
testcase_57 AC 412 ms
78,952 KB
testcase_58 AC 429 ms
80,060 KB
testcase_59 AC 417 ms
79,604 KB
testcase_60 AC 434 ms
80,188 KB
testcase_61 AC 447 ms
76,620 KB
testcase_62 AC 466 ms
80,004 KB
testcase_63 AC 434 ms
79,180 KB
testcase_64 AC 426 ms
80,220 KB
testcase_65 AC 447 ms
80,356 KB
testcase_66 AC 433 ms
80,180 KB
testcase_67 AC 396 ms
79,804 KB
testcase_68 AC 404 ms
80,016 KB
testcase_69 AC 428 ms
80,240 KB
testcase_70 AC 406 ms
80,428 KB
testcase_71 AC 401 ms
79,524 KB
testcase_72 AC 437 ms
78,780 KB
testcase_73 AC 409 ms
79,820 KB
testcase_74 AC 442 ms
80,652 KB
testcase_75 AC 438 ms
79,788 KB
testcase_76 AC 420 ms
77,780 KB
testcase_77 AC 464 ms
78,240 KB
testcase_78 AC 392 ms
79,576 KB
testcase_79 AC 398 ms
80,724 KB
testcase_80 AC 436 ms
80,076 KB
testcase_81 AC 399 ms
80,128 KB
testcase_82 AC 415 ms
79,468 KB
testcase_83 AC 423 ms
80,292 KB
testcase_84 AC 400 ms
80,404 KB
testcase_85 AC 414 ms
79,804 KB
testcase_86 AC 420 ms
80,360 KB
testcase_87 AC 409 ms
80,540 KB
testcase_88 AC 406 ms
80,092 KB
testcase_89 AC 424 ms
79,564 KB
testcase_90 AC 404 ms
80,356 KB
testcase_91 AC 410 ms
80,400 KB
testcase_92 AC 434 ms
80,044 KB
testcase_93 AC 434 ms
80,572 KB
testcase_94 AC 447 ms
77,964 KB
testcase_95 AC 458 ms
78,496 KB
testcase_96 AC 429 ms
79,560 KB
testcase_97 AC 421 ms
81,768 KB
testcase_98 AC 438 ms
79,748 KB
testcase_99 AC 427 ms
80,064 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 < 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;
    }
}
0