배열 한접시
[백준] 13300번: 방 배정 [Java]
NaZZU
2024. 4. 19. 17:30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split(" ");
int count = Integer.parseInt(input[0]);
int max = Integer.parseInt(input[1]);
int[][] arr = new int[2][6];
for (int i =0; i < count; i++ )
{
String[] student = sc.nextLine().split(" ");
int gender = Integer.parseInt(student[0]);
int grade = Integer.parseInt(student[1]);
arr[gender][grade-1]++;
}
int cnt = 0;
for (int i =0; i < 2; i++)
{
for (int j = 0; j < 6; j++)
{
cnt+= (arr[i][j] + (max - 1)) / max;
}
}
System.out.println(cnt);
}
}
|
cs |
필요한 방의 개수를 셀 때, 배열의 현재값에 더하는 값을 예제에 맞춰 2로 하드코딩해뒀었는데, 그거때문에 틀렸었다.
2를 max - 1로 바꾼 이후에는 정답을 받았다.