結果

問題 No.769 UNOシミュレータ
ユーザー KiYugadgeterKiYugadgeter
提出日時 2019-03-31 12:43:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,742 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 75,368 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 00:33:32
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 28 ms
6,940 KB
testcase_13 AC 27 ms
6,940 KB
testcase_14 AC 27 ms
6,940 KB
testcase_15 AC 52 ms
6,940 KB
testcase_16 AC 54 ms
6,944 KB
testcase_17 AC 55 ms
6,944 KB
testcase_18 AC 83 ms
6,940 KB
testcase_19 AC 84 ms
6,944 KB
testcase_20 AC 83 ms
6,944 KB
testcase_21 AC 80 ms
6,944 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

class player {
    public:
        int num;
        int current_player;
        bool is_reverse;

        bool toggle() {
            if (is_reverse)
                is_reverse = false;
            else
                is_reverse = true;
            return is_reverse;
        }
        void prev() {
            if (!is_reverse) {
                if (current_player - 1 < 0) {
                    current_player = num - 1;
                    return;
                }
                current_player--;
            }
            else {
                if (current_player + 1 > num - 1) {
                    current_player = 0;
                    return;
                }
                current_player++;
            }
        }
        void next() {
            if (!is_reverse) {
                if (current_player + 1 > num - 1) {
                    current_player = 0;
                    return;
                }
                current_player++;
            }
            else {
                if (current_player - 1 < 0) {
                    current_player = num - 1;
                    return;
                }
                current_player--;
            }
        }
        player(int num) : is_reverse(false), num(num) {}
};
class Uno {
    public:
        std::vector<int> card_num;
        int player_num;
        int log_num;
        player pobj;
        int drawfour;
        int drawtwo;
        Uno(int player_num, int log_num) : player_num(player_num), log_num(log_num), pobj(player_num), drawfour(0), drawtwo(0) {
            for (int x = 0; x < player_num; x++) {
                card_num.push_back(0);
            }
        }
        void draw() {
            if (drawfour != 0) {
                card_num[pobj.current_player] += drawfour;
                drawfour = 0;
                pobj.next();

            }
            else if (drawtwo != 0) {
                card_num[pobj.current_player] += drawtwo;
                drawtwo = 0;
                pobj.next();
            }
        }
        void turn(std::string s) {
            if (s == "reverse") {
                draw();
                card_num[pobj.current_player] -= 1;
                pobj.toggle();
                pobj.next();
            }
            else if (s == "number") {
                draw();
                card_num[pobj.current_player] -= 1;
                pobj.next();
            }
            else if (s == "skip") {
                draw();
                card_num[pobj.current_player] -= 1;
                pobj.next();
                pobj.next();
            }
            else if (s == "drawfour") {
                if (drawtwo) {
                    card_num[pobj.current_player] += drawtwo;
                    drawtwo = 0;
                    pobj.next();
                }
                card_num[pobj.current_player] -= 1;
                drawfour += 4;
                pobj.next();
            }
            else if (s == "drawtwo") {
                if (drawfour) {
                    card_num[pobj.current_player] += drawfour;
                    drawfour = 0;
                    pobj.next();
                }
                card_num[pobj.current_player] -= 1;
                drawtwo += 2;
                pobj.next();
            }
        }
};

int main() {
    std::string str;
    int player_num, log_num;
    std::cin >> player_num >> log_num;
    Uno u(player_num, log_num);
    for (int i = 0; i < log_num; i++) {
        std::cin >> str;
        u.turn(str);
    }
    u.pobj.prev();
    auto winner = u.pobj.current_player + 1;
    auto w = u.card_num[u.pobj.current_player] * -1;



    std::cout << winner << " " << w << std::endl;
}
0