結果

問題 No.1624 三角形の反射
ユーザー Rheo TommyRheo Tommy
提出日時 2021-07-23 22:30:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 6,974 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 160,252 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 04:47:54
合計ジャッジ時間 2,207 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

// # ファイル構成
// - use 宣言
// - lib モジュール
// - main 関数
// - basic モジュール
//
// 常に使うテンプレートライブラリは basic モジュール内にあります。
// 問題に応じて使うライブラリ lib モジュール内にコピペしています。
// ライブラリのコードはこちら → https://github.com/RheoTommy/at_coder
// Twitter はこちら → https://twitter.com/RheoTommy

use std::collections::*;
use std::io::{stdout, BufWriter, Write};

use crate::basic::*;
use crate::lib::*;

pub mod lib {
    /// O(logN)
    pub fn pow(mut x: i64, mut n: u64) -> i64 {
        let mut res = 1;
        while n != 0 {
            if n & 1 == 1 {
                res *= x;
            }
            n /= 2;
            x *= x;
        }
        res
    }

    /// O(logN)
    pub fn mod_pow(mut x: i64, mut n: u64, m: i64) -> i64 {
        let mut res = 1;
        while n != 0 {
            if n & 1 == 1 {
                res *= x;
            }
            n /= 2;
            x *= x;
            res %= m;
            x %= m;
        }
        res % m
    }

    /// O(logN)
    pub fn gcd(mut a: u64, mut b: u64) -> u64 {
        while b != 0 {
            let tmp = b;
            b = a % b;
            a = tmp;
        }
        a
    }

    /// O(logN)
    pub fn lcm(a: u64, b: u64) -> u64 {
        let g = gcd(a, b);
        a * b / g
    }

    /// O(logN)
    pub fn ext_gcd(a: i64, b: i64) -> (i64, i64, i64) {
        if b == 0 {
            return if a < 0 { (-a, -1, 0) } else { (a, 1, 0) };
        }
        let (g, s, t) = ext_gcd(b, a % b);
        (g, t, s - (a / b) * t)
    }

    pub fn mod_inv(a: i64, m: i64) -> Option<i64> {
        let (g, xi, _) = ext_gcd(a, -m);
        if g != 1 {
            None
        } else {
            Some((xi % m + m) % m)
        }
    }

    pub fn mod_div(a: i64, b: i64, n: i64) -> Option<i64> {
        let d = gcd(gcd(a.abs() as u64, b.abs() as u64), n.abs() as u64) as i64;
        let inv = mod_inv(a / d, n / d)?;
        let n = n / d;
        Some(((inv * b / d) % n + n) % n)
    }

    /// O(√NlogN)
    pub fn divisors(n: u64) -> Vec<u64> {
        let mut res = Vec::new();
        for i in 1.. {
            if i * i > n {
                break;
            }
            if n % i == 0 {
                res.push(i);
                if n / i != i {
                    res.push(n / i);
                }
            }
        }
        res.sort_unstable();
        res
    }

    /// O(√N)
    pub fn is_prime(n: u64) -> bool {
        for i in 2.. {
            if i * i > n {
                break;
            }
            if n % i == 0 {
                return false;
            }
        }
        n > 1
    }

    /// O(√N)
    pub fn factorization(mut n: u64) -> std::collections::HashMap<u64, u64> {
        let mut res = std::collections::HashMap::new();
        for i in 2.. {
            if i * i > n {
                break;
            }
            let mut ex = 0;
            while n % i == 0 {
                ex += 1;
                n /= i;
            }
            if ex != 0 {
                res.insert(i, ex);
            }
        }
        if n != 0 {
            *res.entry(n).or_insert(0) += 1;
        }
        res.remove(&1);
        res
    }

    pub fn float_to_int(s: &[char], x: u32) -> i64 {
        if !s.contains(&'.') {
            return s.iter().collect::<String>().parse::<i64>().unwrap() * 10i64.pow(x);
        }
        let n = s.len();
        let i = s.iter().enumerate().find(|(_, ci)| **ci == '.').unwrap().0;
        let l = n - i - 1;
        let t = s
            .iter()
            .skip_while(|ci| **ci == '0')
            .filter(|ci| **ci != '.')
            .collect::<String>()
            .parse::<i64>()
            .unwrap()
            * 10i64.pow(x - l as u32);
        t
    }
}

fn main() {
    let mut io = IO::new();
    let s = io.next_chars().collect::<Vec<_>>();
    let a = float_to_int(&s, 3);
    let h = lcm(a as u64, 1000) as i64;
    let w = h / a;
    // eprintln!("{:?}", (a, h, w));
    let h = h / 1000;
    let w = w;

    let d = w - 1 + h - 1 + (h + w) / 2 + (h - w).abs() / 2;
    let p = [['A', 'B'], ['C', 'A']];
    io.println(format!("{} {}", p[h as usize % 2][w as usize % 2], d));
}

pub mod basic {
    pub const U_INF: u64 = (1 << 60) + (1 << 30);
    pub const I_INF: i64 = (1 << 60) + (1 << 30);

    pub struct IO {
        iter: std::str::SplitAsciiWhitespace<'static>,
        buf: std::io::BufWriter<std::io::StdoutLock<'static>>,
    }

    impl Default for IO {
        fn default() -> Self {
            Self::new()
        }
    }

    impl IO {
        pub fn new() -> Self {
            use std::io::*;
            let mut input = String::new();
            std::io::stdin().read_to_string(&mut input).unwrap();
            let input = Box::leak(input.into_boxed_str());
            let out = Box::new(stdout());
            IO {
                iter: input.split_ascii_whitespace(),
                buf: BufWriter::new(Box::leak(out).lock()),
            }
        }
        pub fn next_str(&mut self) -> &str {
            self.iter.next().unwrap()
        }
        pub fn read<T: std::str::FromStr>(&mut self) -> T
            where
                <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            self.iter.next().unwrap().parse().unwrap()
        }
        pub fn next_usize(&mut self) -> usize {
            self.read()
        }
        pub fn next_uint(&mut self) -> u64 {
            self.read()
        }
        pub fn next_int(&mut self) -> i64 {
            self.read()
        }
        pub fn next_float(&mut self) -> f64 {
            self.read()
        }
        pub fn next_chars(&mut self) -> std::str::Chars {
            self.next_str().chars()
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T>
            where
                <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            (0..n).map(|_| self.read()).collect::<Vec<_>>()
        }
        pub fn print<T: std::fmt::Display>(&mut self, t: T) {
            use std::io::Write;
            write!(self.buf, "{}", t).unwrap();
        }
        pub fn println<T: std::fmt::Display>(&mut self, t: T) {
            self.print(t);
            self.print("\n");
        }
        pub fn print_iter<T: std::fmt::Display, I: Iterator<Item=T>>(
            &mut self,
            mut iter: I,
            sep: &str,
        ) {
            if let Some(v) = iter.next() {
                self.print(v);
                for vi in iter {
                    self.print(sep);
                    self.print(vi);
                }
            }
            self.print("\n");
        }
        pub fn flush(&mut self) {
            use std::io::Write;
            self.buf.flush().unwrap();
        }
    }
}
0