結果
| 問題 | 
                            No.240 ナイト散歩
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-07-11 16:41:30 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,016 bytes | 
| コンパイル時間 | 747 ms | 
| コンパイル使用メモリ | 64,576 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-07 20:54:20 | 
| 合計ジャッジ時間 | 1,667 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 30 | 
ソースコード
#include <iostream>
#include <queue>
using namespace std;
int main() {
    
    int X, Y;
    
    cin>>X>>Y;
    int dx[8] = {-1,1,2,2,1,-1,-2,-2};
    int dy[8] = {2,2,1,-1,-2,-2,-1,1};
    
    int nowx, nowy, n=0;
    queue<int> queuex;
    queue<int> queuey;
    queuex.push(0);queuey.push(0);
    
    int nextx, nexty;
    
    if(X==0 && Y==0){
    	cout<<"YES"<<endl;
      	return 0;
    }
    
    int cnt = 0;	
    while(1){
        
        if(n == 3){
            cout<<"NO"<<endl;
            return 0;
        }
        
        nowx = queuex.front();
        nowy = queuey.front();
        queuex.pop(); queuey.pop();
        for(int i=0 ; i<8 ; i++){
            nextx = nowx + dx[i];
            nexty = nowy + dy[i];
            if(nextx == X && nexty ==Y){
            	cout<<"YES"<<endl;
            	return 0;
        	}
            queuex.push(nextx);
            queuey.push(nexty);
        }
		cnt++;
		if(cnt==1  || cnt==9 || cnt==73){
       		n++;
        }
    }
    
    return 0;
}