結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー | ldsyb |
提出日時 | 2017-06-22 00:06:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,062 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 65,880 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-02 11:54:44 |
合計ジャッジ時間 | 1,329 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 1 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,824 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 2 ms
6,816 KB |
testcase_17 | AC | 2 ms
6,816 KB |
testcase_18 | AC | 1 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,820 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/exception_ptr.h:43, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/exception:168, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39, from main.cpp:1: In function '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:33:9: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/move.h:205:11: warning: 'pj' may be used uninitialized [-Wmaybe-uninitialized] 205 | __a = _GLIBCXX_MOVE(__b); | ^ main.cpp: In function 'int main()': main.cpp:9:26: note: 'pj' was declared here 9 | int a[4][4], pi, pj, dd[] = {0, 1, 0, -1, 0}; | ^~ In function '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:33:9: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/move.h:205:11: warning: 'pi' may be used uninitialized [-Wmaybe-uninitialized] 205 | __a = _GLIBCXX_MOVE(__b); | ^ main.cpp: In function 'int main()': main.cpp:9:22: note: 'pi' was declared here 9 | int a[4][4], pi, pj, dd[] = {0, 1, 0, -1, 0}; | ^~
ソースコード
#include <iostream> using namespace std; bool inside(int a, int b, int alim, int blim){ return 0 <= a && a < alim && 0 <= b && b < blim; } int main(){ int a[4][4], pi, pj, dd[] = {0, 1, 0, -1, 0}; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++){ cin >> a[i][j]; if(a[i][j] == 0){ pi = i; pj = j; continue; } bool f = a[i][j] == (4 * i + j + 1) % 16; for(int k = 0; k < 4; k++){ int ni = i + dd[k], nj = j + dd[k + 1]; if(inside(ni, nj, 4, 4)) f |= a[i][j] == (4 * ni + nj + 1) % 16; } if(!f){ cerr << i << ' ' << j << endl; cout << "No" << endl; return 0; } } while((4 * pi + pj + 1) % 16){ bool f = true; for(int i = 0; i < 4; i++){ int ni = pi + dd[i], nj = pj + dd[i + 1]; if(inside(ni, nj, 4, 4) && a[ni][nj] == (4 * pi + pj + 1) % 16){ swap(a[pi][pj], a[ni][nj]); pi = ni; pj = nj; f = false; break; } } if(f) break; } bool f = true; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) f &= a[i][j] == (4 * i + j + 1) % 16; cout << (f ? "Yes" : "No") << endl; }