CSES - HIIT Open 2024 - Results
Submission details
Task:Equilateral numbers
Sender:Viestipojat
Submission time:2024-11-16 12:25:35 +0200
Language:Rust (2021)
Status:READY
Result:
Test results
testverdicttime
#1--details
#2--details
#3--details
#4--details
#5--details
#6--details
#7--details
#8--details
#9--details
#10--details
#11--details
#12--details

Code

use std::str::FromStr;
use std::fmt::Debug;

fn read<T: FromStr>() -> Vec<T>where <T as FromStr>::Err: Debug  {
    let stdin = std::io::stdin();
    let line = stdin.lines().next().unwrap().unwrap();
    line.split_whitespace().map(T::from_str).map(|x| x.unwrap()).collect()
}

fn main() {
    let n = read::<usize>()[0];

    let nums = (1..=1_501_000).map(|n| n * (n + 1) / 2).collect::<Vec<_>>();
    let mut r = vec![0; 1_501_000];
    
    r[1] = 1;

    for i in 2..1_501_000 {
        r[i] = 1 + nums.iter().take_while(|s| i >= **s).map(|s| r[i - s]).min().unwrap();
    }

    println!("{}",
        1 + nums.iter().filter_map(|s| r.get(n.wrapping_sub(*s))).min().unwrap()
    )

}

Test details

Test 1

Verdict:

input
1

correct output
1

user output
(empty)

Test 2

Verdict:

input
2

correct output
2

user output
(empty)

Test 3

Verdict:

input
3

correct output
1

user output
(empty)

Test 4

Verdict:

input
5

correct output
3

user output
(empty)

Test 5

Verdict:

input
33

correct output
3

user output
(empty)

Test 6

Verdict:

input
12385719843

correct output
3

user output
(empty)

Test 7

Verdict:

input
10935032

correct output
3

user output
(empty)

Test 8

Verdict:

input
659023495928

correct output
3

user output
(empty)

Test 9

Verdict:

input
913591235689

correct output
2

user output
(empty)

Test 10

Verdict:

input
999999911791

correct output
1

user output
(empty)

Test 11

Verdict:

input
1000000000000

correct output
2

user output
(empty)

Test 12

Verdict:

input
999999999998

correct output
3

user output
(empty)