結果

問題 No.675 ドットちゃんたち
ユーザー wesrivery
提出日時 2019-06-23 16:50:43
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 2,267 bytes
コンパイル時間 17,229 ms
コンパイル使用メモリ 380,588 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-12-26 14:03:19
合計ジャッジ時間 15,642 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(_) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

type Mat33 = [[i64; 3]; 3];

const ROTATION: Mat33 = [[0, 1, 0], [-1, 0, 0], [0, 0, 1]];

fn input_command() -> Mat33 {
    let commands = invec!(i64);
    if commands.len() > 1 {
        let command = commands[0];
        let pos = commands[1];
        match command {
            1 => [[1, 0, pos], [0, 1, 0], [0, 0, 1]],
            2 => [[1, 0, 0], [0, 1, pos], [0, 0, 1]],
            _ => panic!(""),
        }
    } else {
        ROTATION
    }
}

fn multiple_mat33(a: Mat33, b: Mat33) -> Mat33 {
    let mut c = [[0; 3]; 3];
    for i in 0..3 {
        for j in 0..3 {
            for k in 0..3 {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    c
}

fn multiple_mat33_vec(m: Mat33, v: [i64; 3]) -> [i64; 3] {
    let mut a = [0; 3];
    for i in 0..3 {
        for j in 0..3 {
            a[i] += m[i][j] * v[j];
        }
    }
    a
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, px, py) = input!(usize, i64, i64);

    let mut commands = Vec::<Mat33>::with_capacity(n);

    for i in 0..n {
        commands.push(input_command());
    }

    let mut multi_mats = Vec::<Mat33>::with_capacity(n);

    let mut current_mat = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
    for command in commands.iter().rev() {
        let mat = multiple_mat33(current_mat, *command);
        multi_mats.push(mat);
        current_mat = mat;
    }

    multi_mats.reverse();
    for mat in multi_mats {
        let v = multiple_mat33_vec(mat, [px, py, 1]);
        println!("{} {}", v[0], v[1]);
    }
}

fn main() {
    solve();
}

0