Skip to content

Commit a826473

Browse files
committed
solved 18869
1 parent ca2b77b commit a826473

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

18000/18869/18869.cpp

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
bool compare(vector<int> a, vector<int> b){
5+
for(int i=0; i<a.size(); ++i){
6+
if(a[i] > b[i]) return true;
7+
else if(a[i] < b[i]) return false;
8+
}
9+
10+
return false;
11+
}
12+
13+
bool isEqual(vector<int> a, vector<int> b){
14+
for(int i=0; i<a.size(); ++i){
15+
if(a[i] != b[i]) return false;
16+
}
17+
18+
return true;
19+
}
20+
21+
int M, N, i, j, primes[10001]={2};
22+
vector<int> planets[100];
23+
24+
bool isPrime(int n){
25+
if(n==2) return true;
26+
if(n%2==0) return false;
27+
28+
for(int i=3;i*i<=n;i+=2){
29+
if(n%i==0) return false;
30+
}
31+
32+
return true;
33+
}
34+
35+
void fill_up_primes(){
36+
int i = 0, cur = 3;
37+
while(i < N){
38+
if(isPrime(cur)) primes[++i] = cur;
39+
cur += 2;
40+
}
41+
}
42+
43+
int main() {
44+
ios::sync_with_stdio(false); cin.tie(NULL);
45+
46+
map<int, int> mm;
47+
48+
cin >> M >> N;
49+
fill_up_primes();
50+
51+
for(i=0;i<M;++i) {
52+
set<int> numbers;
53+
map<int, int> m;
54+
for(j=0; j<N; ++j) {
55+
int t;
56+
cin >> t;
57+
planets[i].push_back(t);
58+
numbers.insert(t);
59+
}
60+
61+
vector<int> unique(numbers.begin(), numbers.end());
62+
sort(unique.begin(), unique.end());
63+
64+
for(j=0; j<unique.size(); ++j){
65+
m[unique[j]] = j;
66+
}
67+
68+
for(j=0; j<N; ++j) {
69+
planets[i][j] = m[planets[i][j]];
70+
}
71+
}
72+
73+
sort(planets, planets+M, compare);
74+
75+
int ans=0;
76+
77+
int t=1;
78+
for(i=0;i<M-1;++i){
79+
if(isEqual(planets[i], planets[i+1])){
80+
t++;
81+
}else{
82+
ans += t * (t-1) / 2;
83+
t=1;
84+
}
85+
}
86+
ans += t * (t-1) / 2;
87+
cout<<ans<<"\n";
88+
89+
return 0;
90+
}

0 commit comments

Comments
 (0)