여러 개의 우주들과 각 우주 속 행성의 크기가 주어졌을 때, 같은 패턴의 행성을 가지고 있는 우주 쌍의 개수 구하기
#include <bits/stdc++.h>
using namespace std;
int m, n;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
map<vector<int>, int> freq;
cin >> m >> n;
for(int i = 0; i < m; i++){
vector<int> x(n), sorted;
for(int j = 0; j < n; j++){
cin >> x[j];
sorted.push_back(x[j]);
}
sort(sorted.begin(), sorted.end());
sorted.erase(unique(sorted.begin(), sorted.end()), sorted.end());
vector<int> compressed;
for(int j = 0; j < n; j++){
compressed.push_back(lower_bound(sorted.begin(), sorted.end(), x[j]) - sorted.begin());
}
freq[compressed]++;
}
int ans = 0;
for (auto& [key, cnt] : freq) {
ans += cnt * (cnt - 1) / 2;
}
cout << ans;
}