結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー ry0u_ydry0u_yd
提出日時 2015-09-06 18:44:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,966 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 79,296 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-26 09:45:16
合計ジャッジ時間 1,784 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

int a[4][4] = { {1,2,3,4},
                {5,6,7,8},
                {9,10,11,12},
                {13,14,15,0} };

bool check(vector< vector<int> > v) {
    rep(i,4) {
        rep(j,4) {
            if(a[i][j] != v[i][j]) return false;
        }
    }

    return true;
}

int main() {
    vector< vector<int> > v(4,vector<int>(4));
    rep(i,4) rep(j,4) cin >> v[i][j];

    bool flag = true;

    rep(i,4) {
        rep(j,4) {
            if(v[i][j] == 0) continue;

            queue<pair<pair<int,int>,int > > que;
            que.push(mp(mp(i,j),0));

            bool used[5][5];
            memset(used,0,sizeof(used));
            used[i][j] = true;

            int cost = 0;
            while(que.size()) {
                P p = que.front().first;
                int cnt = que.front().second;
                que.pop();
                
                int y = p.first;
                int x = p.second;

                if(v[i][j] == a[y][x]) {
                    cost = cnt;
                    break;
                }

                used[y][x] = true;

                rep(k,4) {
                    int ny = y + dy[k];
                    int nx = x + dx[k];

                    if(0 <= ny && ny < 4 && 0 <= nx && nx < 4 && !used[ny][nx]) {
                        que.push(mp(mp(ny,nx),cnt+1));
                    }
                }
            }

            if(cost >= 2) {
                flag = false;
            }
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}
0