forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
130 lines (123 loc) · 3.54 KB
/
main.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/22b0ae85671b4e3fb5561ef97c4b4b74
#include<bits/stdc++.h>
using namespace std;
struct Board {
int N, M;
vector<vector<int>> Map;
Board(int _N=10, int _M=4) : N(_N), M(_M), Map(_N, vector<int>(_M)) { }
bool isrange(int y, int x) { return 0 <= y && y < N && 0 <= x && x < M; }
void put(int type, int x, int y) {
Map[x][y] = 1;
if(type == 2) Map[x][y + 1] = 1;
else if(type == 3) Map[x + 1][y] = 1;
while(true) {
if(type == 1) {
int nx = x + 1;
int ny = y;
if(!isrange(nx, ny)) break;
if(Map[nx][ny] == 1) break;
Map[nx][ny] = Map[x][y];
Map[x][y] = 0;
x ++;
}
else if(type == 2) {
int nx1 = x + 1;
int ny1 = y;
int nx2 = x + 1;
int ny2 = y + 1;
if(!isrange(nx1, ny1) || !isrange(nx2, ny2)) break;
if(Map[nx1][ny1] == 1 || Map[nx2][ny2] == 1) break;
Map[nx1][ny1] = Map[x][ny1];
Map[nx2][ny2] = Map[x][ny2];
Map[x][ny1] = Map[x][ny2] = 0;
x ++;
}
else {
int nx1 = x + 1;
int ny1 = y;
int nx2 = x + 2;
int ny2 = y;
if(!isrange(nx1, ny1) || !isrange(nx2, ny2)) break;
if(Map[nx2][ny2] == 1) break;
Map[nx2][ny2] = Map[x + 1][ny1];
Map[nx1][ny1] = Map[x][ny1];
Map[x][ny1] = 0;
x++;
}
}
}
int checkLine() {
int score = 0;
for(int i=N-1;i>=0;) {
bool line = true;
for(int j=0;j<M;j++) {
if(Map[i][j] == 0) line = false;
}
if(!line) {
i--;
continue;
}
score ++;
for(int L=i;L>0;L--) {
for(int j=0;j<M;j++) {
Map[L][j] = Map[L - 1][j];
}
}
for(int j=0;j<M;j++) Map[0][j] = 0;
}
return score;
}
void eraseLine() {
while(true) {
bool hasLine = false;
for(int i=4;!hasLine && i<=5;i++) {
for(int j=0;!hasLine && j<M;j++) {
if(Map[i][j] != 0) hasLine = true;
}
}
if(hasLine == false) break;
for(int i=N-1;i>0;i--) {
for(int j=0;j<M;j++) {
Map[i][j] = Map[i - 1][j];
}
}
for(int j=0;j<M;j++) Map[0][j] = 0;
}
}
int getBlocks() {
int ret = 0;
for(int i=6;i<10;i++) {
for(int j=0;j<M;j++) {
if(Map[i][j] == 1) ret++;
}
}
return ret;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
int answer = 0;
Board Green, Blue;
for(int i=0;i<N;i++) {
int t, x, y; cin >> t >> x >> y;
if(t == 1) {
Green.put(t, x, y);
Blue.put(t, y, x);
}
else {
Green.put(t, x, y);
Blue.put(5-t, y, x);
}
answer += Green.checkLine();
answer += Blue.checkLine();
Green.eraseLine();
Blue.eraseLine();
}
cout << answer << '\n';
cout << Green.getBlocks() + Blue.getBlocks() << '\n';
return 0;
}