結果

問題 No.895 MESE
ユーザー akiradeveloperakiradeveloper
提出日時 2019-09-27 23:06:11
言語 Rust
(1.77.0 + proconio)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 7,763 bytes
コンパイル時間 13,098 ms
コンパイル使用メモリ 386,988 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 01:17:57
合計ジャッジ時間 14,963 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 27 ms
6,944 KB
testcase_14 AC 24 ms
6,940 KB
testcase_15 AC 35 ms
6,940 KB
testcase_16 AC 28 ms
6,944 KB
testcase_17 AC 18 ms
6,944 KB
testcase_18 AC 45 ms
6,944 KB
testcase_19 AC 44 ms
6,944 KB
testcase_20 AC 44 ms
6,940 KB
testcase_21 AC 44 ms
6,944 KB
testcase_22 AC 45 ms
6,940 KB
testcase_23 AC 45 ms
6,940 KB
testcase_24 AC 43 ms
6,940 KB
testcase_25 AC 44 ms
6,940 KB
testcase_26 AC 43 ms
6,940 KB
testcase_27 AC 42 ms
6,940 KB
testcase_28 AC 43 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `n`
   --> src/main.rs:226:19
    |
226 |     fn nBk(&self, n: u64, k: u64) -> u64 {
    |                   ^ help: if this is intentional, prefix it with an underscore: `_n`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `k`
   --> src/main.rs:226:27
    |
226 |     fn nBk(&self, n: u64, k: u64) -> u64 {
    |                           ^ help: if this is intentional, prefix it with an underscore: `_k`

warning: methods `fact`, `nHk`, `nSk`, and `nBk` are never used
   --> src/main.rs:190:8
    |
168 | impl ModComb {
    | ------------ methods in this implementation
...
190 |     fn fact(&self, n: usize) -> u64 {
    |        ^^^^
...
205 |     fn nHk(&self, n: u64, k: u64) -> u64 {
    |        ^^^
...
211 |     fn nSk(&self, n: u64, k: u64) -> u64 {
    |        ^^^
...
226 |     fn nBk(&self, n: u64, k: u64) -> u64 {
    |        ^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: method `nCk` should have a snake case name
   --> src/main.rs:193:8
    |
193 |     fn nCk(&self, n: u64, k: u64) -> u64 {
    |        ^^^ help: convert the identifier to snake case: `n_ck`
    |
    = note: `#[warn(non_snake_case)]` on by default

warning: method `nPk` should have a snake case name
   --> src/main.rs:199:8
    |
199 |     fn nPk(&self, n: u64, k: u64) -> u64 {
    |        ^^^ help: convert the identifier to snake case: `n_pk`

warning: method `nHk` should have a snake case name
   --> src/main.rs:205:8
    |
205 |     fn nHk(&self, n: u64, k: u64) -> u64 {
    |        ^^^ help: convert the identifier to snake case: `n_hk`

warning: method `nSk` should have a snake case name
   --> src/main.rs:211:8
    |
211 |     fn nSk(&self, n: u64, k: u64) -> u64 {
    |        ^^^ help: convert the identifier to snake case: `n_sk`

warning: method `nBk` should have a snake case name
   --> src/main.rs:226:8
    |
226 |     fn nBk(&self, n: u64, k: u64) -> u64 {
    |        ^^^ help: convert the i

ソースコード

diff #

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[macro_export]
macro_rules ! dvec { ( $ t : expr ; $ len : expr ) => { vec ! [ $ t ; $ len ] } ; ( $ t : expr ; $ len : expr , $ ( $ rest : expr ) ,* ) => { vec ! [ dvec ! ( $ t ; $ ( $ rest ) ,* ) ; $ len ] } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[macro_export]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut parser = Parser :: from_str ( $ s ) ; input_inner ! { parser , $ ( $ r ) * } } ; ( parser = $ parser : ident , $ ( $ r : tt ) * ) => { input_inner ! { $ parser , $ ( $ r ) * } } ; ( new_stdin_parser = $ parser : ident , $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let reader = std :: io :: BufReader :: new ( stdin . lock ( ) ) ; let mut $ parser = Parser :: new ( reader ) ; input_inner ! { $ parser , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { input ! { new_stdin_parser = parser , $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! input_inner { ( $ parser : ident ) => { } ; ( $ parser : ident , ) => { } ; ( $ parser : ident , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ parser , $ t ) ; input_inner ! { $ parser $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! read_value { ( $ parser : ident , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ parser , $ t ) ) ,* ) } ; ( $ parser : ident , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ parser , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ parser : ident , chars ) => { read_value ! ( $ parser , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ parser : ident , usize1 ) => { read_value ! ( $ parser , usize ) - 1 } ; ( $ parser : ident , $ t : ty ) => { $ parser . next ::<$ t > ( ) . expect ( "Parse error" ) } ; }
use std::io;
use std::io::BufRead;
use std::str;
pub struct Parser<R> {
    reader: R,
    buf: Vec<u8>,
    pos: usize,
}
impl Parser<io::Empty> {
    pub fn from_str(s: &str) -> Parser<io::Empty> {
        Parser {
            reader: io::empty(),
            buf: s.as_bytes().to_vec(),
            pos: 0,
        }
    }
}
impl<R: BufRead> Parser<R> {
    pub fn new(reader: R) -> Parser<R> {
        Parser {
            reader: reader,
            buf: vec![],
            pos: 0,
        }
    }
    pub fn update_buf(&mut self) {
        self.buf.clear();
        self.pos = 0;
        loop {
            let (len, complete) = {
                let buf2 = self.reader.fill_buf().unwrap();
                self.buf.extend_from_slice(buf2);
                let len = buf2.len();
                if len == 0 {
                    break;
                }
                (len, buf2[len - 1] <= 0x20)
            };
            self.reader.consume(len);
            if complete {
                break;
            }
        }
    }
    pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> {
        loop {
            let mut begin = self.pos;
            while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                begin += 1;
            }
            let mut end = begin;
            while end < self.buf.len() && (self.buf[end] > 0x20) {
                end += 1;
            }
            if begin != self.buf.len() {
                self.pos = end;
                return str::from_utf8(&self.buf[begin..end]).unwrap().parse::<T>();
            } else {
                self.update_buf();
            }
        }
    }
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    input!{
        a:u64,b:u64,c:u64,
    }
    let d = a+b+c;
    // d-2ビットからcビットとるやり方

    let mo = 1_000_000_007;
    let modcomb = ModComb::new(d, mo);
    let mut sum = 0;
    // 1-indexed
    // i: MSB of z
    for i in c..d-1 { // [c,d-2]
        let xmsbcnt = modcomb.nCk(i-1, c-1);
        let mut lsum = modpow(2,i-1,mo) * xmsbcnt;
        lsum %= mo;

        if c>=2 {
            // i以下のあるビットが出現する回数
            // ibit目とそいつを固定させて他からc-2個選ぶ
            let xothercnt = if c==2 {
                1
            } else {
                modcomb.nCk(i-2, c-2)
            };
            let sumother = (modpow(2,i-1,mo)+mo-1)%mo;
            lsum += sumother * xothercnt;
            lsum %= mo;
        }

        // yのとり方
        // d-1個からc個を引いたものからbを選ぶ
        // そこから、b<cとなってしまう場合を引く
        let ycnt = (modcomb.nCk(d-1-c, b) + mo - modcomb.nCk(i-c,b)) % mo;

        // 赤は自動的に決まる

        lsum *= ycnt;
        lsum %= mo;

        sum += lsum;
        sum %= mo;
    }
    println!("{}",sum);
}
#[allow(dead_code)]
#[doc = " x ^ n % m"]
pub fn modpow(x: u64, n: u64, m: u64) -> u64 {
    let mut res = 1;
    let mut x = x % m;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            res = (res * x) % m;
        }
        x = (x * x) % m;
        n >>= 1;
    }
    res
}
struct ModComb {
    fact: Vec<u64>,
    fact_inv: Vec<u64>,
    n: u64,
    p: u64,
}
impl ModComb {
    fn initialize(ft: &mut Self) {
        let n = ft.n as usize;
        ft.fact[0] = 1;
        for i in 1..n {
            ft.fact[i] = (ft.fact[i - 1] * i as u64) % ft.p;
        }
        ft.fact_inv[n - 1] = modpow(ft.fact[n - 1], ft.p - 2, ft.p);
        for i in (0..n - 1).rev() {
            ft.fact_inv[i] = (ft.fact_inv[i + 1] * (i + 1) as u64) % ft.p;
        }
    }
    fn new(max_n: u64, p: u64) -> ModComb {
        let mut ft = ModComb {
            fact: vec![0; (max_n + 1) as usize],
            fact_inv: vec![0; (max_n + 1) as usize],
            n: max_n + 1,
            p: p,
        };
        Self::initialize(&mut ft);
        ft
    }
    fn fact(&self, n: usize) -> u64 {
        self.fact[n]
    }
    fn nCk(&self, n: u64, k: u64) -> u64 {
        if n < k {
            return 0;
        }
        (self.nPk(n, k) * self.fact_inv[k as usize]) % self.p
    }
    fn nPk(&self, n: u64, k: u64) -> u64 {
        if n < k {
            return 0;
        }
        self.fact[n as usize] * self.fact_inv[(n - k) as usize] % self.p
    }
    fn nHk(&self, n: u64, k: u64) -> u64 {
        if n == 0 && k == 0 {
            return 1;
        }
        self.nCk(n + k - 1, k)
    }
    fn nSk(&self, n: u64, k: u64) -> u64 {
        if n < k {
            return 0;
        }
        let mut res = 0;
        for i in 0..k + 1 {
            let v = self.nCk(k, i) * modpow(i, n, self.p) % self.p;
            if (k - i) % 2 == 1 {
                res = (res + self.p - v) % self.p;
            } else {
                res = (res + v) % self.p;
            }
        }
        return res * self.fact_inv[k as usize] % self.p;
    }
    fn nBk(&self, n: u64, k: u64) -> u64 {
        0
    }
}
0