結果

問題 No.520 プロジェクトオイラーへの招待
ユーザー tubo28tubo28
提出日時 2017-05-28 18:27:23
言語 Rust
(1.77.0 + proconio)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 6,312 bytes
コンパイル時間 14,997 ms
コンパイル使用メモリ 405,640 KB
最終ジャッジ日時 2024-11-14 20:02:21
合計ジャッジ時間 16,141 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
error[E0432]: unresolved import `io`
   --> src/main.rs:193:9
    |
193 |     use io::*;
    |         ^^ help: a similar path exists: `crate::io`
    |
    = note: `use` statements changed in Rust 2018; read more at <https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html>

error[E0425]: cannot find function `has_next` in this scope
   --> src/main.rs:213:15
    |
213 |         while has_next() {
    |               ^^^^^^^^ not found in this scope
    |
help: consider importing this function
    |
193 +     use crate::io::has_next;
    |

error[E0425]: cannot find function `get` in this scope
   --> src/main.rs:214:25
    |
214 |             for _ in 0..get() {
    |                         ^^^ not found in this scope
    |
help: consider importing this function
    |
193 +     use crate::io::get;
    |

error[E0425]: cannot find function `get` in this scope
   --> src/main.rs:216:33
    |
216 |                 let (a, b, c) = get();
    |                                 ^^^ not found in this scope
    |
help: consider importing this function
    |
193 +     use crate::io::get;
    |

warning: creating a mutable reference to mutable static is discouraged
   --> src/main.rs:154:36
    |
154 |                 match stdin().read(&mut buf) {
    |                                    ^^^^^^^^ mutable reference to mutable static
    |
    = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
    = note: this will be a hard error in the 2024 edition
    = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
    = note: `#[warn(static_mut_refs)]` on by default
help: use `addr_of_mut!` instead to create a raw pointer
    |
154 |                 match stdin().read(addr_of_mut!(buf)) {
    |                                    ~~~~~~~~~~

ソースコード

diff #

#[macro_use]
#[allow(dead_code, unused_macros, non_upper_case_globals)]
mod io {
    macro_rules! p {
        ($x:expr) => {
            println!("{:.10}", $x);
        };
        ($x:expr, $($y:expr),+) => {
            print!("{:.10} ", $x);
            p!($($y),+);
        };
    }

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

    pub trait Scan<T> {
        fn scan() -> T;
    }

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

    macro_rules! scan_tuple {
        ($($t: ident),*) => {
            impl< $($t: Scan<$t>),* > Scan< ( $($t),* ) > for ( $($t),* ) {
                fn scan() -> ( $($t),* ) {
                    ( $( $t::scan()),* )
                }
            }
        };
    }

    scan_primitive!(u8,
                    u16,
                    u32,
                    u64,
                    i8,
                    i16,
                    i32,
                    i64,
                    f32,
                    f64,
                    usize,
                    isize,
                    bool,
                    String);
    scan_tuple!(A, B);
    scan_tuple!(A, B, C);
    scan_tuple!(A, B, C, D);

    pub fn get<T: Scan<T>>() -> T {
        T::scan()
    }

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

    pub fn get_mat<T: Scan<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(16);
        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) }
    }

    pub fn get_line_wrapped() -> Option<String> {
        let c = get_u8();
        if c.is_none() {
            return None;
        }
        let mut line = String::with_capacity(20);
        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);
        }
    }

    static mut idx: usize = 0;
    static mut len: usize = 0;
    static mut buf: [u8; 65536] = [0; 65536];

    fn get_u8() -> Option<u8> {
        unsafe {
            use std::io::{stdin, Read};
            if idx == len {
                match stdin().read(&mut buf) {
                    Ok(l) if l > 0 => {
                        idx = 0;
                        len = l;
                    }
                    _ => return None,
                }
            }
            idx += 1;
            Some(buf[idx - 1])
        }
    }

    fn unget_u8(c: u8) {
        unsafe {
            idx -= 1;
            buf[idx] = c;
        }
    }

    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 const USE_DUMP: bool = true;
}

#[allow(non_upper_case_globals, unused_imports)]
mod solver {
    use io::*;
    use std::cmp::{min, max};

    const MOD: u64 = 1000000007;

    fn rec(a: usize, b: usize, dp: &mut Vec<Vec<Option<u64>>>) -> u64 {
        if let Some(memo) = dp[a][b] {
            memo
        } else {
            let res = if a == 1 || b == 1 {
                1
            } else {
                (rec(a, b - 1, dp) + rec(a - 1, b, dp)) % MOD
            };
            dp[a][b] = Some(res);
            res
        }
    }

    pub fn solve() {
        while has_next() {
            for _ in 0..get() {
                let mut dp = vec![vec![None; 222]; 222];
                let (a, b, c) = get();
                let mut ans = 0;
                for i in 0..a {
                    for j in 0..b {
                        for k in 0..c {
                            ans +=
                                rec(a - i, j + 1, &mut dp) *
                                rec(b - j, k + 1, &mut dp) % MOD *
                                rec(c - k, i + 1, &mut dp) % MOD;
                        }
                    }
                }
                ans += rec(a, b + c + 1, &mut dp) + rec(b, c + a + 1, &mut dp) + rec(c, a + b + 1, &mut dp);
                p!(ans % MOD);
            }
        }
    }
}

fn main() {
    let t = std::thread::Builder::new().stack_size(104_857_600); // 100 MB
    t.spawn(|| solver::solve()).unwrap().join().unwrap();
}    
0