結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー |
|
提出日時 | 2015-06-19 23:37:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 925 bytes |
コンパイル時間 | 471 ms |
コンパイル使用メモリ | 60,548 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-07 04:22:37 |
合計ジャッジ時間 | 972 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:29:28: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized] 29 | while (x != 3 || y != 3) { | ~~^~~~ main.cpp:29:18: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized] 29 | while (x != 3 || y != 3) { | ~~^~~~
ソースコード
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <utility>#include <string>using namespace std;int main() {int board[4][4];int num;int x, y;for (int i = 0; i < 16; i++) {cin >> num;if (num == 0) {x = i % 4;y = i / 4;}board[i / 4][i % 4] = num;}int dx[4] = {0,1,0,-1};int dy[4] = {1,0,-1,0};int nx, ny;while (x != 3 || y != 3) {num = x + y * 4 + 1;bool change = false;for (int j = 0; j < 4; j++) {nx = x + dx[j];ny = y + dy[j];if (nx < 0 || 3 < nx || ny < 0 || 3 < ny) {continue;}if (board[ny][nx] == num) {swap(board[y][x], board[ny][nx]);change = true;x = nx;y = ny;break;}}if (!change) {break;}}for (int i = 0; i < 16; i++) {if (board[i / 4][i % 4] != (i + 1) % 16) {cout << "No" << endl;return 0;}}cout << "Yes" << endl;return 0;}