#include <iostream>
#include <cstring>
using namespace std;
int n;
int red[4][4];
int blue[4][6];
int green[6][4];
int answer = 0;
pair<int, int> MoveBlock_Blue(int x, int y) {
int movej = 0;
while (movej <= 5 && blue[x][movej] != 1) {
movej += 1;
}
blue[x][movej - 1] = 1;
return{ x,movej - 1 };
}
pair<int, int> MoveBlock_Green(int x, int y) {
int movei = 0;
while (movei <= 5 && green[movei][y] != 1) {
movei += 1;
}
green[movei - 1][y] = 1;
return{ movei - 1,y };
}
void DeleteBlue() {
for (int i = 0; i <= 5; i++) {
int count = 0;
for (int j = 0; j < 4; j++) {
if (blue[j][i] == 1) count += 1;
}
if (count == 4) {
answer += 1;
for (int k = i - 1; k >= 0; k--) {
for (int l = 0; l < 4; l++) {
blue[l][k + 1] = blue[l][k];
}
}
for (int k = 0; k < 4; k++) blue[k][0] = 0;
}
}
}
void DeleteGreen() {
for (int i = 0; i <= 5; i++) {
int count = 0;
for (int j = 0; j <= 3; j++) {
if (green[i][j] == 1) count += 1;
}
if (count == 4) {
answer += 1;
for (int k = i - 1; k >= 0; k--) {
for (int l = 0; l < 4; l++) {
green[k + 1][l] = green[k][l];
}
}
for (int k = 0; k < 4; k++) green[0][k] = 0;
}
}
}
void SmoothBlue() {
bool flag1 = false;
bool flag2 = false;
for (int i = 0; i < 4; i++) {
if (blue[i][0] == 1) flag1 = true;
if (blue[i][1] == 1) flag2 = true;
}
//한줄에만 있는 경우
if ((flag1 == true && flag2 == false) || (flag1 == false && flag2 == true)) {
for (int i = 4; i >= 0; i--) {
for (int k = 0; k < 4; k++) {
blue[k][i + 1] = blue[k][i];
}
}
for (int i = 0; i < 4; i++) {
blue[i][0] = 0;
}
}
//두줄 모두 있는 경우
if (flag1 == true && flag2 == true) {
for (int i = 3; i >= 0; i--) {
for (int k = 0; k < 4; k++) {
blue[k][i + 2] = blue[k][i];
}
}
for (int i = 0; i < 4; i++) {
blue[i][0] = 0;
blue[i][1] = 0;
}
}
}
void SmoothGreen() {
bool flag1 = false;
bool flag2 = false;
//한줄에만 있는 경우
for (int i = 0; i < 4; i++) {
if (green[0][i] == 1) flag1 = true;
if (green[1][i] == 1) flag2 = true;
}
if ((flag1 == true && flag2 == false) || (flag1 == false && flag2 == true)) {
for (int i = 4; i >= 0; i--) {
for (int j = 0; j < 4; j++) {
green[i + 1][j] = green[i][j];
}
}
for (int i = 0; i < 4; i++) {
green[0][i] = 0;
}
}
//두줄 모두 있는 경우
if (flag1 == true && flag2 == true) {
for (int i = 3; i >= 0; i--) {
for (int j = 0; j < 4; j++) {
green[i + 2][j] = green[i][j];
}
}
for (int i = 0; i < 4; i++) {
green[0][i] = 0;
green[1][i] = 0;
}
}
}
int main(void) {
cin >> n;
memset(red, 0, sizeof(red));
memset(blue, 0, sizeof(blue));
memset(green, 0, sizeof(green));
for (int i = 0; i < n; i++) {
pair<int, int> temp_blue, temp_green;
int t, x, y;
cin >> t >> x >> y;
temp_blue = MoveBlock_Blue(x, y);
temp_green = MoveBlock_Green(x, y);
if (t == 2) {
blue[temp_blue.first][temp_blue.second - 1] = 1;
pair<int, int> temp = MoveBlock_Green(x, y + 1);
if (temp.first > temp_green.first) {
green[temp.first][temp.second] = 0;
temp.first = temp_green.first;
green[temp.first][temp.second] = 1;
}
else
{
green[temp_green.first][temp_green.second] = 0;
temp_green.first = temp.first;
green[temp_green.first][temp_green.second] = 1;
}
}
else if (t == 3) {
green[temp_green.first - 1][temp_green.second] = 1;
pair<int, int> temp = MoveBlock_Blue(x + 1, y);
if (temp.second > temp_blue.second) {
blue[temp.first][temp.second] = 0;
temp.second = temp_blue.second;
blue[temp.first][temp.second] = 1;
}
else {
blue[temp_blue.first][temp_blue.second] = 0;
temp_blue.second = temp.second;
blue[temp_blue.first][temp_blue.second] = 1;
}
}
DeleteBlue();
DeleteGreen();
SmoothBlue();
SmoothGreen();
}
cout << answer << endl;
int answer = 0;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 4; j++) {
if (green[i][j] == 1) answer += 1;
}
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 6; j++) {
if (blue[i][j] == 1) answer += 1;
}
}
cout << answer << endl;
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
새로운 게임 2 (0) | 2021.04.20 |
---|---|
주사위 윷놀이 C++ (0) | 2021.04.20 |
컨테이너 벨트 (0) | 2021.04.18 |
청소년 상어 C++ (0) | 2021.04.17 |
마법사 상어와 파이어볼 C++ (0) | 2021.04.13 |