結果
問題 | No.240 ナイト散歩 |
ユーザー |
|
提出日時 | 2016-02-11 20:27:58 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,003 bytes |
コンパイル時間 | 1,618 ms |
コンパイル使用メモリ | 170,896 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-07 21:21:01 |
合計ジャッジ時間 | 2,568 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i,n) for(i=0;i<n;++i)#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)#define mp make_pair#define pb push_back#define fi first#define sc secondtypedef pair<long,long> pl;long ab(long p){return (p>0)?p:-p;}int main(int argc, char const *argv[]) {pl d;cin >>d.fi >>d.sc;set<pl> s;queue< pair<pl,int> > que;pl start(0,0);que.push(mp(start,0));s.insert(start);//BFSwhile(!que.empty()){pair<pl,int> v=que.front();que.pop();pl t=v.fi;int now=v.sc;if(now>=3) continue;for(long dx=-2; dx<=2; ++dx){if(dx==0) continue;long dy=3-ab(dx);pl t1(t.fi+dx,t.sc-dy);pl t2(t.fi+dx,t.sc+dy);s.insert(t1);s.insert(t2);que.push(mp(t1,now+1));que.push(mp(t2,now+1));}}string ans="YES";if(s.find(d)==s.end()) ans="NO";std::cout << ans << std::endl;return 0;}