結果
| 問題 |
No.228 ゆきこちゃんの 15 パズル
|
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-06-19 22:30:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 979 bytes |
| コンパイル時間 | 409 ms |
| コンパイル使用メモリ | 49,792 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-07 04:05:39 |
| 合計ジャッジ時間 | 890 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:10:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#include <map>
#include <queue>
#include <cstdio>
#include <set>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
using namespace std;
inline int getInt(){ int s; scanf("%d", &s); return s; }
vector<vector<int> > ans(4, vector<int>(4));
vector<vector<int> > s(4, vector<int>(4));
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
bool check(int x, int y, int f){
if(ans == s) return true;
REP(i,4){
const int xx = x + _dx[i];
const int yy = y + _dy[i];
if(ISIN(xx, yy, 4, 4)){
const int t = s[yy][xx];
if(f & (1 << t)){
swap(s[y][x], s[yy][xx]);
if(check(xx, yy, f ^ (1 << t))) return true;
swap(s[y][x], s[yy][xx]);
}
}
}
return false;
}
int main(){
REP(i,4) REP(j,4) ans[i][j] = getInt();
REP(i,4) REP(j,4) s[i][j] = i * 4 + j + 1;
s[3][3] = 0;
puts(check(3, 3, (1 << 16) - 1) ? "Yes" : "No");
return 0;
}
y_mazun