結果
問題 | No.228 ゆきこちゃんの 15 パズル |
ユーザー |
![]() |
提出日時 | 2015-06-19 22:37:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 1,198 ms |
コンパイル使用メモリ | 159,568 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 04:07:04 |
合計ジャッジ時間 | 1,892 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>#define FOR(i,a,b) for(int i=(a);i<(b);i++)#define REP(i,b) FOR(i,0,b)#define PB push_back#define F first#define S secondusing namespace std;typedef long long LL;typedef LL ut;typedef vector<ut> VI;typedef pair<ut,ut> pr;typedef pair<pr,ut> ppr;typedef vector<ppr> Vppr;typedef priority_queue<ppr,Vppr,greater<ppr> > PQ;const int INF=1e+9;int ans[5][5],an[5][5];int dx[]={0,0,1,-1},dy[]={1,-1,0,0};int main(){FOR(i,1,5)FOR(j,1,5)cin >> an[i][j];int now=1;FOR(i,1,5)FOR(j,1,5)ans[i][j]=now++;ans[4][4]=0;REP(l,20){FOR(i,1,5)FOR(j,1,5)REP(k,4)if(an[i][j]==0 && an[i+dy[k]][j+dx[k]]==ans[i][j])swap(an[i][j],an[i+dy[k]][j+dx[k]]);}bool diff=false;FOR(i,1,5)FOR(j,1,5)if(an[i][j]!=ans[i][j]) diff=true;if(diff)cout << "No" << endl;elsecout <<"Yes" << endl;}