結果

問題 No.1932 動く点 P / Moving Point P
ユーザー koba-e964koba-e964
提出日時 2023-06-13 12:52:17
言語 Rust
(1.77.0)
結果
AC  
実行時間 226 ms / 6,000 ms
コード長 2,476 bytes
コンパイル時間 8,588 ms
コンパイル使用メモリ 156,308 KB
実行使用メモリ 10,852 KB
最終ジャッジ日時 2023-09-03 20:47:34
合計ジャッジ時間 22,046 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 92 ms
6,856 KB
testcase_02 AC 67 ms
6,104 KB
testcase_03 AC 90 ms
4,876 KB
testcase_04 AC 113 ms
5,904 KB
testcase_05 AC 133 ms
6,436 KB
testcase_06 AC 37 ms
4,380 KB
testcase_07 AC 225 ms
10,720 KB
testcase_08 AC 226 ms
10,800 KB
testcase_09 AC 208 ms
10,852 KB
testcase_10 AC 204 ms
10,788 KB
testcase_11 AC 203 ms
10,852 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)))
}

// https://yukicoder.me/problems/no/1932 (3.5)
// 可逆なアファイン変換の範囲合成が欲しいので、セグメント木や累積和などでできる。
// Tags: complex-numbers, affine-transformations
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