結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー tonyu0
提出日時 2020-03-25 08:49:47
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,223 bytes
コンパイル時間 25,684 ms
コンパイル使用メモリ 400,836 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-01 19:50:02
合計ジャッジ時間 25,689 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn permutation(n: usize, p: &mut Vec<usize>, used: &mut Vec<bool>, all: &mut Vec<Vec<usize>>) {
    if p.len() == n {
        all.push(p.to_vec());
        return;
    }
    for i in 0..n {
        if !used[i] {
            p.push(i);
            used[i] = true;
            permutation(n, p, used, all);
            p.pop();
            used[i] = false;
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let mut a: Vec<(i64, i64)> = Vec::new();
    for _ in 0..3 {
        let b: i64 = itr.next().unwrap().parse().unwrap();
        let c: i64 = itr.next().unwrap().parse().unwrap();
        a.push((b, c));
    }

    let mut perm: Vec<Vec<usize>> = Vec::new();
    let mut used = vec![false; 3];
    permutation(3, &mut Vec::new(), &mut used, &mut perm);

    for i in 0..6 {
        let p = perm[i].clone();
        let dx = a[p[1]].0 - a[p[0]].0;
        let dy = a[p[1]].1 - a[p[0]].1;
        if a[p[2]].0 == a[p[1]].0 - dy && a[p[2]].1 == a[p[1]].1 + dx {
            println!("{} {}", a[p[2]].0 - dx, a[p[2]].1 - dy);
            return;
        }
    }
    println!("-1");
}
0