Algorithm/SWEA

[SWEA 1206] View (D3)

Henu 2021. 7. 19. 01:44
 

SW Expert Academy

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

swexpertacademy.com

 

 

1000*255 = 25만 밖에 안되고, test case도 10개 뿐이므로 문제에서 주어진 아파트를 배열에 모두 구현하는 방법을 사용했다.

현재 아파트의 현재 층에서 좌우로 1, 2개 의 칸이 비어있다면 조망권이 있는 집으로 분류했다.

 

아파트의 구조를 2차원 배열에 담지않고 [1000]인 1차원 배열에 아파트의 최대 층수만 가지고 있어도 거의 비슷하게 풀릴듯 하다.

 

코드

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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#define fasti ios_base::sync_with_stdio(false); cin.tie(0);
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 1e9+7
#define pii pair<intint>
 
typedef long long ll;
// typedef pair<int, int> pii;
 
using namespace std;
 
int N, test, t;
int house[1001][256];
 
void input(){
    memset(house, 0sizeof(house));
    int H;
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> H;
        for(int k = 1; k <= H; k++){
            house[i][k] = 1;
        }
    }
}
 
void solve(){
    int res = 0;
    
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= 255; j++){
            if(!house[i][j]) break;
            
            if(!house[i-1][j] && !house[i-2][j] && !house[i+1][j] && !house[i+2][j]){
                res += 1;
            }
        }
    }
    
    cout << "#" << t << " " << res << "\n";
}
 
int main(int argc, char** argv){
    t = 1;
    test = 10;
    while(t <= test){
        input();
        solve();
        t++;
    }
    
    return 0;
}
 
cs