結果

問題 No.228 ゆきこちゃんの 15 パズル
ユーザー HeyHey0111HeyHey0111
提出日時 2016-03-07 22:30:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 896 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 64,120 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 18:34:41
合計ジャッジ時間 1,315 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:7: warning: ‘pos’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |       if(before==pos){
      |       ^~

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<set>
using namespace std;

set<string> sum;

int main(){
  int a[6][6]={},pos;
  for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
        a[i][j]=-1000;   
    }
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
        cin >> a[1+i][1+j];
        if(!a[i+1][j+1])pos=j+1+(i+1)*6;
    }
  }
  int dir[]={1,-1,-6,6};
  while(pos!=28){
      int before=pos;
      for(int i=0;i<4;i++){
          if(a[ (pos+dir[i])/6 ][ (pos+dir[i])%6 ] == (pos%6)+(pos/6-1)*4){
              swap(a[ (pos+dir[i])/6 ][ (pos+dir[i])%6 ],a[pos/6][pos%6]);
              pos+=dir[i];
          }
      }
      if(before==pos){
        break;  
      }
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
        if(a[i+1][j+1]!=(j+1+i*4)%16){
            cout<<"No"<<endl;
            return 0;
        }
    }
  }
  cout<<"Yes"<<endl;
    return 0;
}
0