結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー ldsybldsyb
提出日時 2017-06-22 00:05:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,049 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 66,880 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-10-02 11:54:37
合計ジャッジ時間 1,340 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 2 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 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
6,816 KB
testcase_13 AC 1 ms
6,816 KB
testcase_14 AC 2 ms
6,816 KB
testcase_15 AC 1 ms
6,816 KB
testcase_16 AC 2 ms
6,820 KB
testcase_17 AC 2 ms
6,824 KB
testcase_18 AC 2 ms
6,824 KB
testcase_19 AC 2 ms
6,816 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:32: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:32: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};
      |                      ^~

ソースコード

diff #

#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];
		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;
		}
		if(a[i][j] == 0){
			pi = i;
			pj = j;
		}
	}
	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;
}
0