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로 바꾼 이후에는 정답을 받았다.
'배열 한접시' 카테고리의 다른 글
[백준] 1919번 애너그램 만들기 [Java] (1) | 2024.04.19 |
---|---|
[백준] 11328번: StrFry [Java] (0) | 2024.04.19 |
[백준] 두 수의 합 [C#] (1) | 2024.04.19 |
[백준] 1475번: 방 번호 [Java] (0) | 2024.04.18 |
[백준] 10808번: 알파벳 개수 [Java] (0) | 2024.04.18 |