結果
問題 | No.916 Encounter On A Tree |
ユーザー | phspls |
提出日時 | 2020-02-06 23:49:17 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 2,795 bytes |
コンパイル時間 | 13,950 ms |
コンパイル使用メモリ | 378,672 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-25 07:00:29 |
合計ジャッジ時間 | 15,861 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 5 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 6 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 6 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 6 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 6 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 5 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 6 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 6 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 6 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
testcase_25 | AC | 6 ms
5,376 KB |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 6 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 6 ms
5,376 KB |
testcase_37 | AC | 6 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 1 ms
5,376 KB |
testcase_40 | AC | 6 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 1 ms
5,376 KB |
testcase_44 | AC | 1 ms
5,376 KB |
testcase_45 | AC | 2 ms
5,376 KB |
testcase_46 | AC | 1 ms
5,376 KB |
testcase_47 | AC | 1 ms
5,376 KB |
testcase_48 | AC | 1 ms
5,376 KB |
testcase_49 | AC | 1 ms
5,376 KB |
testcase_50 | AC | 1 ms
5,376 KB |
testcase_51 | AC | 1 ms
5,376 KB |
testcase_52 | AC | 1 ms
5,376 KB |
testcase_53 | AC | 1 ms
5,376 KB |
testcase_54 | AC | 1 ms
5,376 KB |
testcase_55 | AC | 1 ms
5,376 KB |
testcase_56 | AC | 1 ms
5,376 KB |
testcase_57 | AC | 1 ms
5,376 KB |
testcase_58 | AC | 1 ms
5,376 KB |
testcase_59 | AC | 1 ms
5,376 KB |
testcase_60 | AC | 1 ms
5,376 KB |
ソースコード
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 l: usize = dlrk[1]; let r: usize = dlrk[2]; let k: usize = dlrk[3]; let mut l_count = 0; let mut r_count = 0; for i in 1..=d { if l < 2i32.pow(i as u32) as usize { l_count = i; break; } } for i in 1..=d { if r < 2i32.pow(i as u32) as usize { r_count = i; break; } } 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; } if r_count - l_count == k { result *= 2i32.pow(r_count as u32 - l_count as u32) as usize; } else { result *= 2i32.pow(r_count as u32 - l_count as u32 + (k as u32 + l_count as u32 - r_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); } } }