結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー |
![]() |
提出日時 | 2015-07-03 00:29:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,850 bytes |
コンパイル時間 | 571 ms |
コンパイル使用メモリ | 85,392 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 22:32:29 |
合計ジャッジ時間 | 1,223 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp:45:8: warning: extra tokens at end of #endif directive [-Wendif-labels] 45 | #endif _DEBUG | ^~~~~~
ソースコード
#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 = 16; 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]] && (mass[x+vx[i]][y + vy[i]] == 4*x+y+1 )) { #ifdef _DEBUG cout << (mass[x+vx[i]][y + vy[i]] - (4*x+y+1)) << endl; #endif _DEBUG 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; }