結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー kyotoku1483
提出日時 2025-03-27 20:37:47
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,289 bytes
コンパイル時間 12,892 ms
コンパイル使用メモリ 389,692 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-27 20:38:02
合計ジャッジ時間 14,391 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused)]
use proconio::{input, marker::Chars};

fn main() {
    input! {
        xy: [(i32, i32); 3],
    }
    for i in 0..3 {
        for j in 0..3 {
            if i != j {
                for k in 0..3 {
                    if i != k && j != k {
                        let (ax, ay) = xy[i];
                        let (bx, by) = xy[j];
                        let (cx, cy) = xy[k];
                        let dx = ax + cx - bx;
                        let dy = ay + cy - by;
                        if let Ok((x, y)) = is_square(xy[i], xy[j], xy[k], (dx, dy)) {
                            println!("{} {}", x, y);
                            return;
                        }
                    }
                }
            }
        }
    }
    println!("-1")
}
fn is_square(
    a: (i32, i32),
    b: (i32, i32),
    c: (i32, i32),
    d: (i32, i32),
) -> Result<(i32, i32), i32> {
    if distance(a, b) == distance(b, c)
        && distance(b, c) == distance(c, d)
        && distance(c, d) == distance(a, b)
    {
        if distance(a, c) == distance(b, d) {
            if distance(a, b) > 0 {
                return Ok(d);
            }
        }
    }
    Err(-1)
}
fn distance(a: (i32, i32), b: (i32, i32)) -> i32 {
    (a.0 - b.0).abs() + (a.1 - b.1).abs()
}
0