結果

問題 No.523 LED
ユーザー tubo28tubo28
提出日時 2017-06-06 10:40:20
言語 Rust
(1.77.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 8,355 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 184,788 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 17:47:12
合計ジャッジ時間 3,566 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// パフォーマンスと使いやすさ再優先のためunsafeもunwrapもカジュアルに使う.
// 入力はASCII文字以外ダメ.
fn main() {
    let mut input_buffer = String::with_capacity(cp_io::BUFFER_SIZE);
    let mut output_buffer = Vec::with_capacity(cp_io::BUFFER_SIZE);
    unsafe {
        cp_io::input::buf = &mut output_buffer;
        cp_io::output::buf = &mut input_buffer;
    }
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve).unwrap()
        .join().unwrap();
    cp_io::output::flush();
}

#[macro_use]
#[allow(dead_code, non_upper_case_globals, unused_macros)]
mod cp_io {
    pub const BUFFER_SIZE: usize = 8192;
    #[macro_use]
    pub mod output {
        pub const ENABLE_DUMP: bool = true;
        pub const PRECISION: usize = 10;
        pub static mut buf: *mut String = 0 as *mut String;

        macro_rules! p {
            ($x: expr) => {{
                $x.output();
                "\n".output();
                unsafe {
                    if (*cp_io::output::buf).len() > cp_io::BUFFER_SIZE {
                        flush();
                    }
                }
            }};
            ($x: expr, $($y: expr),+) => {{
                $x.output();
                " ".output();
                p!($($y),+);
            }};
        }

        macro_rules! pf {
            ($($x: expr),+) => {{
                p!($($x),+);
                flush();
            }};
        }

        macro_rules! d {
            ($($a: expr),+) => {
                if ENABLE_DUMP {
                    use std::io::*;
                    write!(stderr(), "{}:{}\t", file!(), line!()).unwrap();
                    d!(A $($a),+);
                    write!(stderr(), " = ").unwrap();
                    d!(B $($a),+);
                    write!(stderr(), "\n").unwrap();
                    stderr().flush().unwrap();
                }
            };
            (A $x: expr) => {
                write!(stderr(), "{}", stringify!($x)).unwrap();
            };
            (A $x: expr, $($y: expr),+) => {
                write!(stderr(), "{}, ", stringify!($x)).unwrap();
                d!(A $($y),+);
            };
            (B $x: expr) => {
                write!(stderr(), "{:?}", $x).unwrap();
            };
            (B $x: expr, $($y: expr),+) => {
                write!(stderr(), "{:?}, ", $x).unwrap();
                d!(B $($y),+);
            };
        }

        pub trait Output {
            fn output(&self);
        }

        macro_rules! output_normal {
            ($t: ty) => {
                impl Output for $t {
                    fn output(&self) {
                        unsafe {
                            use std::fmt::Write;
                            write!(&mut *buf, "{}", self).unwrap();
                        }
                    }
                }
            };
            ($t: ty, $($u: ty),+) => {
                output_normal!($t);
                output_normal!($($u),+);
            };
        }

        macro_rules! output_float {
            ($t: ty) => {
                impl Output for $t {
                    fn output(&self) {
                        unsafe {
                            use std::fmt::Write;
                            write!(&mut *buf, "{:.*}", PRECISION, self).unwrap();
                        }
                    }
                }
            };
            ($t: ty, $($u: ty),+) => {
                output_float!($t);
                output_float!($($u),+);
            };
        }

        pub fn flush() {
            unsafe {
                print!("{}", *buf);
                use std::io::*;
                stdout().flush().unwrap();
                (*buf).clear();
            }
        }

        output_normal!(u8, u16, u32, u64, usize);
        output_normal!(i8, i16, i32, i64, isize);
        output_normal!(bool, &'static str, String);
        output_float!(f32, f64);
    }

    pub mod input {
        pub trait Input<T> {
            fn input() -> T;
        }

