結果

問題 No.208 王将
ユーザー maine_honzuki
提出日時 2020-12-22 11:05:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 797 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 193,148 KB
最終ジャッジ日時 2025-01-17 06:05:09
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    auto dist = [](int x1, int y1, int x2, int y2) {
        return max(abs(x1 - x2), abs(y1 - y2));
    };

    int ans = 2e9 + 10;
    if (sx == sy && tx == ty && sx > tx) {
        const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
        const int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                ans = min(ans, dist(0, 0, tx + dx[i], ty + dy[i])
                                   + abs(dx[i] - dx[j]) + abs(dy[i] - dy[j])
                                   + dist(tx + dx[j], ty + dy[j], sx, sy));
            }
        }
    } else
        ans = dist(0, 0, sx, sy);
    cout << ans << endl;
}
0