Skip to content

Commit e426eed

Browse files
authored
Merge pull request #1084 from AlgorithmWithGod/zinnnn37
[20251010] BOJ / G4 / 램프 / 김민진
2 parents 6f5c1c4 + 86ab1cc commit e426eed

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
```java
2+
package etc;
3+
4+
import java.io.*;
5+
import java.util.StringTokenizer;
6+
7+
public class BJ_1034_램프 {
8+
9+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
private static StringTokenizer st;
12+
13+
private static int N, M, K, max;
14+
private static boolean[][] lamp;
15+
16+
public static void main(String[] args) throws IOException {
17+
init();
18+
sol();
19+
}
20+
21+
private static void init() throws IOException {
22+
st = new StringTokenizer(br.readLine());
23+
N = Integer.parseInt(st.nextToken());
24+
M = Integer.parseInt(st.nextToken());
25+
26+
lamp = new boolean[N][M];
27+
for (int i = 0; i < N; i++) {
28+
String s = br.readLine();
29+
for (int j = 0; j < M; j++) {
30+
lamp[i][j] = s.charAt(j) == '1';
31+
}
32+
}
33+
34+
K = Integer.parseInt(br.readLine());
35+
max = 0;
36+
}
37+
38+
private static void sol() throws IOException {
39+
for (int i = 0; i < N; i++) {
40+
int toTurnOn = 0;
41+
42+
for (int j = 0; j < M; j++) {
43+
if (!lamp[i][j]) toTurnOn++;
44+
}
45+
46+
// (K - 켜야 하는 열의 수)가 홀수면 켜지 않아야 할 다른 열도 켜지기 때문에 걸러야 함
47+
if (toTurnOn > K || (K - toTurnOn) % 2 != 0) continue;
48+
49+
// 행 개수 세기
50+
int cnt = 0;
51+
for (int k = 0; k < N; k++) {
52+
if (isAllTurnedOn(i, k)) cnt++;
53+
}
54+
max = Math.max(max, cnt);
55+
}
56+
bw.write(max + "\n");
57+
bw.flush();
58+
bw.close();
59+
br.close();
60+
}
61+
62+
private static boolean isAllTurnedOn(int row1, int row2) {
63+
for (int j = 0; j < M; j++) {
64+
if (lamp[row1][j] != lamp[row2][j]) return false;
65+
}
66+
return true;
67+
}
68+
69+
}
70+
```

0 commit comments

Comments
 (0)