結果

問題 No.566 だいたい完全二分木
ユーザー phsplsphspls
提出日時 2020-05-08 22:26:40
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 150,028 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 03:07:44
合計ジャッジ時間 1,851 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut k = String::new();
    std::io::stdin().read_line(&mut k).ok();
    let k: usize = k.trim().parse().unwrap();
    
    let upper: usize = 1<<k;
    let lower: usize = 1;
    let mid: usize = (upper + lower) / 2;
    let mut result: Vec<usize> = vec![];
    let mut temp: Vec<usize> = vec![];
    temp.push(lower);
    temp.push(mid);
    temp.push(upper);
    result.push(upper-1);
    result.push(mid);
    for i in 0..(k-1) {
        let lim = temp.len() - 1;
        for j in 0..lim {
            temp.push((temp[j+1] + temp[j]) / 2);
            result.push((temp[j+1] + temp[j]) / 2);
        }
        if i < k-2 {
            temp.sort();
        }
    }
    result.pop();
    println!("{}", result.iter().map(|i| i.to_string()).collect::<Vec<String>>().join(" "));
}
0