結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー maine_honzukimaine_honzuki
提出日時 2020-12-25 18:56:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 842 bytes
コンパイル時間 2,355 ms
コンパイル使用メモリ 206,900 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-23 18:33:13
合計ジャッジ時間 3,420 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 2 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:30:39: warning: 'nxt_y' may be used uninitialized [-Wmaybe-uninitialized]
   30 |         swap(st[x][y], st[nxt_x][nxt_y]);
      |                                       ^
main.cpp:19:20: note: 'nxt_y' was declared here
   19 |         int nxt_x, nxt_y;
      |                    ^~~~~
main.cpp:30:32: warning: 'nxt_x' may be used uninitialized [-Wmaybe-uninitialized]
   30 |         swap(st[x][y], st[nxt_x][nxt_y]);
      |                                ^
main.cpp:19:13: note: 'nxt_x' was declared here
   19 |         int nxt_x, nxt_y;
      |             ^~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    vector<vector<int>> st(4), fi(4);
    for (int i = 0; i < 4; i++) {
        st[i].resize(4);
        fi[i].resize(4);
        for (int j = 0; j < 4; j++) {
            int x;
            cin >> x;
            fi[i][j] = x;
            (st[i][j] = i * 4 + j + 1) %= 16;
        }
    }

    int x = 3, y = 3;
    while (st != fi) {
        int nxt_x, nxt_y;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (fi[x][y] == st[i][j])
                    nxt_x = i, nxt_y = j;
            }
        }
        if (abs(nxt_x - x) + abs(nxt_y - y) != 1) {
            cout << "No" << endl;
            return 0;
        }
        swap(st[x][y], st[nxt_x][nxt_y]);
        x = nxt_x;
        y = nxt_y;
    }
    cout << "Yes" << endl;
}
0