結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー | Mayimg |
提出日時 | 2019-01-19 00:38:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 912 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 165,220 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-21 11:15:22 |
合計ジャッジ時間 | 2,745 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 1 ms
4,380 KB |
testcase_16 | AC | 2 ms
4,376 KB |
testcase_17 | AC | 2 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,376 KB |
コンパイルメッセージ
次のファイルから読み込み: /usr/local/gcc7/include/c++/12.2.0/bits/exception_ptr.h:43, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/exception:168, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/ios:39, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/istream:38, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/sstream:38, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/complex:45, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/ccomplex:39, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54, 次から読み込み: main.cpp:2: 関数 ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = int]’ 内, inlined from ‘int main()’ at main.cpp:29:10: /usr/local/gcc7/include/c++/12.2.0/bits/move.h:206:11: 警告: ‘y’ may be used uninitialized [-Wmaybe-uninitialized] 206 | __b = _GLIBCXX_MOVE(__tmp); | ^ main.cpp: 関数 ‘int main()’ 内: main.cpp:9:16: 備考: ‘y’ はここで定義されています 9 | int x, y; | ^ 関数 ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = int]’ 内, inlined from ‘int main()’ at main.cpp:29:10: /usr/local/gcc7/include/c++/12.2.0/bits/move.h:206:11: 警告: ‘x’ may be used uninitialized [-Wmaybe-uninitialized] 206 | __b = _GLIBCXX_MOVE(__tmp); | ^ main.cpp: 関数 ‘int main()’ 内: main.cpp:9:13: 備考: ‘x’ はここで定義されています 9 | int x, y; | ^
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int goal[4][4], a[4][4]; int x, y; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> a[i][j]; goal[i][j] = i * 4 + j + 1; if(a[i][j] == 0) { x = i; y = j; } } } goal[3][3] = 0; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; while (true) { bool flag = false; for (int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx >= 0 && xx < 4 && yy >= 0 && yy < 4) { if (a[xx][yy] == x * 4 + y + 1) { swap(a[xx][yy], a[x][y]); x = xx; y = yy; flag = true; break; } } } if(!flag) break; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if(a[i][j] != goal[i][j]) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }