|
| 1 | +use std::io::{Read, StdinLock}; |
| 2 | +use std::str::{from_utf8, FromStr}; |
| 3 | +use std::vec::Vec; |
| 4 | + |
| 5 | +struct StdinReader<'a> { |
| 6 | + reader: StdinLock<'a>, |
| 7 | +} |
| 8 | + |
| 9 | +impl<'a> StdinReader<'a> { |
| 10 | + pub fn new(reader: StdinLock<'a>) -> StdinReader { |
| 11 | + StdinReader { reader: reader } |
| 12 | + } |
| 13 | + |
| 14 | + pub fn read<T: FromStr>(&mut self) -> T { |
| 15 | + fn is_whitespace(ch: u8) -> bool { |
| 16 | + ch == 0x20 || ch == 0x0a || ch == 0x0d |
| 17 | + } |
| 18 | + |
| 19 | + let token: Vec<u8> = self.reader |
| 20 | + .by_ref() |
| 21 | + .bytes() |
| 22 | + .map(|ch| ch.expect("failed to read a byte")) |
| 23 | + .skip_while(|ch| is_whitespace(*ch)) |
| 24 | + .take_while(|ch| !is_whitespace(*ch)) |
| 25 | + .collect(); |
| 26 | + let token_str = from_utf8(&token) |
| 27 | + .unwrap_or_else(|_| panic!(format!("invalid utf8 sequence: {:?}", token))); |
| 28 | + token_str |
| 29 | + .parse() |
| 30 | + .unwrap_or_else(|_| panic!(format!("failed to parse input: {}", token_str))) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +fn f_50(c: i32, x: i32) -> i64 { |
| 35 | + if c * 50 >= x { |
| 36 | + 1 |
| 37 | + } else { |
| 38 | + 0 |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +fn f_100(b: i32, c: i32, x: i32) -> i64 { |
| 43 | + let mut sum: i64 = 0; |
| 44 | + for i in 0..(b + 1) { |
| 45 | + if x - i * 100 >= 0 { |
| 46 | + sum += f_50(c, x - i * 100); |
| 47 | + } |
| 48 | + } |
| 49 | + sum |
| 50 | +} |
| 51 | + |
| 52 | +fn f_500(a: i32, b: i32, c: i32, x: i32) -> i64 { |
| 53 | + let mut sum: i64 = 0; |
| 54 | + for i in 0..(a + 1) { |
| 55 | + if x - i * 500 >= 0 { |
| 56 | + sum += f_100(b, c, x - i * 500); |
| 57 | + } |
| 58 | + } |
| 59 | + sum |
| 60 | +} |
| 61 | + |
| 62 | +fn main() { |
| 63 | + let stdin = std::io::stdin(); |
| 64 | + let mut reader = StdinReader::new(stdin.lock()); |
| 65 | + |
| 66 | + let a: i32 = reader.read(); |
| 67 | + let b: i32 = reader.read(); |
| 68 | + let c: i32 = reader.read(); |
| 69 | + let x: i32 = reader.read(); |
| 70 | + |
| 71 | + println!("{}", f_500(a, b, c, x)); |
| 72 | +} |
0 commit comments