結果

問題 No.208 王将
ユーザー fumi6328fumi6328
提出日時 2018-10-11 00:55:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 963 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 169,608 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-02 19:28:26
合計ジャッジ時間 3,037 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int INF = 1e9;

int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int board[y1+1][x1+1];
    for(int i = 0; i < y1+1; i++) for(int j = 0; j < x1+1; j++) board[i][j] = INF;
    board[0][0] = 0;
    int dx[] = {-1,0,1,-1,1,-1,0,1},dy[] = {1,1,1,0,0,-1,-1,-1};
    queue<P> que;
    que.push(P(0,0));

    while(que.size()){
        P xy = que.front();
        if(xy.first == y1 && xy.second == x1) break;
        que.pop();
        for(int i = 0; i < 8; i++){
            int nx = xy.second + dx[i];
            int ny = xy.first + dy[i];
            if(nx >= 0 && nx <= x1 && ny >= 0 && ny <= y1 && board[ny][nx] == INF && !(nx == x2 && ny == y2)){
                board[ny][nx] = board[xy.first][xy.second] + 1;
                que.push(P(ny,nx));
            }
        }
    }

    cout << board[y1][x1] << endl;

    return 0;
}
0