-
Notifications
You must be signed in to change notification settings - Fork 0
/
cow-gymnastics.cpp
59 lines (49 loc) · 1.32 KB
/
cow-gymnastics.cpp
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
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("gymnastics.in", "r", stdin);
freopen("gymnastics.out", "w", stdout);
int k, n;
cin >> k >> n;
vector<vector<int>> rankings;
for(int i = 0; i < k; i++) {
vector<int> newVector;
for(int j = 0; j < n; j++) {
int val;
cin >> val;
newVector.push_back(val);
}
rankings.push_back(newVector);
}
/*
for(auto rank : rankings) {
for(auto element : rank)
cout << element << " ";
cout << endl;
}
*/
unordered_set<string> consistentPairs;
for(int a = 0; a < rankings.size(); a++) {
auto rank = rankings[a];
for(int i = 0; i < rank.size(); i++) {
for(int j = i + 1; j < rank.size(); j++) {
string order = to_string(rank[i]) + "," + to_string(rank[j]);
string reverse = to_string(rank[j]) + "," + to_string(rank[i]);
if(consistentPairs.find(order) == consistentPairs.end() && consistentPairs.find(reverse) != consistentPairs.end()) {
consistentPairs.erase(reverse);
} else if(a == 0 && consistentPairs.find(order) == consistentPairs.end()){
consistentPairs.insert(order);
}
}
}
/*
for(auto it = consistentPairs.begin(); it != consistentPairs.end(); it++) {
cout << *it << " ";
}
cout << endl;
*/
}
cout << consistentPairs.size() << endl;
return 0;
}