슈콩

[BOJ] 백준 18869 멀티버스 Ⅱ 본문

Algorithms/Baekjoon

[BOJ] 백준 18869 멀티버스 Ⅱ

shukong 2025. 9. 20. 22:42

[문제]

https://www.acmicpc.net/problem/18869

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int m = Integer.parseInt(st.nextToken());
		int n = Integer.parseInt(st.nextToken());
		int[][] planets = new int[m][n];
		List<Integer>[] sortedPlanets = new ArrayList[m];
		int[][] order = new int[m][n];
		for(int i=0;i<m;i++) {
			st = new StringTokenizer(br.readLine());
			HashSet<Integer> hs = new HashSet<>();
			for(int j=0;j<n;j++) {
				planets[i][j] = Integer.parseInt(st.nextToken());
				hs.add(planets[i][j]);
			}
			sortedPlanets[i] = new ArrayList<>(hs);
			Collections.sort(sortedPlanets[i]);
			for(int j=0;j<n;j++) {
				order[i][j] = Collections.binarySearch(sortedPlanets[i],planets[i][j]);
			}
		} 
		int result = 0;
		for(int i=0;i<m;i++) {
			for(int j=i+1;j<m;j++) {
				if(Arrays.equals(order[i],order[j])) {
					result++;
				}
			}
		}
		System.out.println(result);
	}
}

'Algorithms > Baekjoon' 카테고리의 다른 글

[BOJ] 백준 2143 두 배열의 합  (2) 2025.09.21
[BOJ] 백준 2110 공유기 설치  (0) 2025.09.20
[BOJ] 백주 1822 차집합  (0) 2025.09.19
[BOJ] 백준 14502 연구소  (2) 2025.09.19
[BOJ] 백준 14499 주사위 굴리기  (0) 2025.09.19