結果
| 問題 |
No.391 CODING WAR
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-02 17:43:19 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 962 bytes |
| コンパイル時間 | 18,718 ms |
| コンパイル使用メモリ | 377,476 KB |
| 実行使用メモリ | 12,672 KB |
| 最終ジャッジ日時 | 2024-11-24 05:00:19 |
| 合計ジャッジ時間 | 44,290 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 3 WA * 3 TLE * 10 |
ソースコード
fn getline() -> String{
let mut __ret=String::new();
std::io::stdin().read_line(&mut __ret).ok();
return __ret;
}
fn nfactorial(x: i64, y: i64) -> i64 {
match y {
0 => 1,
_ => x * nfactorial(x-1, y-1) % 1000000007
}
}
fn mpow( x: i64, y: i64) -> i64 {
let (mut r,mut xx,mut yy) = (1, x, y);
while yy > 0 {
if (yy % 2) == 1 {
r = (r * xx) % 1000000007;
}
yy /= 2;
xx = (xx * xx) % 1000000007;
}
return r;
}
fn main(){
let s=getline();
let a:Vec<_>=s.trim().split(' ').collect();
let (n, m): (i64, i64) = (a[0].parse().unwrap(), a[1].parse().unwrap());
let mut r = mpow(m, n);
(1..m).for_each(|i| {
let patterns = mpow(m-i, n);
let zeros = nfactorial(m, i) * mpow(nfactorial(i, i), 1000000007-2);
r = (if (i % 2) == 0 {r + patterns * zeros} else {(r + 1000000007 - patterns * zeros) % 1000000007}) % 1000000007;
});
print!("{} ", r);
}