結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
syoken_desuka
|
| 提出日時 | 2015-07-03 00:33:33 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,815 bytes |
| コンパイル時間 | 701 ms |
| コンパイル使用メモリ | 83,996 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-07 22:32:35 |
| 合計ジャッジ時間 | 1,244 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 12 WA * 5 |
ソースコード
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include<complex>
#include <cmath>
#include <iostream>
#include <fstream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <string>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define ALLOF(c) (c).begin(), (c).end()
#define IS_BETWEEN(x,a,b) (a <= x && x <= b)
typedef long long ll;
int mass[4][4];
bool canMove[4][4];
int vx[4] = {1,0,-1,0};
int vy[4] = {0,1,0,-1};
int remain = 0;
bool f(int x, int y)
{
if (remain == 0)
{
return true;
}
rep(i,4)
{
if (IS_BETWEEN(x+vx[i],0,3) && IS_BETWEEN(y + vy[i],0,3) && canMove[x+ vx[i]][y+vy[i]])
{
if (((mass[(x+vx[i])][(y+vy[i])]) == (4 * x + y + 1)));
{
swap(mass[x][y],mass[x+vx[i]][y+vy[i]]);
canMove[x][y] = false;
remain--;
return f(x+vx[i],y+vy[i]);
}
}
}
return false; // cant move
}
int main()
{
int init_x = 0;
int init_y = 0;
rep(i,4)
rep(j,4)
canMove[i][j] = true;
rep(i,4)
rep(j,4)
cin >> mass[i][j];
rep(i,4)
{
rep(j,4)
{
if (mass[i][j] == 0 )
{
init_x = i;
init_y = j;
}
if (mass[i][j] == 4 * i + j + 1)
{
remain++;
canMove[i][j] = false;
}
}
}
remain--; // remove diff of 0 panel;
if (f(init_x, init_y))
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return 0;
}
syoken_desuka