結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-16 17:13:03 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,128 bytes |
| コンパイル時間 | 892 ms |
| コンパイル使用メモリ | 152,608 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 04:29:58 |
| 合計ジャッジ時間 | 1,735 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 17 |
コンパイルメッセージ
Main.d(49): Deprecation: foreach: loop index implicitly converted from `size_t` to `int` Main.d(50): Deprecation: foreach: loop index implicitly converted from `size_t` to `int`
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;
alias Tuple!(int[][], "board", int, "visited") qItem;
void main()
{
auto aij = iota(4).map!(_ => readln.split.map!(to!int).array).array;
auto bij = iota(4).map!(i => iota(4).map!(j => (i * 4 + j + 1).to!int).array).array;
bij[3][3] = 0;
auto qi = new DList!(qItem);
qi.insert(qItem(bij.dupDeep, 0));
while (!qi.empty) {
auto q = qi.front, cij = q.board, visited = q.visited;
qi.removeFront;
if (cmp(aij, cij)) {
writeln("YES");
return;
}
auto p = find0(cij);
foreach (sib; sibPoints) {
auto np = p + sib;
if (np.x < 0 || np.x >= 4 || np.y < 0 || np.y >= 4) continue;
if (visited.bitTest(cij[np.y][np.x])) continue;
auto dij = cij.dupDeep;
swap(dij[p.y][p.x], dij[np.y][np.x]);
qi.insert(qItem(dij, visited.bitSet(dij[p.y][p.x])));
}
}
writeln("NO");
}
bool cmp(int[][] aij, int[][] bij)
{
return aij.zip(bij).all!("a[0] == a[1]");
}
int[][] dupDeep(int[][] aij)
{
return aij.map!(a => a.dup).array;
}
point find0(int[][] aij)
{
foreach (int i, ai; aij)
foreach (int j, a; ai)
if (a == 0) return point(j, i);
assert(0);
}
struct Point(T) {
T x, y;
point opBinary(string op)(point rhs) {
static if (op == "+") return point(x + rhs.x, y + rhs.y);
else static if (op == "-") return point(x - rhs.x, y - rhs.y);
}
}
alias Point!int point;
alias Point!real rpoint;
const auto sibPoints = [point(-1, 0), point(0, -1), point(1, 0), point(0, 1)];
template BitOp(T) {
bool bitTest(T n, size_t i) { return (n & (1.to!T << i)) != 0; }
T bitSet(T n, size_t i) { return n | (1.to!T << i); }
T bitReset(T n, size_t i) { return n & ~(1.to!T << i); }
T bitComp(T n, size_t i) { return n ^ (1.to!T << i); }
int bsf(T n) { return core.bitop.bsf(n.to!ulong); }
int bsr(T n) { return core.bitop.bsr(n.to!ulong); }
int popcnt(T n) { return core.bitop.popcnt(n.to!ulong); }
}
mixin BitOp!(int);