AC 042, started from the beginning of atcoder with rust to practice my rust
This commit is contained in:
25
atcoder/beginner_contests/abc042/Cargo.lock
generated
Normal file
25
atcoder/beginner_contests/abc042/Cargo.lock
generated
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "abc042"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"proconio",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proconio"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91c333be3af2936f8e810300bc74fe4d0cc168ebc04ab02a28c5b1060fa1bd59"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static",
|
||||||
|
]
|
||||||
12
atcoder/beginner_contests/abc042/Cargo.toml
Normal file
12
atcoder/beginner_contests/abc042/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "abc042"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# dependencies added to new project
|
||||||
|
[dependencies]
|
||||||
|
proconio = "0.4.3"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
panic = 'abort'
|
||||||
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