結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー pekempeypekempey
提出日時 2018-03-02 23:04:55
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 147,144 KB
実行使用メモリ 25,692 KB
最終ジャッジ日時 2023-09-04 06:35:13
合計ジャッジ時間 3,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
25,616 KB
testcase_01 AC 25 ms
25,616 KB
testcase_02 AC 25 ms
25,612 KB
testcase_03 AC 25 ms
25,620 KB
testcase_04 AC 25 ms
25,612 KB
testcase_05 AC 25 ms
25,604 KB
testcase_06 AC 24 ms
25,600 KB
testcase_07 AC 24 ms
25,564 KB
testcase_08 AC 24 ms
25,612 KB
testcase_09 AC 25 ms
25,608 KB
testcase_10 AC 25 ms
25,612 KB
testcase_11 AC 24 ms
25,620 KB
testcase_12 AC 25 ms
25,684 KB
testcase_13 AC 23 ms
25,624 KB
testcase_14 AC 24 ms
25,624 KB
testcase_15 AC 24 ms
25,616 KB
testcase_16 AC 25 ms
25,604 KB
testcase_17 AC 25 ms
25,608 KB
testcase_18 AC 25 ms
25,608 KB
testcase_19 AC 25 ms
25,648 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 24 ms
25,608 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

const MOD: i64 = 1000000007;

fn main() {
  let n: usize = input();  

  let mut inv: Vec<i64> = vec![0; 1010101];
  let mut fact: Vec<i64> = vec![0; 1010101];
  let mut ifact: Vec<i64> = vec![0; 1010101];

  inv[1] = 1;
  fact[0] = 1;
  fact[1] = 1;
  ifact[0] = 1;
  ifact[1] = 1;

  for i in 2..inv.len() {
    inv[i] = inv[(MOD % (i as i64)) as usize] * (MOD - MOD / (i as i64)) % MOD;
    fact[i] = (i as i64) * fact[i - 1] % MOD;
    ifact[i] = inv[i] * ifact[i - 1] % MOD;
  }

  let f = |x: usize, y: usize| {
    if (x + y) % 2 == 1 {
      0
    } else {
      let n = x;
      let r = (x + y) / 2;
      if n >= r {
        fact[n] * ifact[r] % MOD * ifact[n - r] % MOD
      } else {
        0
      }
    }
  };

  let mut ans: i64 = 0;
  for i in 1..(2*n + 1) {
    ans += f(i - 1, n - 1) - f(i - 1, n + 1);
  }

  println!("{}", ans);
}

fn input<T: std::str::FromStr>() -> T {
  use std::io::Read;
  let stdin = std::io::stdin();
  let stdin = stdin.bytes();
  let token = stdin
    .skip_while(|x| (*x.as_ref().unwrap() as char).is_whitespace())
    .take_while(|x| !(*x.as_ref().unwrap() as char).is_whitespace())
    .map(|x| x.unwrap())
    .collect();
  let token = String::from_utf8(token).unwrap();
  match token.parse() {
    Ok(x) => x,
    Err(_) => panic!("{}", token),
  }
}
0