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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
| #include <iostream>
#include <cstring>
#define MAX_TILE 10000
#define WIDTH 6
#define HEIGHT 4
using namespace std;
typedef struct Tile {
int type;
int row;
int col;
} Tile;
int blueMap[HEIGHT][WIDTH];
int greenMap[WIDTH][HEIGHT];
int numOfTile;
Tile tile[MAX_TILE];
int getScore();
void putTile(int index);
void putTile(int row, int col, int map);
int updateMap();
int getRestTile();
int main() {
cin >> numOfTile;
for (int i = 0; i < numOfTile; i++) {
cin >> tile[i].type >> tile[i].row >> tile[i].col;
}
memset(blueMap, 0, sizeof(blueMap));
memset(greenMap, 0, sizeof(blueMap));
cout << getScore() << endl;
cout << getRestTile() << endl;
}
int getScore() {
int score = 0;
for (int i = 0; i < numOfTile; i++) {
putTile(i);
score += updateMap();
}
return score;
}
void putTile(int index) {
if (tile[index].type == 1) {
for (int i = 2; i < WIDTH; i++) {
if (blueMap[tile[index].row][i] != 0) {
blueMap[tile[index].row][i - 1] = index+1;
break;
}
else if (i == WIDTH - 1)
blueMap[tile[index].row][i] = index+1;
}
for (int i = 2; i < WIDTH; i++) {
if (greenMap[i][tile[index].col] != 0) {
greenMap[i - 1][tile[index].col] = index+1;
break;
}
else if (i == WIDTH - 1)
greenMap[i][tile[index].col] = index+1;
}
}
else if (tile[index].type == 2) { //1x2
for (int i = 2; i < WIDTH; i++) {
if (blueMap[tile[index].row][i] != 0) {
blueMap[tile[index].row][i - 1] = index+1;
blueMap[tile[index].row][i - 2] = index+1;
break;
}
else if (i == WIDTH - 1) {
blueMap[tile[index].row][i] = index+1;
blueMap[tile[index].row][i - 1] = index+1;
}
}
for (int i = 2; i < WIDTH; i++) {
if (greenMap[i][tile[index].col] != 0|| greenMap[i][tile[index].col + 1] != 0) {
greenMap[i - 1][tile[index].col] = index+1;
greenMap[i - 1][tile[index].col + 1] = index+1;
break;
}
else if (i == WIDTH - 1) {
greenMap[i][tile[index].col] = index+1;
greenMap[i][tile[index].col + 1] = index+1;
}
}
}
else if (tile[index].type == 3) { //2x1
for (int i = 2; i < WIDTH; i++) {
if (blueMap[tile[index].row][i] != 0 || blueMap[tile[index].row + 1][i] != 0) {
blueMap[tile[index].row][i - 1] = index+1;
blueMap[tile[index].row + 1][i - 1] = index+1;
break;
}
else if (i == WIDTH - 1) {
blueMap[tile[index].row][i] = index+1;
blueMap[tile[index].row + 1][i] = index+1;
}
}
for (int i = 2; i < WIDTH; i++) {
if (greenMap[i][tile[index].col] != 0) {
greenMap[i - 2][tile[index].col] = index+1;
greenMap[i - 1][tile[index].col] = index+1;
break;
}
else if (i == WIDTH - 1) {
greenMap[i][tile[index].col] = index+1;
greenMap[i - 1][tile[index].col] = index+1;
}
}
}
}
void putTile(int row, int col, int map) {
if (map == 0) {
int temp = blueMap[row][col];
blueMap[row][col] = 0;
blueMap[row + 1][col] = 0;
for (int i = col + 1; i < WIDTH; i++) {
if (blueMap[row][i] != 0 || blueMap[row + 1][i] != 0) {
blueMap[row][i - 1] = temp;
blueMap[row + 1][i - 1] = temp;
break;
}
else if (i == WIDTH - 1) {
blueMap[row][i] = temp;
blueMap[row + 1][i] = temp;
}
}
}
else if (map == 1) {
int temp = greenMap[row][col];
greenMap[row][col] = 0;
greenMap[row][col + 1] = 0;
for (int i = row + 1; i < WIDTH; i++) {
if (greenMap[i][col] != 0 || greenMap[i][col + 1] != 0) {
greenMap[i - 1][col] = temp;
greenMap[i - 1][col + 1] = temp;
break;
}
else if (i == WIDTH - 1) {
greenMap[i][col] = temp;
greenMap[i][col + 1] = temp;
}
}
}
}
int updateMap() {
int score = 0;
//파랑
for (int i = 2; i < WIDTH; i++) {
int count = 0;
for (int j = 0; j < HEIGHT; j++) {
if (blueMap[j][i] != 0)
count++;
}
if (count == 4) {
score++;
for (int k = 0; k < 4; k++) blueMap[k][i] = 0;
//2*1 일때만 따로 처리해주면 됨
for (int j = i-1; j >=0; j--) {
for (int k = 0; k <= HEIGHT; k++) {
if (blueMap[k][j] != 0) {
if (k != HEIGHT - 1 && blueMap[k + 1][j] == blueMap[k][j])
putTile(k, j, 0);
else {
int temp = blueMap[k][j];
blueMap[k][j] = 0;
for (int tempCol = j + 1; tempCol < WIDTH; tempCol++) {
if (blueMap[k][tempCol] != 0) {
blueMap[k][tempCol - 1] = temp;
break;
}
else if (tempCol == WIDTH - 1)
blueMap[k][tempCol] = temp;
}
}
}
}
}
i = 2;
}
}
for (int i = 0; i < 2; i++) {
bool check = false;
for (int j = 0; j < HEIGHT; j++) {
if (blueMap[j][i])
check = true;
}
if (check) {
int temp[4] = { blueMap[0][i], blueMap[1][i], blueMap[2][i], blueMap[3][i] };
for (int k = 0; k < 4; k++) blueMap[k][i] = 0;
for (int col = i + 1; col < WIDTH; col++) {
int temp2[4] = { blueMap[0][col], blueMap[1][col], blueMap[2][col], blueMap[3][col] };
for (int k = 0; k < 4; k++) blueMap[k][col] = temp[k];
memcpy(temp, temp2, sizeof(temp));
}
}
}
//초록
for (int i = 2; i < WIDTH; i++) {
int count = 0;
for (int j = 0; j < HEIGHT; j++) {
if (greenMap[i][j] != 0)
count++;
}
if (count == 4) {
score++;
for (int k = 0; k < 4; k++) greenMap[i][k] = 0;
for (int j = i-1; j >= 0; j--) {
for (int k = 0; k < HEIGHT; k++) {
if (greenMap[j][k] != 0) {
if (k != HEIGHT - 1 && greenMap[j][k] == greenMap[j][k + 1]) {//옯기고, 다음 k에서 출동?
putTile(j, k, 1);
}
else {
int temp = greenMap[j][k];
greenMap[j][k] = 0;
for (int tempRow = j + 1; tempRow < WIDTH; tempRow++) {
if (greenMap[tempRow][k] != 0) {
greenMap[tempRow - 1][k] = temp;
break;
}
else if (tempRow == WIDTH - 1)
greenMap[tempRow][k] = temp;
}
}
}
}
}
i = 2;
}
}
for (int i = 0; i < 2; i++) {
bool check = false;
for (int j = 0; j < HEIGHT; j++) {
if (greenMap[i][j])
check = true;
}
if (check) {
int temp[4] = { greenMap[i][0], greenMap[i][1], greenMap[i][2], greenMap[i][3] };
for (int k = 0; k < 4; k++) greenMap[i][k] = 0;
for (int row = i + 1; row < WIDTH; row++) {
int temp2[4] = { greenMap[row][0], greenMap[row][1], greenMap[row][2], greenMap[row][3] };
for (int k = 0; k < 4; k++) greenMap[row][k] = temp[k];
memcpy(temp, temp2, sizeof(temp));
}
}
}
return score;
}
int getRestTile() {
int count = 0;
for (int i = 0; i < 24; i++) {
if (blueMap[i / WIDTH][i % WIDTH] != 0)
count++;
if (greenMap[i / HEIGHT][i % HEIGHT] != 0)
count++;
}
return count;
}
|