結果

問題 No.769 UNOシミュレータ
ユーザー Pump0129Pump0129
提出日時 2018-12-25 08:49:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,756 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 76,436 KB
実行使用メモリ 46,484 KB
最終ジャッジ日時 2024-11-22 08:57:11
合計ジャッジ時間 6,827 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
権限があれば一括ダウンロードができます

ソースコード

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.println(ans_array[0]);
        System.out.println(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