結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー |
![]() |
提出日時 | 2016-07-16 13:50:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,644 bytes |
コンパイル時間 | 695 ms |
コンパイル使用メモリ | 101,164 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 13:44:18 |
合計ジャッジ時間 | 1,646 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <iostream> #include <cstdio> #include <cassert> #include <cstring> #include <vector> #include <valarray> #include <array> #include <queue> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <algorithm> #include <cmath> #include <complex> #include <random> using namespace std; using ll = long long; using ull = unsigned long long; constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);} int main() { int a[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> a[i][j]; a[i][j]--; if (a[i][j] == -1) a[i][j] = 15; } } using P = array<int, 2>; constexpr P d4[4] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1}, }; while (true) { P p; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[i][j] == 15) { p = P{i, j}; } } } if (p == P{3, 3}) break; bool f = false; for (int i = 0; i < 4; i++) { P np = P{p[0]+d4[i][0], p[1]+d4[i][1]}; if (!(0 <= min(np[0], np[1]) and max(np[0], np[1]) <= 3)) continue; if (a[np[0]][np[1]] == p[0]*4+p[1]) { f = true; swap(a[np[0]][np[1]], a[p[0]][p[1]]); } } if (!f) break; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[i][j] != i*4+j) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }