結果
| 問題 |
No.916 Encounter On A Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-06 23:15:36 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,486 bytes |
| コンパイル時間 | 13,110 ms |
| コンパイル使用メモリ | 390,588 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-25 06:57:30 |
| 合計ジャッジ時間 | 14,711 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 44 WA * 12 |
ソースコード
use std::io::Read;
fn main() {
const DIVIDER: usize = 1_000_000_007;
let mut all_data = String::new();
std::io::stdin().read_to_string(&mut all_data).ok();
let dlrk: Vec<usize> = all_data.trim().split('\n').next().unwrap().trim().split_whitespace()
.map(|s| s.parse().unwrap())
.collect();
let d: usize = dlrk[0];
let mut l: usize = dlrk[1];
let mut r: usize = dlrk[2];
let k: usize = dlrk[3];
let mut l_count = 0;
let mut r_count = 0;
while l > 0 {
l /= 2;
l_count += 1;
}
while r > 0 {
r /= 2;
r_count += 1;
}
if l_count < r_count {
if (r_count - l_count + k) % 2 == 1 {
println!("{}", 0);
} else if r_count - l_count > k || r_count + l_count - 2 < k {
println!("{}", 0);
} else {
let mut result: usize = 1;
for depth in 1..=d {
if depth == r_count {
for i in 1..(2i32.pow(depth as u32 -1)) {
result *= i as usize;
result %= DIVIDER;
}
result *= 2i32.pow(r_count as u32 - l_count as u32 + (k as u32 - r_count as u32 + l_count as u32) / 2 - 1u32) as usize;
result %= DIVIDER;
} else {
for i in 1..=(2i32.pow(depth as u32 -1)) {
result *= i as usize;
result %= DIVIDER;
}
}
}
println!("{}", result);
}
} else {
if k < 2 || k % 2 != 0 || r_count + l_count - 2 < k {
println!("{}", 0);
} else {
let mut result: usize = 1;
for depth in 1..=d {
if depth == r_count {
for i in 1..(2i32.pow(depth as u32 -1) - 1) {
result *= i as usize;
result %= DIVIDER;
}
result *= 2i32.pow(depth as u32 -1) as usize;
result %= DIVIDER;
result *= 2i32.pow((k as u32) / 2 - 1) as usize;
result %= DIVIDER;
} else {
for i in 1..=(2i32.pow(depth as u32 -1)) {
result *= i as usize;
result %= DIVIDER;
}
}
}
println!("{}", result);
}
}
}