Submission #31645236


Source Code Expand

use std::collections::BTreeMap;

use proconio::input;

fn f(memo: &mut BTreeMap<i64, usize>, x: i64, y: i64) -> usize {
    if y == 1 {
        return (x - y).abs() as usize;
    }
    if let Some(&r) = memo.get(&y) {
        return r;
    }
    let v = if y % 2 == 0 {
        f(memo, x, y / 2) + 1
    } else {
        f(memo, x, y + 1).min(f(memo, x, y - 1)) + 1
    }
    .min((x - y).abs() as usize);
    memo.entry(y).or_insert(v);
    v
}

fn main() {
    input! {
        x: i64,
        y: i64,
    };
    let mut memo = BTreeMap::new();
    let ans = f(&mut memo, x, y);
    println!("{}", ans);
}

Submission Info

Submission Time
Task F - +1-1x2
User bouzuya
Language Rust (1.42.0)
Score 600
Code Size 608 Byte
Status AC
Exec Time 6 ms
Memory 2168 KiB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 600 / 600 0 / 0
Status
AC × 3
AC × 49
AC × 1
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All extreme_00.txt, extreme_01.txt, extreme_02.txt, extreme_03.txt, extreme_04.txt, handmade_00.txt, handmade_01.txt, handmade_02.txt, handmade_03.txt, handmade_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_exp_00.txt, random_exp_01.txt, random_exp_02.txt, random_exp_03.txt, random_exp_04.txt, random_exp_05.txt, random_exp_06.txt, random_exp_07.txt, random_exp_08.txt, random_exp_09.txt, random_exp_10.txt, random_exp_11.txt, random_exp_12.txt, random_exp_13.txt, random_exp_14.txt, random_exp_15.txt, random_small_00.txt, random_small_01.txt, random_small_02.txt, random_small_03.txt, random_small_04.txt, random_small_05.txt, random_small_06.txt, random_small_07.txt, random_small_08.txt, random_small_09.txt, sample_01.txt, sample_02.txt, sample_03.txt
after_contest after_contest_01.txt
Case Name Status Exec Time Memory
after_contest_01.txt AC 6 ms 2096 KiB
extreme_00.txt AC 1 ms 1992 KiB
extreme_01.txt AC 1 ms 2004 KiB
extreme_02.txt AC 1 ms 2040 KiB
extreme_03.txt AC 2 ms 2008 KiB
extreme_04.txt AC 2 ms 2160 KiB
handmade_00.txt AC 1 ms 1992 KiB
handmade_01.txt AC 1 ms 2164 KiB
handmade_02.txt AC 1 ms 2052 KiB
handmade_03.txt AC 1 ms 2084 KiB
handmade_04.txt AC 1 ms 2140 KiB
random_00.txt AC 1 ms 2104 KiB
random_01.txt AC 2 ms 2144 KiB
random_02.txt AC 2 ms 2076 KiB
random_03.txt AC 2 ms 2140 KiB
random_04.txt AC 1 ms 2096 KiB
random_05.txt AC 2 ms 2064 KiB
random_06.txt AC 2 ms 2092 KiB
random_07.txt AC 2 ms 2092 KiB
random_08.txt AC 1 ms 2160 KiB
random_09.txt AC 2 ms 2128 KiB
random_exp_00.txt AC 1 ms 2056 KiB
random_exp_01.txt AC 1 ms 2132 KiB
random_exp_02.txt AC 3 ms 2168 KiB
random_exp_03.txt AC 1 ms 2072 KiB
random_exp_04.txt AC 1 ms 2160 KiB
random_exp_05.txt AC 1 ms 2072 KiB
random_exp_06.txt AC 1 ms 2088 KiB
random_exp_07.txt AC 1 ms 2072 KiB
random_exp_08.txt AC 3 ms 2064 KiB
random_exp_09.txt AC 1 ms 2080 KiB
random_exp_10.txt AC 1 ms 2088 KiB
random_exp_11.txt AC 1 ms 2084 KiB
random_exp_12.txt AC 1 ms 2060 KiB
random_exp_13.txt AC 1 ms 1992 KiB
random_exp_14.txt AC 1 ms 2060 KiB
random_exp_15.txt AC 4 ms 2076 KiB
random_small_00.txt AC 2 ms 2052 KiB
random_small_01.txt AC 2 ms 2072 KiB
random_small_02.txt AC 1 ms 1988 KiB
random_small_03.txt AC 1 ms 1916 KiB
random_small_04.txt AC 2 ms 2048 KiB
random_small_05.txt AC 1 ms 2048 KiB
random_small_06.txt AC 3 ms 2048 KiB
random_small_07.txt AC 1 ms 2072 KiB
random_small_08.txt AC 1 ms 2048 KiB
random_small_09.txt AC 1 ms 2068 KiB
sample_01.txt AC 2 ms 1996 KiB
sample_02.txt AC 1 ms 2124 KiB
sample_03.txt AC 1 ms 2032 KiB