Skip to content

Commit 2f41161

Browse files
committed
[D2] Title: 어디에 단어가 들어갈 수 있을까, Time: 78 ms, Memory: 24,704 KB -BaekjoonHub
1 parent e028680 commit 2f41161

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [D2] 어디에 단어가 들어갈 수 있을까 - 1979
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PuPq6AaQDFAUq)
4+
5+
### 성능 요약
6+
7+
메모리: 24,704 KB, 시간: 78 ms, 코드길이: 1,813 Bytes
8+
9+
### 제출 일자
10+
11+
2025-10-06 17:10
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.util.*;
2+
import java.io.*;
3+
4+
class Solution {
5+
public static void main(String args[]) throws Exception {
6+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
StringBuilder sb = new StringBuilder();
8+
int T = Integer.parseInt(br.readLine());
9+
10+
for (int t = 1; t <= T; t++) {
11+
StringTokenizer st = new StringTokenizer(br.readLine());
12+
int N = Integer.parseInt(st.nextToken());
13+
int K = Integer.parseInt(st.nextToken());
14+
int[][] arr = new int[N][N];
15+
16+
for (int i = 0; i < N; i++) {
17+
st = new StringTokenizer(br.readLine());
18+
for (int j = 0; j < N; j++) {
19+
arr[i][j] = Integer.parseInt(st.nextToken());
20+
}
21+
}
22+
23+
int count = 0;
24+
25+
// 가로 검사
26+
for (int i = 0; i < N; i++) {
27+
int consecutive = 0;
28+
for (int j = 0; j < N; j++) {
29+
if (arr[i][j] == 1) consecutive++;
30+
else {
31+
if (consecutive == K) count++;
32+
consecutive = 0;
33+
}
34+
}
35+
if (consecutive == K) count++;
36+
}
37+
38+
// 세로 검사
39+
for (int j = 0; j < N; j++) {
40+
int consecutive = 0;
41+
for (int i = 0; i < N; i++) {
42+
if (arr[i][j] == 1) consecutive++;
43+
else {
44+
if (consecutive == K) count++;
45+
consecutive = 0;
46+
}
47+
}
48+
if (consecutive == K) count++;
49+
}
50+
51+
sb.append("#").append(t).append(" ").append(count).append("\n");
52+
}
53+
54+
System.out.print(sb);
55+
}
56+
}

0 commit comments

Comments
 (0)