結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー CleyLCleyL
提出日時 2022-05-13 09:48:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,093 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 76,688 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 11:57:57
合計ジャッジ時間 1,605 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 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,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:21:31: 警告: ‘zeroy’ may be used uninitialized [-Wmaybe-uninitialized]
   21 |   while(!(zerox == 3 && zeroy == 3)){
      |                         ~~~~~~^~~~
main.cpp:7:13: 備考: ‘zeroy’ はここで定義されています
    7 |   int zerox,zeroy;
      |             ^~~~~
main.cpp:24:20: 警告: ‘zerox’ may be used uninitialized [-Wmaybe-uninitialized]
   24 |       if(0 <= zerox+ar4[i].first && zerox+ar4[i].first < 4 && 0 <= zeroy+ar4[i].second && zeroy+ar4[i].second < 4 && A[zerox+ar4[i].first][zeroy+ar4[i].second] == B[zerox][zeroy]){
      |               ~~~~~^~~~~~~~~~~~~
main.cpp:7:7: 備考: ‘zerox’ はここで定義されています
    7 |   int zerox,zeroy;
      |       ^~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
pair<int,int> ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
int main(){
  vector<vector<int>> A(4,vector<int>(4)),B(4,vector<int>(4));
  int zerox,zeroy;
  int nw = 1;
  for(int i = 0; 4 > i; i++){
    for(int j = 0; 4 > j; j++){
      cin>>A[i][j];
      B[i][j] = nw;
      nw++;
      if(A[i][j] == 0){
        zerox = i;
        zeroy = j;
      }
    }
  }
  B[3][3] = 0;
  while(!(zerox == 3 && zeroy == 3)){
    bool next = false;
    for(int i = 0; 4 > i; i++){
      if(0 <= zerox+ar4[i].first && zerox+ar4[i].first < 4 && 0 <= zeroy+ar4[i].second && zeroy+ar4[i].second < 4 && A[zerox+ar4[i].first][zeroy+ar4[i].second] == B[zerox][zeroy]){
        swap(A[zerox][zeroy],A[zerox+ar4[i].first][zeroy+ar4[i].second]);
        zerox+=ar4[i].first;
        zeroy+=ar4[i].second;
        next = true;
        break;
      }
    }
    if(!next)break;
  }
  for(int i = 0; 4 > i; i++){
    for(int j = 0; 4 > j; j++){
      if(A[i][j] != B[i][j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}
0