結果

問題 No.240 ナイト散歩
ユーザー sekiya9311sekiya9311
提出日時 2016-04-15 02:17:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 776 bytes
コンパイル時間 702 ms
コンパイル使用メモリ 75,800 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 01:42:54
合計ジャッジ時間 10,873 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,940 KB
testcase_05 RE -
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 AC 2 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 WA -
testcase_26 RE -
testcase_27 RE -
testcase_28 WA -
testcase_29 RE -
testcase_30 AC 2 ms
6,944 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#define pii pair<int,int>
using namespace std;

int dx[]={-2, -2, -1, -1, 1, 1, 2, 2};
int dy[]={-1, 1, -2, 2, -2, 2, -1, 1};

int main(void){
    int X,Y;
    cin>>X>>Y;
    unsigned long long P[X+1][Y+1];
    for(int i=0;i<=X;i++){
        for(int j=0;j<=Y;j++) P[i][j]=0;
    }
    queue<pii> q;
    q.push(pii(X,Y));
    while(!q.empty()){
        pii p=q.front(); q.pop();
        int x=p.first,y=p.second;
        for(int i=0;i<8;i++){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx<0 || ny<0 || nx>X || ny>Y) continue;
            if(!P[nx][ny]) continue;
            q.push(pii(nx,ny));
            P[nx][ny]=P[x][y]+1;
        }
    }
    if(P[X][Y]<=3) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
0