Submission #51450732
Source Code Expand
use std::collections::HashMap;
use proconio::input;
fn f(x: usize, y: usize, map: &mut HashMap<(usize, usize), usize>, c: usize, n: usize) {
if map.get(&(c, n)).is_some() {
return;
}
if n >= 2 {
if c == 1 {
f(x, y, map, 1, n - 1);
f(x, y, map, 0, n);
map.insert(
(c, n),
map.get(&(1, n - 1)).unwrap_or(&0) + map.get(&(0, n)).unwrap_or(&0) * x,
);
} else {
f(x, y, map, 0, n - 1);
f(x, y, map, 1, n - 1);
map.insert(
(c, n),
map.get(&(1, n - 1)).unwrap_or(&0) + map.get(&(0, n - 1)).unwrap_or(&0) * y,
);
}
}
}
fn main() {
input! {
n: usize,
x: usize,
y: usize,
};
let mut map = HashMap::new();
map.insert((1, 1), 0);
map.insert((0, 1), 1);
f(x, y, &mut map, 1, n);
let ans = map.get(&(1, n)).unwrap();
println!("{}", ans);
}
Submission Info
| Submission Time |
|
| Task |
E - Changing Jewels |
| User |
bouzuya |
| Language |
Rust (rustc 1.70.0) |
| Score |
300 |
| Code Size |
993 Byte |
| Status |
AC |
| Exec Time |
1 ms |
| Memory |
2088 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
300 / 300 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 02_n_max_00.txt, 02_n_max_01.txt, 02_n_max_02.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
1968 KiB |
| 00_sample_01.txt |
AC |
1 ms |
1864 KiB |
| 00_sample_02.txt |
AC |
1 ms |
1808 KiB |
| 01_random_00.txt |
AC |
0 ms |
1976 KiB |
| 01_random_01.txt |
AC |
0 ms |
1860 KiB |
| 01_random_02.txt |
AC |
1 ms |
1936 KiB |
| 02_n_max_00.txt |
AC |
0 ms |
1940 KiB |
| 02_n_max_01.txt |
AC |
1 ms |
2088 KiB |
| 02_n_max_02.txt |
AC |
1 ms |
1940 KiB |