AC 042, started from the beginning of atcoder with rust to practice my rust
This commit is contained in:
11
atcoder/beginner_contests/abc042/src/bin/a.rs
Normal file
11
atcoder/beginner_contests/abc042/src/bin/a.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
mut abc: [u8; 3],
|
||||
};
|
||||
abc.sort();
|
||||
let ans = abc == vec![5, 5, 7];
|
||||
|
||||
println!("{}", if ans {"YES"} else {"NO"});
|
||||
}
|
||||
14
atcoder/beginner_contests/abc042/src/bin/b.rs
Normal file
14
atcoder/beginner_contests/abc042/src/bin/b.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use proconio::input;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
n: u8,
|
||||
_l: u8,
|
||||
mut s: [String; n],
|
||||
};
|
||||
|
||||
s.sort();
|
||||
for substring in s {
|
||||
print!("{}", substring);
|
||||
}
|
||||
}
|
||||
40
atcoder/beginner_contests/abc042/src/bin/c.rs
Normal file
40
atcoder/beginner_contests/abc042/src/bin/c.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use proconio::input;
|
||||
|
||||
fn check_number(n: u32, likes: &[bool; 10]) -> bool {
|
||||
let mut result = true;
|
||||
|
||||
let mut m = n;
|
||||
while m > 0 {
|
||||
let l = m % 10;
|
||||
|
||||
if !likes[l as usize] {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
m /= 10;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
mut n: u32,
|
||||
k: u32,
|
||||
d: [u32; k],
|
||||
};
|
||||
|
||||
let mut likes = [true; 10];
|
||||
for dislike in d {
|
||||
likes[dislike as usize] = false;
|
||||
}
|
||||
|
||||
let mut check = false;
|
||||
while !check {
|
||||
check = check_number(n, &likes);
|
||||
n += 1;
|
||||
}
|
||||
|
||||
print!("{}", n - 1);
|
||||
}
|
||||
43
atcoder/beginner_contests/abc042/src/bin/d.rs
Normal file
43
atcoder/beginner_contests/abc042/src/bin/d.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use proconio::input;
|
||||
|
||||
const MAX: u128 = u128::pow(10, 9) + 7;
|
||||
|
||||
fn main() {
|
||||
input!{
|
||||
h: u128,
|
||||
w: u128,
|
||||
a: u128,
|
||||
b: u128,
|
||||
};
|
||||
|
||||
// Ok it seems like this way is too naive for this problem and I actually have
|
||||
// to do some magic with combinations or something else I haven't even thought of
|
||||
|
||||
// But I don't think you can do combinations because you need to divide big numbers
|
||||
// and you can't do that with modulo iirc
|
||||
|
||||
let mut dp = vec![vec![0; w as usize]; h as usize];
|
||||
for i in 0..(h-a) {
|
||||
dp[i as usize][0] = 1;
|
||||
}
|
||||
for j in 0..w {
|
||||
dp[0][j as usize] = 1;
|
||||
}
|
||||
|
||||
for i in 1..h {
|
||||
for j in 1..w {
|
||||
if !(i >= h - a && j < b) {
|
||||
dp[i as usize][j as usize] = (dp[(i - 1) as usize][j as usize] + dp[i as usize][(j - 1) as usize]) % MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for row in &dp {
|
||||
// for cell in row {
|
||||
// print!("{} ", {cell});
|
||||
// }
|
||||
// print!("\n");
|
||||
// }
|
||||
|
||||
println!("{}", {dp[(h-1) as usize][(w-1) as usize]});
|
||||
}
|
||||
Reference in New Issue
Block a user