Home BOJ. Dragon Curve (15685)
Post
Cancel

BOJ. Dragon Curve (15685)

[Link] https://www.acmicpc.net/problem/15685


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
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
// #include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define endl "\n"
typedef long long ll;
const int INF = 987654321;
const int MAX = 100;

int n, m, ans = 0;
vector<vector<int>> sub;
vector<int> sum;
bool mm[101][101];
int cx, cy;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

vector<int> directions;

void draw(int generation) {
  fori(i, generation) {
    int start_idx = directions.size();
    for(int i = start_idx - 1; i >= 0; i--) {
      int dir = directions[i];
      if(++dir == 4) dir = 0;
      cx += dx[dir], cy += dy[dir];
      if(0 <= cx && 0 <= cy && cx <= 100 && cy <= 100) mm[cx][cy] = true;
      directions.push_back(dir);
    }
  }
}

int count() {
  int ans = 0;
  for0(i, 100) {
    for0(j, 100) {
      if(mm[i][j] && mm[i+1][j] && mm[i][j+1] && mm[i+1][j+1]) ans++;
    }
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n;
  for0(i, n) {
    int d, g; cin >> cx >> cy >> d >> g;
    directions.clear();
    mm[cx][cy] = true;
    cx += dx[d], cy += dy[d];
    mm[cx][cy] = true;
    directions.push_back(d);
    draw(g);
  }
  cout << count() << endl;
}
This post is licensed under CC BY 4.0 by the author.