結果
| 問題 | No.228 ゆきこちゃんの 15 パズル |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-19 00:38:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 912 bytes |
| 記録 | |
| コンパイル時間 | 1,329 ms |
| コンパイル使用メモリ | 167,448 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 05:13:20 |
| 合計ジャッジ時間 | 2,011 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
コンパイルメッセージ
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:2:
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:29:10:
/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:16: 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:29:10:
/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:13: note: 'x' was declared here
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;
}