[BOJ] 15685 드래곤 커브

Time Lapse :23min 2sec

15685.c

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
#include <stdio.h>
int map[101][101];
int curve[1024];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { -1,0,1,0 };
int main(int argc, char** argv) {
int N, idx, x, y, d, g, answer = 0;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d %d %d %d", &x, &y, &d, &g);
switch (d) {
case 0: d = 1; break;
case 1: d = 0; break;
case 2: d = 3; break;
default : d = 2; break;
}
idx = 0; curve[idx++] = d;
for (int gen = 1; gen <= g; gen++)
for (int rev = idx - 1; rev >= 0; rev--)
curve[idx++] = curve[rev] ? curve[rev] - 1 : 3;
map[y][x] = 1;
for (int s = 0; s < idx; s++) {
x += dx[curve[s]];
y += dy[curve[s]];
map[y][x] = 1;
}
}
for(int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
if (map[i][j] && map[i + 1][j] && map[i][j + 1] && map[i + 1][j + 1]) ++answer;
if (map[99][99] && map[99][100] && map[100][99] && map[100][100]) ++answer;
printf("%d", answer);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/BOJ/15685/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.