• 문제 링크
https://www.acmicpc.net/problem/32201
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
Map<Integer, Integer> map = new HashMap<>();
int n = read();
for (int i = 0; i < n; i++) map.put(read(), i);
List<Integer> list = new ArrayList<>();
int max = 0;
for (int i = 0; i < n; i++) {
int k = read(), d = map.get(k) - i;
if (max < d) {
max = d;
list.clear();
}
if (max == d) list.add(k);
}
for (int i : list) sb.append(i).append(" ");
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 24653 Announcements - Data Structure / Java (0) | 2024.09.18 |
---|---|
[백준] 6800 Huffman Encoding - Data Structure / Java (0) | 2024.09.17 |
[백준] 31884 Stacking Sticks - Data Structure / Java (0) | 2024.09.15 |
[백준] 15237 Cipher - Data Structure / Java (0) | 2024.09.14 |
[백준] 11270 Disastrous Downtime - Data Structure / Java (0) | 2024.09.13 |
댓글