Skip to content

Instantly share code, notes, and snippets.

@HyeonWooKim
Created December 15, 2016 12:09
Show Gist options
  • Save HyeonWooKim/ac19e5ccb92c348f92ab3541f5ae7e9b to your computer and use it in GitHub Desktop.
Save HyeonWooKim/ac19e5ccb92c348f92ab3541f5ae7e9b to your computer and use it in GitHub Desktop.
11559 Puyo Puyo
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
string M[12];
int no=1, V[12][6];
int X[4] = { -1,0,1,0 }, Y[4] = { 0,1,0,-1 };
int dfs(int x, int y, char puyo)
{
V[x][y] = no;
int A = 1;
for (int i = 0; i < 4; i++)
{
int nx = x + X[i], ny = y + Y[i];
if (nx < 0 || ny < 0 || nx>11 || ny>5 || V[nx][ny] || M[nx][ny]!=puyo) continue;
A += dfs(nx, ny, puyo);
}
return A;
}
void clear()
{
for(int i=0; i<12; i++)for(int j=0; j<6; j++)if (V[i][j] == no)
M[i][j] = '.';
}
int main()
{
int A = 0;
for (int i = 0; i < 12; i++) cin >> M[i];
while (1)
{
memset(V, 0, sizeof(V));
bool F = false;
for (int i = 0; i <12; i++)
for (int j = 0; j < 6; j++)
if (!V[i][j] && M[i][j] != '.')
{
if (dfs(i, j, M[i][j]) >= 4)
F = true, clear();
no++;
}
if (F)
{
A++;
for(int i=0; i<6; i++)
for (int j = 11; j >= 0; j--)
{
int x = j, y = i;
if (M[x][y] != '.')
{
x++;
while (x < 12 && M[x][y] == '.') swap(M[x][y], M[x - 1][y]), x++;
}
}
}
else break;
}
cout << A;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment