結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー |
![]() |
提出日時 | 2016-04-25 15:27:18 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 958 bytes |
コンパイル時間 | 1,155 ms |
コンパイル使用メモリ | 166,196 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-04 15:42:56 |
合計ジャッジ時間 | 1,861 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘std::string solve(vvi)’: main.cpp:36:29: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized] 36 | int yy = y + dy[i]; | ^~ main.cpp:35:29: warning: ‘x’ may be used uninitialized in this function [-Wmaybe-uninitialized] 35 | int xx = x + dx[i]; | ^~
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) typedef vector<int> vi; typedef vector<vi> vvi; string solve(vvi a) { vvi done(4, vi(4, 0)); int x, y; rep(yy, 0, 4) rep(xx, 0, 4) if (a[yy][xx] == 0) { x = xx; y = yy; } int dx[4] = { 0,0,1,-1 }; int dy[4] = { 1,-1,0,0 }; while (1) { bool ok = true; rep(yy, 0, 4) rep(xx, 0, 4) { if ((yy * 4 + xx + 1) % 16 != a[yy][xx]) ok = false; } if (ok) return "Yes"; ok = false; rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx < 0 || 4 <= xx) continue; if (yy < 0 || 4 <= yy) continue; if (done[yy][xx] == 1) continue; if (a[yy][xx] == (y * 4 + x + 1) % 16) { swap(a[y][x], a[yy][xx]); ok = true; done[y][x] = 1; y = yy; x = xx; break; } } if (!ok) return "No"; } } int main() { vvi a(4, vi(4, 0)); rep(y, 0, 4) rep(x, 0, 4) cin >> a[y][x]; cout << solve(a) << endl; }