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
#include <iostream>
#include <sstream>
#include <bitset>
using namespace std;

class Player
{
public:
   Player(int numOfDecks)
      : m_decksInPlay(numOfDecks)
   {
      for (int i = 0; i < numOfDecks; ++i)
      {
         drawDecks[0].set(i);
         drawDecks[1].set(i);
      }
   }
   void Win(int a, int b)
   {
      winningDecks[0].set(a - 1);
      drawDecks[0].reset(a - 1);
      loosingDecks[1].set(b - 1);
      drawDecks[1].reset(b - 1);
   }
   void Loose(int a, int b)
   {
      loosingDecks[0].set(a - 1);
      drawDecks[0].reset(a - 1);
      winningDecks[1].set(b - 1);
      drawDecks[1].reset(b - 1);
   }
   std::string Result()
   {
      std::string result;
      if ((loosingDecks[0].count() >= m_decksInPlay) || (winningDecks[1].count() >= m_decksInPlay))
         result = "PRZEGRANA";
      else if ((drawDecks[0].count() > 0) || /* (drawDecks[1].count() > 0) || */ (winningDecks[0].count() == winningDecks[1].count()))
         result = "REMIS";
      else if ((winningDecks[0].count() >= m_decksInPlay) || (loosingDecks[1].count() >= m_decksInPlay))
         result = "WYGRANA";
      //else
#if 0
      {
         std::ostringstream uncertainity;
         uncertainity << " D0 = " << drawDecks[0].count() << " W0 = " << winningDecks[0].count() << " L0 = " << loosingDecks[0].count()
                      << " D1 = " << drawDecks[1].count() << " W1 = " << winningDecks[1].count() << " L1 = " << loosingDecks[1].count();
         result.append(uncertainity.str());
      }
#endif
      return result;
   }
private:
   using deck = std::bitset<100000>;
   int m_decksInPlay;
   deck drawDecks[2];
   deck winningDecks[2];
   deck loosingDecks[2];
};

int main()
{
   int tests = 0;
   std::cin >> tests;
   for (int i = 0; i < tests; ++i)
   {
      int decks, pairs;
      std::cin >> decks >> pairs;
      Player player(decks);
      for (int z = 0; z < pairs; ++z)
      {
         int a, b;
         char c;
         std::cin >> a >> c >> b;
         switch (c)
         {
         case '>':
            player.Win(a, b);
            break;
         case '<':
            player.Loose(a, b);
            break;
         default:
            break;
         }
      }
      std::cout << player.Result() << std::endl;
   }
   return 0;
}