Submission #39357782


Source Code Expand

use std::collections::HashMap;

use proconio::input;

fn f(memo: &mut HashMap<usize, usize>, x: usize) -> usize {
    if x == 1 {
        return 1;
    }
    if let Some(count) = memo.get(&x) {
        return *count;
    }

    let count = 1 + f(memo, x / 2) * 2;
    memo.insert(x, count);
    count
}

fn main() {
    input! {
        h: usize,
    };
    let mut memo = HashMap::new();
    let ans = f(&mut memo, h);
    println!("{}", ans);
}

Submission Info

Submission Time
Task D - Caracal vs Monster
User bouzuya
Language Rust (1.42.0)
Score 400
Code Size 447 Byte
Status AC
Exec Time 7 ms
Memory 2140 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 22
Set Name Test Cases
Sample sample_01, sample_02, sample_03
All hand_01, hand_02, hand_03, hand_04, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_14, random_15, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
hand_01 AC 7 ms 2068 KiB
hand_02 AC 1 ms 2128 KiB
hand_03 AC 1 ms 2128 KiB
hand_04 AC 2 ms 2040 KiB
random_01 AC 2 ms 2052 KiB
random_02 AC 2 ms 2052 KiB
random_03 AC 1 ms 2112 KiB
random_04 AC 1 ms 2088 KiB
random_05 AC 1 ms 2140 KiB
random_06 AC 2 ms 2048 KiB
random_07 AC 2 ms 2068 KiB
random_08 AC 1 ms 2072 KiB
random_09 AC 1 ms 2012 KiB
random_10 AC 1 ms 1972 KiB
random_11 AC 1 ms 2056 KiB
random_12 AC 2 ms 2108 KiB
random_13 AC 1 ms 2096 KiB
random_14 AC 2 ms 2012 KiB
random_15 AC 1 ms 1900 KiB
sample_01 AC 1 ms 1976 KiB
sample_02 AC 2 ms 2092 KiB
sample_03 AC 1 ms 2028 KiB