結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー | Bantako |
提出日時 | 2018-05-27 19:35:20 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,777 bytes |
コンパイル時間 | 1,355 ms |
コンパイル使用メモリ | 167,628 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 19:09:29 |
合計ジャッジ時間 | 2,200 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 6 | main(){ | ^~~~ 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/istream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, 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:27:21: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/move.h:206:11: warning: 'y' may be used uninitialized [-Wmaybe-uninitialized] 206 | __b = _GLIBCXX_MOVE(__tmp); | ^ main.cpp: In function 'int main()': main.cpp:9:11: note: 'y' was declared here 9 | int x,y; | ^ 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:27:21: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/move.h:206:11: warning: 'x' may be used uninitialized [-Wmaybe-uninitialized] 206 | __b = _GLIBCXX_MOVE(__tmp); | ^ main.cpp: In function 'int main()': main.cpp:9:9: no
ソースコード
#include<bits/stdc++.h> typedef long long ll; using namespace std; int INF = 1LL << 30; int MOD = 1e9+7; main(){ int A[4][4],table[4][4] = {};//座標が合わないなら1 for(int i = 0;i < 4;i++)for(int j = 0;j < 4;j++)cin >> A[i][j]; int x,y; for(int i = 0;i < 4;i++)for(int j = 0;j < 4;j++){ if(A[i][j] && A[i][j] != i*4 + j + 1)table[i][j] = 1; if(A[i][j] == 0){ y = i,x = j; } } //movable bool movable = 0; for(int i = 0;i < 4;i++)for(int j = 0;j < 4;j++)movable |= table[i][j]; while(movable){ bool ismoved = 0; int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0}; for(int i = 0;i < 4;i++){ int nx = x + dx[i], ny = y + dy[i]; if(nx < 0 || nx >= 4 || ny < 0 || ny >= 4)continue; if(table[ny][nx] && (A[ny][nx] == y*4 + x + 1)){ swap(A[ny][nx], A[y][x]); table[ny][nx] = 0; y = ny,x = nx; ismoved = 1; break; } } /* cout << y << " " << x << endl; for(int i = 0;i < 4;i++){ for(int j = 0;j < 4;j++){ cout << table[i][j] << " "; }cout << endl; } for(int i = 0;i < 4;i++){ for(int j = 0;j < 4;j++){ cout << A[i][j] << " "; }cout << endl; } */ movable = 0; for(int i = 0;i < 4;i++)for(int j = 0;j < 4;j++)movable |= table[i][j]; if(!ismoved)movable = 0; } //judge bool ok = 1; for(int i = 0;i < 4;i++)for(int j = 0;j < 4;j++){ if(A[i][j] && A[i][j] != i*4 + j + 1)ok = 0; } if(ok)cout << "Yes" << endl; else cout << "No" << endl; }