SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
가로 세로 방향으로 따로 구해서 완전 탐색을 해준다.
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import java.util.Scanner;
public class Solution {
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int n = sc.nextInt();
int k = sc.nextInt();
int [][] arr=new int[n][n];
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
arr[i][j]=sc.nextInt();
}
}
//가로 확인
for(int i=0;i<n;i++){
int colcount=0;
for(int j=0;j<n;j++){
if(arr[i][j]==0){
if(colcount==k){
ans++;
}
colcount=0;
}
else{ //arr[i][j] 가 1일떄
colcount+=1;
}
}
if(colcount==k) ans++;
}
//세로
for(int i=0;i<n;i++){
int rowcount=0;
for(int j=0;j<n;j++){
if(arr[j][i]==0){
if(rowcount==k){
ans++;
}
rowcount=0;
}
else{ //arr[j][i] 가 1일떄
rowcount+=1;
}
}
if(rowcount==k) ans++;
}
System.out.println("#" + test_case + " " + ans);
}
sc.close();
}
}
|
cs |
'알고리즘 > 삼성 SW expert Academy' 카테고리의 다른 글
[SWEA] 1970. 쉬운 거스름돈_JAVA (0) | 2022.05.07 |
---|---|
[SWEA] 1974. 스도쿠 검증_JAVA (0) | 2022.05.07 |
[SWEA] 1989. 초심자의 회문 검사_JAVA (0) | 2022.05.06 |
[SWEA] 2001. 파리 퇴치_JAVA (0) | 2022.05.06 |
[SWEA] 2005. 파스칼의 삼각형_JAVA (0) | 2022.05.06 |