• 문제 링크
29615번: 알파빌과 베타빌
$1$번과 $3$번을 바꾸고 $2$번과 $4$번을 바꾸면 $3\,4\,1\,2\,5$가 되어 모든 친구들이 먼저 입주할 수 있다.
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read(), m = read();
int[] arr = new int[n];
for (int i = 0; i < n; i++) arr[i] = read();
boolean[] flag = new boolean[n + 1];
for (int i = 0; i < m; i++) flag[read()] = true;
int i = 0, cnt = 0;
while (i < m) if (!flag[arr[i++]]) cnt++;
bw.write(String.valueOf(cnt));
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' 카테고리의 다른 글
[백준] 28353 고양이 카페 - Greedy / Java (0) | 2023.09.23 |
---|---|
[백준] 25707 팔찌 만들기 - Greedy / Java (0) | 2023.09.22 |
[백준] 28324 스케이트 연습 - Greedy / Java (0) | 2023.09.20 |
[백준] 23351 물 주기 - Greedy / Java (0) | 2023.09.19 |
[백준] 8061 Bitmap - Graph Theory / Java (0) | 2023.09.18 |
댓글