Skip to content

Commit a9155e5

Browse files
committed
[Gold IV] Title: 램프, Time: 104 ms, Memory: 14296 KB -BaekjoonHub
1 parent edec08a commit a9155e5

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# [Gold IV] 램프 - 1034
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1034)
4+
5+
### 성능 요약
6+
7+
메모리: 14296 KB, 시간: 104 ms
8+
9+
### 분류
10+
11+
브루트포스 알고리즘, 애드 혹, 홀짝성
12+
13+
### 제출 일자
14+
15+
2025년 11월 17일 09:29:19
16+
17+
### 문제 설명
18+
19+
<p>지민이는 각 칸마다 (1×1크기의 정사각형) 램프가 들어있는 직사각형 모양의 탁자를 샀다. 모든 램프는 켜져있거나 꺼져있다. 각 열의 아래에는 스위치가 하나씩 달려있는데, 이 스위치를 누를 때마다 그 열에 있는 램프의 상태가 바뀐다. 켜져있는 램프는 꺼지고, 꺼져있는 램프는 켜진다)</p>
20+
21+
<p>만약 어떤 행에 있는 램프가 모두 켜져있을 때, 그 행이 켜져있다고 말한다. 지민이는 스위치를 K번 누를 것이다. 서로다른 스위치 K개를 누르지 않아도 된다. 지민이는 스위치를 K번 눌러서 켜져있는 행을 최대로 하려고 한다.</p>
22+
23+
<p>지민이의 탁자에 있는 램프의 상태와 K가 주어졌을 때, 스위치를 K번 누른 후에 켜져있는 행의 최댓값을 구하는 프로그램을 작성하시오.</p>
24+
25+
### 입력
26+
27+
<p>첫째 줄에 N과 M이 주어진다. N은 행의 개수이고, M은 열의 개수이다. N과 M은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 램프의 상태가 주어진다. 1이 켜져있는 상태이고, 0이 꺼져있는 상태이다. 마지막 줄에는 K가 주어진다. K는 1,000보다 작거나 같은 자연수 또는 0이다.</p>
28+
29+
### 출력
30+
31+
<p>첫째 줄에 문제의 정답을 출력한다.</p>
32+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
public static void main(String[] args) throws Exception {
6+
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
9+
StringTokenizer st = new StringTokenizer(br.readLine());
10+
11+
int N = Integer.parseInt(st.nextToken());
12+
int M = Integer.parseInt(st.nextToken());
13+
14+
int arr[][] = new int[N][M];
15+
16+
Map<String, Integer> patterns = new HashMap<>();
17+
for(int i =0; i<N; i++) {
18+
String input = br.readLine();
19+
patterns.put(input, patterns.getOrDefault(input, 0)+1);
20+
}
21+
int K = Integer.parseInt(br.readLine());
22+
int answer = 0;
23+
for(String pattern: patterns.keySet()) {
24+
int zeroCnt = 0;
25+
for(char c : pattern.toCharArray()) {
26+
if(c == '0') {
27+
zeroCnt+=1;
28+
}
29+
}
30+
31+
if(zeroCnt > K) {
32+
continue;
33+
}
34+
if((K - zeroCnt) %2 !=0) {
35+
continue;
36+
}
37+
38+
answer = Math.max(answer, patterns.get(pattern));
39+
}
40+
System.out.println(answer);
41+
42+
}
43+
}

0 commit comments

Comments
 (0)