結果
| 問題 | 
                            No.3108 Luke or Bishop
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-04-18 23:14:44 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,060 bytes | 
| コンパイル時間 | 886 ms | 
| コンパイル使用メモリ | 77,152 KB | 
| 実行使用メモリ | 7,848 KB | 
| 最終ジャッジ日時 | 2025-04-18 23:14:47 | 
| 合計ジャッジ時間 | 1,862 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 26 | 
ソースコード
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    long long Gx, Gy;
    cin >> Gx >> Gy;
    
    // Calculate minimum moves for Rook
    int rook_moves;
    if (Gx == 0 && Gy == 0) {
        rook_moves = 0;  // Already at the goal
    } else if (Gx == 0 || Gy == 0) {
        rook_moves = 1;  // Can reach in one move (horizontally or vertically)
    } else {
        rook_moves = 2;  // Need two moves: one horizontal and one vertical
    }
    
    // Calculate minimum moves for Bishop
    int bishop_moves;
    if (Gx == 0 && Gy == 0) {
        bishop_moves = 0;  // Already at the goal
    } else if (abs(Gx) == abs(Gy)) {
        bishop_moves = 1;  // Can reach in one move (on a diagonal)
    } else {
        // For any point not on the main diagonals, we need 2 moves
        // With real numbers k, a bishop can reach any point in 2 moves
        bishop_moves = 2;
    }
    
    // Choose the piece that requires fewer moves
    int result = min(rook_moves, bishop_moves);
    cout << result << endl;
    
    return 0;
}