File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static void main (String [] args ) throws IOException {
7+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
8+ StringTokenizer st = new StringTokenizer (br. readLine());
9+
10+ int M = Integer . parseInt(st. nextToken());
11+ int N = Integer . parseInt(st. nextToken());
12+
13+ List<List<Integer > > spaces = new ArrayList<> ();
14+
15+ for (int i = 0 ; i < M ; i++ ) {
16+ st = new StringTokenizer (br. readLine());
17+ List<Integer > space = new ArrayList<> ();
18+ Set<Integer > set = new HashSet<> ();
19+
20+ for (int j = 0 ; j < N ; j++ ) {
21+ int planet = Integer . parseInt(st. nextToken());
22+ set. add(planet);
23+ space. add(planet);
24+ }
25+
26+ List<Integer > sorted = new ArrayList<> (set);
27+ Collections . sort(sorted);
28+
29+ for (int j = 0 ; j < N ; j++ ) {
30+ int idx = Collections . binarySearch(sorted, space. get(j));
31+ space. set(j, idx);
32+ }
33+ spaces. add(space);
34+ }
35+
36+ int answer = 0 ;
37+ for (int i = 0 ; i < M ; i++ ) {
38+ for (int j = i + 1 ; j < M ; j++ ) {
39+ if (spaces. get(i). equals(spaces. get(j))) answer++ ;
40+ }
41+ }
42+
43+ System . out. println(answer);
44+ }
45+ }
46+ ```
You can’t perform that action at this time.
0 commit comments