結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー syoken_desukasyoken_desuka
提出日時 2015-07-03 00:33:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,815 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 82,728 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 05:48:20
合計ジャッジ時間 1,563 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include<complex>
#include <cmath>
#include <iostream>
#include <fstream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <string>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define ALLOF(c) (c).begin(), (c).end()
#define IS_BETWEEN(x,a,b) (a <= x && x <= b)
typedef long long ll;

int mass[4][4];
bool canMove[4][4];
int vx[4] = {1,0,-1,0};
int vy[4] = {0,1,0,-1};
int remain = 0;

bool f(int x, int y)
{
    if (remain == 0)
    {
       return true;
    }
    rep(i,4)
    {

        if (IS_BETWEEN(x+vx[i],0,3) && IS_BETWEEN(y + vy[i],0,3) && canMove[x+ vx[i]][y+vy[i]])
        {
            if (((mass[(x+vx[i])][(y+vy[i])]) == (4 * x + y + 1)));
            {
                swap(mass[x][y],mass[x+vx[i]][y+vy[i]]);
                canMove[x][y] = false;
                remain--;
                return f(x+vx[i],y+vy[i]);
            }
        }
    }
    return false; // cant move
}

int main()
{
    int init_x = 0;
    int init_y = 0;
    rep(i,4)
        rep(j,4)
        canMove[i][j] = true;

    rep(i,4)
        rep(j,4)
        cin >> mass[i][j];

    rep(i,4)
    {
        rep(j,4)
        {
            if (mass[i][j] == 0 )
            {
                init_x = i;
                init_y = j;
            }
            if (mass[i][j] == 4 * i + j + 1)
            {
                remain++;
                canMove[i][j] = false;
            }
        }
    }
    remain--; // remove diff of 0 panel;

    if (f(init_x, init_y))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;

}

0