Comparing sensitive data, confidential files or internal emails?

Most legal and privacy policies prohibit uploading sensitive data online. Diffchecker Desktop ensures your confidential information never leaves your computer. Work offline and compare documents securely.

Untitled diff

Created Diff never expires
5 removals
102 lines
8 additions
105 lines
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <cstring>
#include <algorithm>
#include <algorithm>
#define CLEAR(x) memset((x),0,sizeof(x))
#define CLEAR(x) memset((x),0,sizeof(x))
using namespace std;
using namespace std;
struct Step{
struct Step{
int x,y;
int x,y,d;
int d;
} T[1010];
} T[1010];


int N,SCnt,GameMap[6][8],GameMapBkup[10][6][8],cr[6][8],cc[6][8];
int N,SCnt,GameMap[6][8],GameMapBkup[10][6][8],cr[6][8],cc[6][8];
bool del[6][8];
bool del[6][8];
inline bool isValid(int x,int y) { return x>=0 && x<=4 && y>=0 && y<=6; }
inline bool isValid(int x,int y) { return x>=0 && x<=4 && y>=0 && y<=6; }
inline bool drag(int x,int y,int d) {
inline bool drag(int x,int y,int d) {
if(!isValid(x+d,y) || GameMap[x][y] == GameMap[x+d][y] || GameMap[x][y]==0)
if(!isValid(x+d,y) || GameMap[x][y] == GameMap[x+d][y] || GameMap[x][y]==0)
return false;
return false;
else {
else {
swap(GameMap[x][y],GameMap[x+d][y]);
swap(GameMap[x][y],GameMap[x+d][y]);
T[++SCnt] = (Step) {x,y,d};
T[++SCnt] = (Step) {x,y,d};
}
}
return true;
return true;
}
}
inline bool Click() {
inline bool Click() {
bool ret=false;
bool ret=false;
CLEAR(del);CLEAR(cr);CLEAR(cc);
CLEAR(del);CLEAR(cr);CLEAR(cc);
for(int i=4;i>=0;i--)
for(int i=4;i>=0;i--)
for(int j=6;j>=0;j--) {
for(int j=6;j>=0;j--) {
if(GameMap[i][j] == GameMap[i][j+1] && GameMap[i][j])
if(!GameMap[i][j]) continue;
if(GameMap[i][j] == GameMap[i][j+1])
cc[i][j]=cc[i][j+1]+1;
cc[i][j]=cc[i][j+1]+1;
else cc[i][j]=1;
else cc[i][j]=1;
if(GameMap[i][j] == GameMap[i+1][j] && GameMap[i][j])
if(GameMap[i][j] == GameMap[i+1][j])
cr[i][j]=cr[i+1][j]+1;
cr[i][j]=cr[i+1][j]+1;
else cr[i][j]=1;
else cr[i][j]=1;
}
}
for(int i=0;i<=4;i++)
for(int i=0;i<=4;i++)
for(int j=0;j<=6;j++) {
for(int j=0;j<=6;j++) {
if(cc[i][j]>=3) {
if(cc[i][j]>=3) {
del[i][j]=true;
del[i][j]=true;
while(cc[i][j]>1) del[i][j+1]=true,j++;
while(cc[i][j]>1) del[i][j+1]=true,j++;
}
}
}
}
for(int j=0;j<=6;j++)
for(int j=0;j<=6;j++)
for(int i=0;i<=4;i++){
for(int i=0;i<=4;i++){
if(cr[i][j]>=3) {
if(cr[i][j]>=3) {
del[i][j]=true;
del[i][j]=true;
while(cr[i][j]>1) del[i+1][j]=true,i++;
while(cr[i][j]>1) del[i+1][j]=true,i++;
}
}
}
}
for(int i=0;i<=4;i++)
for(int i=0;i<=4;i++)
for(int j=0;j<=6;j++)
for(int j=0;j<=6;j++)
if(del[i][j]) {
if(del[i][j]) {
GameMap[i][j]=0;ret=true;
GameMap[i][j]=0;ret=true;
}
}
return ret;
return ret;
}
}
inline void Fall() {
inline void Fall() {
for(int i=0;i<=4;i++)
for(int i=0;i<=4;i++)
for(int j=0;j<=6;j++) {
for(int j=0;j<=6;j++) {
for(int tj=j;tj!=0 && GameMap[i][tj-1]==0;tj--)
for(int tj=j;tj!=0 && GameMap[i][tj-1]==0;tj--)
swap(GameMap[i][tj-1],GameMap[i][tj]);
swap(GameMap[i][tj-1],GameMap[i][tj]);
}
}
}
}
inline bool Succeed() {
inline bool Succeed() {
for(int i=0;i<=4;i++)
for(int i=0;i<=4;i++)
for(int j=0;j<=6;j++)
for(int j=0;j<=6;j++)
if(GameMap[i][j]) return false;
if(GameMap[i][j]) return false;
return true;
return true;
}
}
inline void PrintAns() {
inline void PrintAns() {
for(int i=1;i<=SCnt;i++) printf("%d %d %d\n",T[i].x,T[i].y,T[i].d);
for(int i=1;i<=SCnt;i++) printf("%d %d %d\n",T[i].x,T[i].y,T[i].d);
exit(0);
exit(0);
}
}
inline void dfs(int cur) {
inline void dfs(int cur) {
if(Succeed()) PrintAns();
if(Succeed()) PrintAns();
if(cur>N) return;
if(cur>N) return;
memcpy(GameMapBkup[cur],GameMap,sizeof(GameMap));
memcpy(GameMapBkup[cur],GameMap,sizeof(GameMap));
for(int i=0;i<=4;i++)
for(int i=0;i<=4;i++)
for(int j=0;j<=6;j++) {
for(int j=0;j<=6;j++) {
//Right
//Right
if(drag(i,j,1)) {
if(drag(i,j,1)) {
Fall();
while(Click()) Fall();
while(Click()) Fall();
dfs(cur+1);
dfs(cur+1);
SCnt--;
SCnt--;
memcpy(GameMap,GameMapBkup[cur],sizeof(GameMap));
memcpy(GameMap,GameMapBkup[cur],sizeof(GameMap));
}
}
//Left
if(drag(i,j,-1)) {
if(drag(i,j,-1)) {
Fall();
while(Click()) Fall();
while(Click()) Fall();
dfs(cur+1);
dfs(cur+1);
SCnt--;
SCnt--;
memcpy(GameMap,GameMapBkup[cur],sizeof(GameMap));
memcpy(GameMap,GameMapBkup[cur],sizeof(GameMap));
}
}
}
}
}
}
int main() {
int main() {
scanf("%d",&N);
scanf("%d",&N);
for(int i=0;i<=4;i++) {
for(int i=0;i<=4;i++) {
int j=0,t=0;
int j=0,t=0;
while(scanf("%d",&t) && t) GameMap[i][j++]=t;
while(scanf("%d",&t) && t) GameMap[i][j++]=t;
}
}
dfs(1);
dfs(1);
printf("-1");
printf("-1");
}
}