Problem:
Score: 300 points

Problem Statement

AtCoder Mart sells 1000000 of each of the six items below:

Riceballs, priced at 100 yen (the currency of Japan) each

Sandwiches, priced at 101 yen each

Cookies, priced at 102 yen each

Cakes, priced at 103 yen each

Candies, priced at 104 yen each

Computers, priced at 105 yen each

Takahashi wants to buy some of them that cost exactly X yen in total.
Determine whether this is possible.

(Ignore consumption tax.)

Constraints

1 \leq X \leq 100000

X is an integer.

Input

Input is given from Standard Input in the following format:

X

Output

If it is possible to buy some set of items that cost exactly X yen in total, print 1; otherwise, print 0.

Sample Input 1

615

Sample Output 1

1

For example, we can buy one of each kind of item, which will cost 100+101+102+103+104+105=615 yen in total.

Sample Input 2

217

Sample Output 2

0

No set of items costs 217 yen in total.

Solution in Rust (1.42.0) (judge verdict: Accepted)

use whiteread::parse_line;

fn calc(n: usize, dp: &mut Vec<bool>, price: &[usize; 6]) -> bool {
    if !dp[n] && n > 105 {
        dp[n] |= match n % 5 {
            x @ 1..=4 => calc(n - price[x], dp, price),
            _ => calc(n - price[0], dp, price) | calc(n - price[5], dp, price),
        };
    }
    dp[n]
}

fn main() {
    let x: usize = parse_line().unwrap();
    let price: [usize; 6] = [100, 101, 102, 103, 104, 105];
    let mut dp: Vec<bool> = vec![false; x + 1];

    dp[0] = true;
    for &p in &price {
        let mut idx = 0;
        while idx <= x {
            dp[idx] = true;
            idx += p;
        }
    }

    calc(x, &mut dp, &price);
    if dp[x] {
        println!("1");
    } else {
        println!("0");
    }
}