結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー vain0vain0
提出日時 2015-06-19 22:52:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,622 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 74,776 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 10:02:50
合計ジャッジ時間 1,433 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <functional>
#include <set>
#include <ctime>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#ifndef ONLINE_JUDGE //POJ
# include <complex>
# include <random>
# include <array>
# define mkt make_tuple
# define empb emplace_back
#endif
#ifdef _LOCAL
# include "for_local.h"
#endif
using namespace std;
typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define mkp make_pair
#define all(_X) (_X).begin(), (_X).end()
inline int scani() { int n; scanf("%d", &n); return n; }


static int const dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };

int board[4][4] {};
int iz, jz;

bool correct(int i, int j, int k) {
	return k == (i * 4 + j + 1);
}

void move() {
	for (;;) {
		bool continues = false;

		rep(d, 4) {
			int u = iz + dx[d];
			int v = jz + dy[d];
			if ( 0 <= u && u < 4 && 0 <= v && v < 4
				&& correct(iz, jz, board[u][v]) ) {
				swap(board[iz][jz], board[u][v]);
				iz = u; jz = v;
				continues = true;
				break;
			}
		}
		if ( !continues) break;
	}
}
bool check() {
	move();

	rep(i, 4) rep(j, 4) {
		if ( i == iz && j == jz ) continue;
		if ( !correct(i, j, board[i][j]) ) return false;
	}
	return true;
}

signed main() {
	rep(i, 4) rep(j, 4) {
		int k; cin >> k;
		board[i][j] = k;

		if ( k == 0 ) {
			iz = i; jz = j;
		}
	}
	cout << (check() ? "Yes" : "No") << endl;
	return 0;
}

0