-
Notifications
You must be signed in to change notification settings - Fork 0
/
19235.cpp
209 lines (202 loc) · 4.31 KB
/
19235.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <iostream>
#include <vector>
using namespace std;
const int GREEN = 0;
const int BLUE = 1;
const int dy[] = {-1, 0};
const int dx[] = {0, 1};
int map[2][10][4];
int n;
int score = 0;
void swap(int &a, int &b)
{
int temp = a;
a = b;
b = temp;
}
void move_one_block(int color, int y, int x, int num)
{
bool flag = false;
map[color][y][x] = 0;
while (y < 10)
{
if (map[color][y][x])
{
break;
}
flag = true;
y++;
}
y--;
map[color][y][x] = num;
}
void move_garo_block(int color, int y, int x, int num)
{
bool flag = false;
map[color][y][x] = 0;
map[color][y][x + 1] = 0;
while (y < 10)
{
if (map[color][y][x] || map[color][y][x + 1])
{
break;
}
flag = true;
y++;
}
y--;
map[color][y][x] = num;
map[color][y][x + 1] = num;
}
void move_sero_block(int color, int y, int x, int num)
{
bool flag = false;
map[color][y + 1][x] = 0;
map[color][y][x] = 0;
while (y < 9)
{
if (map[color][y + 1][x])
{
break;
}
flag = true;
y++;
}
y--;
map[color][y][x] = num;
map[color][y + 1][x] = num;
}
void down(int row, int color)
{
// 요놈이 문제.....
for (int y = row; y >= 4; y--)
{
for (int x = 0; x < 4; x++)
{
if (map[color][y][x] == 0)
continue;
bool move_flag = false;
for (int dir = 0; dir < 2; dir++)
{
int ny = y + dy[dir], nx = x + dx[dir];
if (ny < 4 || nx >= 4)
continue;
int block_num = map[color][ny][nx];
if (map[color][y][x] == block_num)
{
move_flag = true;
if (dir == 0)
{
move_sero_block(color, ny, nx, block_num);
break;
}
else if (dir == 1)
{
move_garo_block(color, y, x, block_num);
break;
}
}
}
if (move_flag)
continue;
move_one_block(color, y, x, map[color][y][x]);
}
}
}
void blur_delete(int color)
{
int k = 0;
for (int i = 5; i >= 4; i--)
{
for (int j = 0; j < 4; j++)
{
if (map[color][i][j] && i == 4)
{
k = 2;
break;
}
else if (map[color][i][j] && i == 5)
{
k = 1;
break;
}
}
}
if (k == 0)
return;
for (int i = 9; i >= 6; i--)
{
for (int j = 0; j < 4; j++)
{
map[color][i][j] = map[color][i - k][j];
map[color][i - k][j] = 0;
}
}
}
void line_delete(int color)
{
int delete_flag = 0;
for (int i = 6; i <= 9; i++)
{
int cnt = 0;
for (int j = 0; j < 4; j++)
{
if (map[color][i][j])
cnt++;
}
if (cnt == 4)
{
for (int j = 0; j < 4; j++)
{
map[color][i][j] = 0;
}
score++;
delete_flag = 1;
down(i - 1, color);
}
}
if (delete_flag)
line_delete(color);
}
void put(int color, int t, int y, int x, int num)
{
if (t == 1)
{
move_one_block(color, y, x, num);
}
else if ((t == 2 && color == GREEN) || (t == 3 && color == BLUE))
{
move_garo_block(color, y, x, num);
}
else if ((t == 3 && color == GREEN) || (t == 2 && color == BLUE))
{
move_sero_block(color, y, x, num);
}
line_delete(color);
blur_delete(color);
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
int t, y, x;
cin >> t >> y >> x;
put(GREEN, t, y, x, i + 1);
put(BLUE, t, x, y, i + 1);
}
int cnt = 0;
for (int color = 0; color < 2; color++)
{
for (int i = 6; i < 10; i++)
{
for (int j = 0; j < 4; j++)
{
if (map[color][i][j])
cnt++;
}
}
}
cout << score << '\n'
<< cnt;
}