結果

問題 No.769 UNOシミュレータ
ユーザー Pump0129Pump0129
提出日時 2018-12-25 08:50:18
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 4,737 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 77,740 KB
実行使用メモリ 50,440 KB
最終ジャッジ日時 2024-11-22 08:57:20
合計ジャッジ時間 8,769 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
41,036 KB
testcase_01 AC 126 ms
41,240 KB
testcase_02 AC 127 ms
41,052 KB
testcase_03 AC 127 ms
40,916 KB
testcase_04 AC 136 ms
41,368 KB
testcase_05 AC 133 ms
40,900 KB
testcase_06 AC 135 ms
41,344 KB
testcase_07 AC 135 ms
41,100 KB
testcase_08 AC 135 ms
41,968 KB
testcase_09 AC 172 ms
42,184 KB
testcase_10 AC 182 ms
42,080 KB
testcase_11 AC 192 ms
42,464 KB
testcase_12 AC 271 ms
45,940 KB
testcase_13 AC 272 ms
45,956 KB
testcase_14 AC 270 ms
45,824 KB
testcase_15 AC 318 ms
46,744 KB
testcase_16 AC 320 ms
47,408 KB
testcase_17 AC 314 ms
48,660 KB
testcase_18 AC 351 ms
48,304 KB
testcase_19 AC 356 ms
47,784 KB
testcase_20 AC 349 ms
50,440 KB
testcase_21 AC 356 ms
47,988 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.No769;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class No769 {
    int ans = 0;
    int person_number;
    int log_number;

    BufferedReader reader;

    No769() throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));

        String[] split_str = reader.readLine().split(" ");

        person_number = Integer.parseInt(split_str[0]);
        log_number = Integer.parseInt(split_str[1]);

        int[] ans_array = analyze();

        System.out.printf("%d %d\n", ans_array[0], ans_array[1]);
    }

    private int[] analyze() throws IOException {
        int[] persons_card = new int[person_number];

        int turn_number = 0;
        int drawtwo_acc = 0;
        int drawfour_acc = 0;
        boolean is_reverse = false;

        for (int i = 0; i < log_number; i++) {
            switch (reader.readLine()) {
                case "number":
                    if (0 < drawtwo_acc) {
                        persons_card[turn_number] -= 2 * drawtwo_acc;
                        drawtwo_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    } else if (0 < drawfour_acc) {
                        persons_card[turn_number] -= 4 * drawfour_acc;
                        drawfour_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    }

                    persons_card[turn_number] += 1;
                    break;
                case "drawtwo":
                    if (0 < drawfour_acc) {
                        persons_card[turn_number] -= 4 * drawfour_acc;
                        drawfour_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    }

                    drawtwo_acc += 1;
                    persons_card[turn_number] += 1;
                    break;
                case "drawfour":
                    if (0 < drawtwo_acc) {
                        persons_card[turn_number] -= 2 * drawtwo_acc;
                        drawtwo_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    }

                    drawfour_acc += 1;
                    persons_card[turn_number] += 1;
                    break;
                case "skip":
                    if (0 < drawtwo_acc) {
                        persons_card[turn_number] -= 2 * drawtwo_acc;
                        drawtwo_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    } else if (0 < drawfour_acc) {
                        persons_card[turn_number] -= 4 * drawfour_acc;
                        drawfour_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    }

                    persons_card[turn_number] += 1;
                    turn_number = getNextTurn(turn_number, is_reverse);
                    break;
                case "reverse":
                    if (0 < drawtwo_acc) {
                        persons_card[turn_number] -= 2 * drawtwo_acc;
                        drawtwo_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    } else if (0 < drawfour_acc) {
                        persons_card[turn_number] -= 4 * drawfour_acc;
                        drawfour_acc = 0;
                        turn_number = getNextTurn(turn_number, is_reverse);
                    }

                    is_reverse = !is_reverse;
                    persons_card[turn_number] += 1;
                    break;
            }

            turn_number = getNextTurn(turn_number, is_reverse);
        }

        is_reverse = !is_reverse;
        turn_number = getNextTurn(turn_number, is_reverse);

        return new int[] {turn_number + 1, persons_card[turn_number]};
    }

    private int getNextTurn(int turn, boolean reverse) {
        if (reverse) {
            if (turn == 0) {
                return this.person_number - 1;
            } else {
                return turn - 1;
            }
        } else {
            if (turn == this.person_number - 1) {
                return 0;
            } else {
                return turn + 1;
            }
        }
    }

    public int getAns() {
        return ans;
    }
}

public class Main {
    public static void main(String[] args) {
        try {
            No769 ques = new No769();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
0