結果

問題 No.1932 動く点 P / Moving Point P
ユーザー koba-e964koba-e964
提出日時 2023-06-13 12:51:04
言語 Rust
(1.77.0)
結果
AC  
実行時間 228 ms / 6,000 ms
コード長 2,259 bytes
コンパイル時間 7,392 ms
コンパイル使用メモリ 152,040 KB
実行使用メモリ 10,936 KB
最終ジャッジ日時 2023-09-03 20:45:48
合計ジャッジ時間 28,316 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 91 ms
6,936 KB
testcase_02 AC 67 ms
6,160 KB
testcase_03 AC 89 ms
4,868 KB
testcase_04 AC 112 ms
5,896 KB
testcase_05 AC 132 ms
6,348 KB
testcase_06 AC 36 ms
4,380 KB
testcase_07 AC 226 ms
10,932 KB
testcase_08 AC 228 ms
10,936 KB
testcase_09 AC 209 ms
10,812 KB
testcase_10 AC 204 ms
10,744 KB
testcase_11 AC 204 ms
10,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr,) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

type C = (f64, f64);
fn addc((a, b): C, (c, d): C) -> C {
    (a + c, b + d)
}
fn mulc((a, b): C, (c, d): C) -> C {
    (a * c - b * d, a * d + b * c)
}
fn invc((a, b): C) -> C {
    (a, -b) // norm = 1, so inv = conj
}

fn mul((a, x): (C, C), (b, y): (C, C)) -> (C, C) {
    (mulc(a, b), addc(mulc(x, b), y))
}
fn inv((a, (x, y)): (C, C)) -> (C, C) {
    let inva = invc(a);
    (inva, mulc(inva, (-x, -y)))
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););}
    input! {
        n: usize,
        pqr: [(f64, f64, f64); n],
        q: usize,
        stxy: [(usize1, usize, (f64, f64)); q],
    }
    let mut acc = vec![((1.0, 0.0), (0.0, 0.0)); n + 1];
    for i in 0..n {
        let (p, q, r) = pqr[i];
        let r = r * std::f64::consts::PI / 180.0;
        let r = (r.cos(), r.sin());
        acc[i + 1] = mul(acc[i], (r, addc(mulc(r, (-p, -q)), (p, q))));
    }
    for (s, t, xy) in stxy {
        let (a, b) = mul(inv(acc[s]), acc[t]);
        let (x, y) = addc(mulc(a, xy), b);
        puts!("{} {}\n", x, y);
    }
}
0