結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー |
![]() |
提出日時 | 2015-10-08 12:04:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,147 bytes |
コンパイル時間 | 1,178 ms |
コンパイル使用メモリ | 70,684 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 02:14:22 |
合計ジャッジ時間 | 1,339 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <vector> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <functional> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cctype> #include <string> using namespace std; int main() { int a[4][4], b[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> a[j][i]; b[j][i] = (i*4+j+1)%16; } } int px, py; px = py = 3; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, -1, 0, 1}; while(true) { if (b[px][py] != a[px][py]) { bool ok = false; for (int i = 0; i < 4; i++) { int nx = px+dx[i], ny = py+dy[i]; if (nx >= 0 && ny >= 0 && nx < 4 && ny < 4 && b[nx][ny] == a[px][py]) { ok = true; swap(b[nx][ny], b[px][py]); px = nx; py = ny; break; } } if (!ok) { puts("No"); return 0; } }else { break; } } bool ok = true; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[j][i] != b[j][i]) { ok = false; break; } } if (!ok) break; } if (ok) { puts("Yes"); }else { puts("No"); } }