        macro_rules! input_primitive {
            ($t: ty) => {
                impl Input<$t> for $t {
                    fn input() -> $t {
                        get_word().expect("EOF?").parse()
                            .unwrap_or_else(|e| panic!("Cannot parse {}", e))
                    }
                }
            };
            ($t: ty, $($u: ty),+) => {
                input_primitive!($t);
                input_primitive!($($u),+);
            };
        }

        macro_rules! input_tuple {
            ($($t: ident),*) => {
                impl< $($t: Input<$t>),* > Input< ( $($t),* ) > for ( $($t),* ) {
                    fn input() -> ( $($t),* ) {
                        ( $( $t::input()),* )
                    }
                }
            };
        }

        input_primitive!(u8, u16, u32, u64, usize);
        input_primitive!(i8, i16, i32, i64, isize);
        input_primitive!(bool, String);
        input_tuple!(A, B);
        input_tuple!(A, B, C);
        input_tuple!(A, B, C, D);

        pub fn get<T: Input<T>>() -> T {
            T::input()
        }

        pub fn get_vec<T: Input<T>>(n: usize) -> Vec<T> {
            (0..n).map(|_| get()).collect()
        }

        pub fn get_mat<T: Input<T>>(r: usize, c: usize) -> Vec<Vec<T>> {
            (0..r).map(|_| get_vec(c)).collect()
        }

        pub fn get_vec_char() -> Vec<char> {
            get_word().unwrap().chars().collect()
        }

        pub fn get_mat_char(h: usize) -> Vec<Vec<char>> {
            (0..h).map(|_| get_vec_char()).collect()
        }

        pub fn get_line() -> String {
            get_line_wrapped().unwrap()
        }

        fn get_word() -> Option<String> {
            let mut res = String::with_capacity(18);
            while let Some(c) = get_u8() {
                let d = c as char;
                if !d.is_whitespace() {
                    res.push(d);
                } else if res.len() != 0 {
                    unget_u8(c);
                    break;
                }
            }
            if res.len() == 0 { None } else { Some(res) }
        }

        fn get_line_wrapped() -> Option<String> {
            let c = get_u8();
            if c.is_none() {
                return None;
            }
            let mut line = String::with_capacity(18);
            line.push(c.unwrap() as char);
            loop {
                let c = get_u8();
                if c.is_none() || c.unwrap() == b'\n' {
                    // コメントはC++等での仕様
                    // if c.is_some() {
                    //     self.unget_u8(b'\n');
                    // }
                    return Some(line);
                }
                line.push(c.unwrap() as char);
            }
        }

        pub fn has_next() -> bool {
            loop {
                let c = get_u8();
                if c.is_none() {
                    return false;
                }
                let c = c.unwrap();
                if !(c as char).is_whitespace() {
                    unget_u8(c);
                    return true;
                }
            }
        }

        pub static mut buf: *mut Vec<u8> = 0 as *mut Vec<u8>;

        fn get_u8() -> Option<u8> {
            unsafe {
                let b = &mut (*buf);
                use std::io::{stdin, Read};
                if let Some(c) = b.pop() {
                    Some(c as u8)
                } else {
                    b.resize(super::BUFFER_SIZE, 0);
                    match stdin().read(b) {
                        Ok(l) if l > 0 => {
                            b.truncate(l);
                            b.reverse();
                            b.pop()
                        }
                        _ => return None,
                    }
                }
            }
        }

        fn unget_u8(c: u8) {
            unsafe {
                (*buf).push(c)
            }
        }
    }
}

#[allow(unused_imports)]
use cp_io::input::*;
#[allow(unused_imports)]
use cp_io::output::*;

pub const MOD: i64 = 1000000007;

fn solve() {
    while has_next() {
        let n: i64 = get();
        let i2 = (MOD + 1) / 2;
        let f = (1..n+1).fold(1, |acc, x| acc * 2 * x % MOD * (2 * x - 1) % MOD * i2 % MOD);
        p!(f);
    }
}
0