1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
#include <iostream>
#include <vector>

enum class Result
{
    Draw,
    First,
    Second
};

class Hearthstone
{
    public:
        Hearthstone(std::size_t n_)
            : n(n_), secondMatchups(n_, 0), drawMatchups(n_, n_)
        {

        }
        void addFirst(std::size_t secondDeck)
        {
            drawMatchups[secondDeck]--;
        }
        void addSecond(std::size_t secondDeck)
        {
            drawMatchups[secondDeck]--;
            secondMatchups[secondDeck]++;
        }
        Result getResult()
        {
            bool canWin = true, canDraw = true;
            for (std::size_t i = 0; i < n && (canWin || canDraw); i++)
            {
                if (secondMatchups[i] <= 0)
                {
                    canWin = false;
                    if (drawMatchups[i] <= 0)
                    {
                        canDraw = false;
                    }
                }
            }

            if (canWin)
            {
                return Result::Second;
            }
            else if (canDraw)
            {
                return Result::Draw;
            }
            else
            {
                return Result::First;
            }
        }
    private:
        std::size_t n;
        std::vector<std::size_t> secondMatchups; // [n] <=> ilość talii Bajtka
            // z którymi wygrywa n-ta talia Bitka
        std::vector<std::size_t> drawMatchups;   // [n] <=> ilość talii Bajtka
            // z którymi remisuje n-ta talia Bitka
};

int main()
{
    std::uint_fast16_t t;
    std::cin >> t;
    for (std::uint_fast16_t i = 0; i < t; i++)
    {
        std::size_t n;
        std::cin >> n;
        Hearthstone game(n);
        std::uint_fast32_t m;
        std::cin >> m;
        for (std::uint_fast32_t j = 0; j < m; j++)
        {
            std::size_t a, b;
            char w;
            std::cin >> a >> w >> b;
            if (w == '>')
            {
                game.addFirst(b - 1);
            }
            else
            {
                game.addSecond(b - 1);
            }
        }
        switch (game.getResult())
        {
            case Result::First:
                std::cout << "WYGRANA\n";
                break;
            case Result::Draw:
                std::cout << "REMIS\n";
                break;
            case Result::Second:
                std::cout << "PRZEGRANA\n";
                break;
        }
    }
}