Submission #9431284


Source Code Expand

Copy
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn modpow(mut a: i64, n:usize, m: i64) -> i64 {
    let mut res:i64 = 1;
    let mut nn = n;
    while nn > 0 {
        if nn & 1 != 0 {
            res = res * a % m;
        }
        a = a * a % m;
        nn >>= 1;
    }
    res
}

fn main() {
    input!{
        n: usize,
        x: [i64;n],
    }
    let m:i64 = 1_000_000_007;
    // inverse mod
    let mut inv = vec![0;n+1];
    let mut inv_sum = vec![0;n+1];
    let mut fact:Vec<i64> = vec![0;n+1];
    fact[0] = 1;
    for i in 0..n {
        fact[i+1] = fact[i]*(i as i64 +1)%m;
    }
    inv[1] = modpow(1, n, m);
    inv_sum[1] = inv[1];
    for i in 2..n+1 {
        inv[i] = m - inv[(m as usize)%i] * (m/(i as i64)) % m;
        inv_sum[i] = inv_sum[i-1] + inv[i];
        inv_sum[i]%=m;
    }
    // println!("{:?}", inv_sum);
    let mut res:i64 = 0;
    for i in 1..n {
        res += ((x[i] - x[i-1])%m)*inv_sum[i]%m;
        res%=m;
    }
    println!("{}", res*fact[n-1]%m);
}

Submission Info

Submission Time
Task B - Fusing Slimes
User TateyamaKaito
Language Rust (1.15.1)
Score 600
Code Size 2634 Byte
Status AC
Exec Time 33 ms
Memory 8444 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 400 / 400 200 / 200
Status
AC × 2
AC × 15
AC × 32
Set Name Test Cases
Sample sample_01, sample_02
Subtask small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, small_09, small_10, small_max_01, small_max_02, small_max_03, small_max_04, small_max_05
All max_01, max_02, max_03, max_04, max_05, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, sample_01, sample_02, small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, small_09, small_10, small_max_01, small_max_02, small_max_03, small_max_04, small_max_05
Case Name Status Exec Time Memory
max_01 AC 32 ms 8444 KB
max_02 AC 32 ms 8444 KB
max_03 AC 32 ms 8444 KB
max_04 AC 33 ms 8444 KB
max_05 AC 32 ms 8444 KB
random_01 AC 9 ms 4352 KB
random_02 AC 30 ms 6396 KB
random_03 AC 18 ms 6396 KB
random_04 AC 14 ms 4352 KB
random_05 AC 3 ms 4352 KB
random_06 AC 17 ms 6396 KB
random_07 AC 6 ms 4352 KB
random_08 AC 12 ms 4352 KB
random_09 AC 22 ms 6396 KB
random_10 AC 14 ms 4352 KB
sample_01 AC 2 ms 4352 KB
sample_02 AC 2 ms 4352 KB
small_01 AC 2 ms 4352 KB
small_02 AC 2 ms 4352 KB
small_03 AC 2 ms 4352 KB
small_04 AC 2 ms 4352 KB
small_05 AC 2 ms 4352 KB
small_06 AC 2 ms 4352 KB
small_07 AC 2 ms 4352 KB
small_08 AC 2 ms 4352 KB
small_09 AC 2 ms 4352 KB
small_10 AC 2 ms 4352 KB
small_max_01 AC 2 ms 4352 KB
small_max_02 AC 2 ms 4352 KB
small_max_03 AC 2 ms 4352 KB
small_max_04 AC 2 ms 4352 KB
small_max_05 AC 2 ms 4352 KB