본문 바로가기
SWEA

[SWEA] 1979. 어디에 단어가 들어갈 수 있을까

by 콩순이냉장고 2021. 8. 12.

문제 URL : https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PuPq6AaQDFAUq&categoryId=AV5PuPq6AaQDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1 

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

문제 접근법 : 단순 구현문제입니다. n^2으로도 풀수있고 N^3으로 풀수있는 문제지만 간단하니만큼  O(n^3)으로

풀었네요 해설은 따로 없습니다.

 

소스코드 :

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
#include <bits/stdc++.h>
using namespace std;
int n, k;
int board[15][15];
 
void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> board[i][j];
}
 
void solve() {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n;) {
            int length = 0;
            for (int k = j; k <n&&board[i][k]==1; k++) {
                length++;
            }
            if (length == k)cnt++;
            if (length)
                j += length;
            else
                j++;
        }
    }
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n;) {
            int length = 0;
            for (int k = j; k < n && board[k][i] == 1; k++) {
                length++;
            }
            if (length == k)cnt++;
            if (length)
                j += length;
            else
                j++;
        }
    }
    cout << cnt << "\n";
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    int test;
    cin >> test;
    for (int i = 1; i <= test; i++) {
        input();
        cout << "#" << i << " ";
        solve();
    }
}
cs

궁금한점 혹은 모르는점 어떤 질문이든 댓글은 언제나 환영입니다.

 

'SWEA' 카테고리의 다른 글

[SWEA] 4522. 세상의 모든 팰린드롬  (0) 2021.08.14
[SWEA] 11315. 오목 판정  (0) 2021.08.12
[SWEA] 11688. Calkin-Wilf tree 1  (0) 2021.08.11
[SWEA] 1974. 스도쿠 검증  (0) 2021.08.03
[SWEA] 2001 파리 퇴치  (0) 2021.08.02