結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
158b
|
| 提出日時 | 2015-06-19 22:53:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,393 bytes |
| コンパイル時間 | 649 ms |
| コンパイル使用メモリ | 75,696 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-07 04:10:12 |
| 合計ジャッジ時間 | 1,286 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
using namespace std;
//#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vecy[4] = {0,-1,0,1};
const int Vecx[4] = {1,0,-1,0};
bool check[4][4] = {false};
int from[4][4];
int to[4][4] = {0};
bool func(){
for(int i=0; i<16; i++){
if(from[i/4][i%4] != to[i/4][i%4]){
return false;
}
}
return true;
}
int main(){
bool c[4][4] = {false};
int nowy = 3;
int nowx = 3;
int iy,ix;
int veci;
bool ans = true;
for(int i=0; i<16; i++){
from[i/4][i%4] = i + 1;
}
from[3][3] = 0;
for(int i=0; i<16; i++){
cin >> to[i/4][i%4];
if(from[i/4][i%4] == to[i/4][i%4]){
check[i/4][i%4] = true;
}
}
while(!func()){
for(veci=0; veci<4; veci++){
iy = nowy + Vecy[veci];
ix = nowx + Vecx[veci];
if(iy >= 0 && iy<4 && ix >= 0 && ix < 4){
if(from[iy][ix] == to[nowy][nowx]){
break;
}
}
}
if(veci == 4){
ans = false;
break;
}
if(c[iy][ix] == true){
ans = false;
break;
}
c[iy][ix] = true;
swap(from[nowy][nowx], from[iy][ix]);
nowy = iy;
nowx = ix;
}
if(ans){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
}
158b