#include <stdio.h>
#define BIT_IDX(X, Y) (X + (Y << 3))
#define XYBIT(X, Y) (1ULL << BIT_IDX(X, Y))
#define IF_CAN_JUMP(X, Y) xx = x + X; yy = y + Y; if (0 <= xx && xx <= 7 && 0 <= yy && yy <= 7)
int main(void) {
unsigned long long now;
unsigned long long old;
int step;
int score[64];
unsigned long long bit[64];
int i;
int x;
int y;
for(i = 0; i < 64; ++i)
{
unsigned long long bitmap = 0;
int x = i % 8; int xx;
int y = i / 8; int yy;
IF_CAN_JUMP(-1, -2) bitmap |= XYBIT(xx, yy);
IF_CAN_JUMP(-1, +2) bitmap |= XYBIT(xx, yy);
IF_CAN_JUMP(+1, -2) bitmap |= XYBIT(xx, yy);
IF_CAN_JUMP(+1, +2) bitmap |= XYBIT(xx, yy);
IF_CAN_JUMP(-2, -1) bitmap |= XYBIT(xx, yy);
IF_CAN_JUMP(-2, +1) bitmap |= XYBIT(xx, yy);
IF_CAN_JUMP(+2, -1) bitmap |= XYBIT(xx, yy);
IF_CAN_JUMP(+2, +1) bitmap |= XYBIT(xx, yy);
bit[i] = bitmap;
score[i] = 0;
}
now = XYBIT(0, 0);
old = now;
step = 1;
while (old != 0xffffffffffffffffULL)
{
unsigned long long to = 0;
while (now)
{
int idx = __builtin_ctzll(now);
now &= now - 1;
to |= bit[idx];
}
now = (to & ~old);
old |= now;
to = now;
while (to)
{
int idx = __builtin_ctzll(to);
to &= to - 1;
score[idx] = step;
}
++step;
}
for(y = 0; y < 8; ++y)
{
for( x = 0; x < 8; ++x)
printf(" %d", score
[BIT_IDX
(x
, y
)]); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIEJJVF9JRFgoWCwgWSkJKFggKyAoWSA8PCAzKSkKI2RlZmluZSBYWUJJVChYLCBZKQkoMVVMTCA8PCBCSVRfSURYKFgsIFkpKQojZGVmaW5lIElGX0NBTl9KVU1QKFgsIFkpCXh4ID0geCArIFg7IHl5ID0geSArIFk7IGlmICgwIDw9IHh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