Skip to content

Commit

Permalink
abc060 a, b, c, d
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Sep 28, 2022
1 parent 849db2c commit ed9fdbb
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 33 deletions.
88 changes: 86 additions & 2 deletions abc060/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion abc060/Cargo.toml
@@ -1,11 +1,11 @@
[package]
name = "abc060"
version = "0.1.0"
authors = ["bouzuya <m@bouzuya.net>"]
edition = "2018"

# dependencies added to new project
[dependencies]
num = "=0.2.1"
proconio = { version = "=0.3.6", features = ["derive"] }
superslice = "=1.0.0"

Expand Down
5 changes: 2 additions & 3 deletions abc060/src/bin/a.rs
@@ -1,12 +1,11 @@
use proconio::input;
use proconio::marker::Chars;
use proconio::{input, marker::Chars};

fn main() {
input! {
a: Chars,
b: Chars,
c: Chars,
};
let ans = a[a.len() - 1] == b[0] && b[b.len() - 1] == c[0];
let ans = a.last() == b.first() && b.last() == c.first();
println!("{}", if ans { "YES" } else { "NO" });
}
21 changes: 12 additions & 9 deletions abc060/src/bin/b.rs
@@ -1,16 +1,19 @@
use std::collections::HashSet;

use proconio::input;

fn main() {
input! {
a: u64,
b: u64,
c: u64,
a: usize,
b: usize,
c: usize,
};
for x in 1..b {
if (x * a) % b == c {
println!("YES");
return;
}
let mut x = a;
let mut set = HashSet::new();
while set.insert(x % b) {
x += a;
x %= b;
}
println!("NO");
let ans = set.contains(&c);
println!("{}", if ans { "YES" } else { "NO" });
}
17 changes: 7 additions & 10 deletions abc060/src/bin/c.rs
Expand Up @@ -3,17 +3,14 @@ use proconio::input;
fn main() {
input! {
n: usize,
t_l: i64,
t: [i64; n],
capital_t: usize,
t: [usize; n],
};
let mut s = 0;
for (t_i0, t_i1) in t.windows(2).map(|w| match w {
&[t_i0, t_i1] => (t_i0, t_i1),
_ => unreachable!(),
}) {
s += std::cmp::min(t_l, t_i1 - t_i0);
let mut sum = 0_usize;
for i in 0..n - 1 {
sum += (t[i + 1] - t[i]).min(capital_t);
}
s += t_l;
let ans = s;
sum += capital_t;
let ans = sum;
println!("{}", ans);
}
18 changes: 10 additions & 8 deletions abc060/src/bin/d.rs
Expand Up @@ -17,21 +17,23 @@ fn main() {
w: usize,
wv: [(usize, usize); n],
};
let mut dp = vec![vec![vec![0; 400 + 1]; n + 1]; n + 1];
let w_1 = wv[0].0;
for (i, (w_i, v_i)) in wv.iter().enumerate() {
for j in 0..=n {
for k in 0..=400 {
let mut dp = vec![vec![vec![0_usize; 4 * n + 1]; n + 1]; n + 1];
for (i, (w_i, v_i)) in wv.iter().copied().enumerate() {
for j in 0..n {
for k in 0..4 * n {
chmax!(dp[i + 1][j][k], dp[i][j][k]);
if j + 1 <= n && k + w_i - w_1 <= 400 && w_1 * j + w_i + k <= w {
chmax!(dp[i + 1][j + 1][k + w_i - w_1], dp[i][j][k] + v_i);
if (j + 1) * w_1 + k + (w_i - w_1) <= w && k + (w_i - w_1) <= 4 * n {
chmax!(dp[i + 1][j + 1][k + (w_i - w_1)], dp[i][j][k] + v_i);
}
}
}
}
let mut ans = 0;
let mut ans = 0_usize;
for j in 0..=n {
chmax!(ans, *dp[n][j].iter().max().unwrap());
for k in 0..4 * n {
ans = ans.max(dp[n][j][k]);
}
}
println!("{}", ans);
}

0 comments on commit ed9fdbb

Please sign in to comment.