import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Comparator; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.TreeSet; public class kar { public static class Pair { private int key; private int value; public Pair(int key, int value) { this.key = key; this.value = value; } public int getKey() { return key; } public int getValue() { return value; } } public static class Triplet { private int first; private int second; private int third; public Triplet(int first, int second, int third) { this.first = first; this.second = second; this.third = third; } public int getFirst() { return first; } public int getSecond() { return second; } public int getThird() { return third; } } public static class PairComparatorPositive implements Comparator<Triplet> { @Override public int compare(Triplet t0, Triplet t1) { return t0.getFirst() < t1.getFirst() ? -1 : t0.getFirst() > t1.getFirst() ? 1 : -Integer.compare(t0.getSecond(), t1.getSecond()); } } public static class PairComparatorNegative implements Comparator<Triplet> { @Override public int compare(Triplet t0, Triplet t1) { return t0.getFirst() < t1.getFirst() ? 1 : t0.getFirst() > t1.getFirst() ? -1 : -Integer.compare(t0.getSecond(), t1.getSecond()); } } @SuppressWarnings("unchecked") public static void main(String[] args) { try { BufferedReader buffReader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenzier = new StringTokenizer(buffReader.readLine()); int t = Integer.parseInt(tokenzier.nextToken()); for(int testNumber = 0; testNumber < t; testNumber++){ tokenzier = new StringTokenizer(buffReader.readLine()); int n = Integer.parseInt(tokenzier.nextToken()); int m = Integer.parseInt(tokenzier.nextToken()); int[] sumX = new int[n]; int[] sumY = new int[n]; int[] sumAbsX = new int[n]; int[] sumAbsY = new int[n]; int negSignY[] = new int[n]; int posSignX[] = new int[n]; LinkedList<Pair>[] cardPairsX = new LinkedList[n]; LinkedList<Pair>[] cardPairsY = new LinkedList[n]; for(int i = 0; i < n; i++){ cardPairsX[i] = new LinkedList<Pair>(); cardPairsY[i] = new LinkedList<Pair>(); } for(int i = 0; i < m; i++){ tokenzier = new StringTokenizer(buffReader.readLine()); int x = Integer.parseInt(tokenzier.nextToken()) - 1; int sign = tokenzier.nextToken().charAt(0) == '>' ? 1 : -1; int y = Integer.parseInt(tokenzier.nextToken()) - 1; sumX[x] += sign; sumY[y] += sign; sumAbsX[x] += 1; sumAbsY[y] += 1; if(sign < 0) negSignY[y] = 1; else posSignX[x] += 1; cardPairsX[x].add(new Pair(y, sign)); cardPairsY[y].add(new Pair(x, sign)); } TreeSet<Integer> lengthPairsY = new TreeSet<Integer>(); int negSignCount = 0; for(int i = 0; i < n; i++){ negSignCount += negSignY[i]; if(negSignY[i] > 0){ for(Pair cardPair : cardPairsY[i]){ if(cardPair.getValue() > 0) posSignX[cardPair.getKey()] -= 1; } }else{ lengthPairsY.add(-cardPairsY[i].size()); } } String result = "PRZEGRANA"; if(negSignCount < n){ int posSignCount = 0; for(int i = 0; i < n; i++){ if(posSignX[i] > 0) posSignCount += 1; } result = "REMIS"; if(posSignCount == n && lengthPairsY.first() == -n) result = "WYGRANA"; } System.out.println(result); } } catch (Exception e) { e.printStackTrace(); } } }
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Comparator; import java.util.LinkedList; import java.util.StringTokenizer; import java.util.TreeSet; public class kar { public static class Pair { private int key; private int value; public Pair(int key, int value) { this.key = key; this.value = value; } public int getKey() { return key; } public int getValue() { return value; } } public static class Triplet { private int first; private int second; private int third; public Triplet(int first, int second, int third) { this.first = first; this.second = second; this.third = third; } public int getFirst() { return first; } public int getSecond() { return second; } public int getThird() { return third; } } public static class PairComparatorPositive implements Comparator<Triplet> { @Override public int compare(Triplet t0, Triplet t1) { return t0.getFirst() < t1.getFirst() ? -1 : t0.getFirst() > t1.getFirst() ? 1 : -Integer.compare(t0.getSecond(), t1.getSecond()); } } public static class PairComparatorNegative implements Comparator<Triplet> { @Override public int compare(Triplet t0, Triplet t1) { return t0.getFirst() < t1.getFirst() ? 1 : t0.getFirst() > t1.getFirst() ? -1 : -Integer.compare(t0.getSecond(), t1.getSecond()); } } @SuppressWarnings("unchecked") public static void main(String[] args) { try { BufferedReader buffReader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenzier = new StringTokenizer(buffReader.readLine()); int t = Integer.parseInt(tokenzier.nextToken()); for(int testNumber = 0; testNumber < t; testNumber++){ tokenzier = new StringTokenizer(buffReader.readLine()); int n = Integer.parseInt(tokenzier.nextToken()); int m = Integer.parseInt(tokenzier.nextToken()); int[] sumX = new int[n]; int[] sumY = new int[n]; int[] sumAbsX = new int[n]; int[] sumAbsY = new int[n]; int negSignY[] = new int[n]; int posSignX[] = new int[n]; LinkedList<Pair>[] cardPairsX = new LinkedList[n]; LinkedList<Pair>[] cardPairsY = new LinkedList[n]; for(int i = 0; i < n; i++){ cardPairsX[i] = new LinkedList<Pair>(); cardPairsY[i] = new LinkedList<Pair>(); } for(int i = 0; i < m; i++){ tokenzier = new StringTokenizer(buffReader.readLine()); int x = Integer.parseInt(tokenzier.nextToken()) - 1; int sign = tokenzier.nextToken().charAt(0) == '>' ? 1 : -1; int y = Integer.parseInt(tokenzier.nextToken()) - 1; sumX[x] += sign; sumY[y] += sign; sumAbsX[x] += 1; sumAbsY[y] += 1; if(sign < 0) negSignY[y] = 1; else posSignX[x] += 1; cardPairsX[x].add(new Pair(y, sign)); cardPairsY[y].add(new Pair(x, sign)); } TreeSet<Integer> lengthPairsY = new TreeSet<Integer>(); int negSignCount = 0; for(int i = 0; i < n; i++){ negSignCount += negSignY[i]; if(negSignY[i] > 0){ for(Pair cardPair : cardPairsY[i]){ if(cardPair.getValue() > 0) posSignX[cardPair.getKey()] -= 1; } }else{ lengthPairsY.add(-cardPairsY[i].size()); } } String result = "PRZEGRANA"; if(negSignCount < n){ int posSignCount = 0; for(int i = 0; i < n; i++){ if(posSignX[i] > 0) posSignCount += 1; } result = "REMIS"; if(posSignCount == n && lengthPairsY.first() == -n) result = "WYGRANA"; } System.out.println(result); } } catch (Exception e) { e.printStackTrace(); } } } |