結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー | Bantako |
提出日時 | 2018-05-27 19:35:20 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,777 bytes |
コンパイル時間 | 1,779 ms |
コンパイル使用メモリ | 165,500 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-11 04:43:31 |
合計ジャッジ時間 | 2,656 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,384 KB |
testcase_04 | AC | 2 ms
4,384 KB |
testcase_05 | AC | 1 ms
4,384 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 1 ms
4,376 KB |
testcase_15 | AC | 1 ms
4,380 KB |
testcase_16 | AC | 2 ms
4,376 KB |
testcase_17 | AC | 1 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,376 KB |
コンパイルメッセージ
main.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type] 6 | main(){ | ^~~~ 次のファイルから読み込み: /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:1: 関数 ‘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: /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:11: 備考: ‘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:27:21: /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:9: 備考: ‘x’ はここで定義されています 9 | int x,y; | ^
ソースコード
#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; }