본문 바로가기
삼성 코팅테스트 준비/모의 역량 테스트 문제

4014 활주로 건설

by tryotto 2020. 3. 4.
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
using namespace std;
 
int width, x_len;
int way[30][30];
 
void initialize();
int row_line(int y);
int col_line(int x);
 
int main() {
    int test;
    scanf("%d"&test);
 
    for (int t = 1; t <= test; t++) {
        initialize();
 
        int rst_cnt = 0;
        for (int i = 1; i <= width; i++)
            rst_cnt += row_line(i);
        for (int i = 1; i <= width; i++)
            rst_cnt += col_line(i);
 
        printf("#%d %d\n", t, rst_cnt);
    }
}
 
int row_line(int y) {
    int tmp_len = 1;
    int cur_h = way[y][1];
 
    for (int i = 2; i <= width; i++) {
        if (abs(cur_h - way[y][i]) >= 2
            return 0;
        // 올라가는 경우
        if (cur_h - way[y][i] == -1) {
            if (tmp_len >= x_len) {
                tmp_len = 1;
                cur_h = way[y][i];
            }
            else
                return 0;
        }// 내려가는 경우
        else if (cur_h - way[y][i] == 1) {
            int tmp_h = way[y][i];
            for (int j = i; j < i + x_len; j++
                if (tmp_h != way[y][j])
                    return 0;
            i = i + x_len - 1;
            tmp_len = 0;
            cur_h = tmp_h;
        }
        else 
            tmp_len++;
    }
 
    return 1;
}
 
int col_line(int x) {
    int tmp_len = 1;
    int cur_h = way[1][x];
 
    for (int i = 2; i <= width; i++) {
        if (abs(cur_h - way[i][x]) >= 2)
            return 0;
        // 올라가는 경우
        if (cur_h - way[i][x] == -1) {
            if (tmp_len >= x_len) {
                tmp_len = 1;
                cur_h = way[i][x];
            }
            else
                return 0;
        }// 내려가는 경우
        else if (cur_h - way[i][x] == 1) {
            int tmp_h = way[i][x];
            for (int j = i; j < i + x_len; j++)
                if (tmp_h != way[j][x])
                    return 0;
            i = i + x_len - 1;
            tmp_len = 0;
            cur_h = tmp_h;
        }
        else
            tmp_len++;
    }
 
    return 1;
}
 
void initialize() {
    scanf("%d %d"&width, &x_len);
    memset(way, 0sizeof(way));
 
    for (int i = 1; i <= width; i++
        for (int j = 1; j <= width; j++
            scanf("%d"&way[i][j]);
}
cs

반례인 100011 같은걸 찾아내지 못해서 검색을 좀 했다
알고리즘 자체는 굉장히 간단하며, 특별한 자료구조도 요구되지 않았다
반례를 충분히 줬다면 금방 맞췄을듯


'삼성 코팅테스트 준비 > 모의 역량 테스트 문제' 카테고리의 다른 글

2382 미생물 격리  (0) 2020.03.06
2117 홈 방범 서비스  (0) 2020.03.05
1953 탈주범 검거  (0) 2020.03.04
2477 차량 정비소  (0) 2020.03.04
2105 디저트 카페  (0) 2020.03.03