Skip to content

Commit

Permalink
abc183 a, b, c, d, e
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Aug 26, 2022
1 parent 7613cf7 commit 7a46a36
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 209 deletions.
88 changes: 86 additions & 2 deletions abc183/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 abc183/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "abc183"
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
2 changes: 1 addition & 1 deletion abc183/src/bin/a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ fn main() {
input! {
x: i64,
};
let ans = std::cmp::max(x, 0);
let ans = x.max(0);
println!("{}", ans);
}
16 changes: 9 additions & 7 deletions abc183/src/bin/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use proconio::input;

fn main() {
input! {
s_x: i64,
s_y: i64,
g_x: i64,
g_y: i64,
s: (f64, f64),
g: (f64, f64),
};
let a = (g_y + s_y) as f64 / (g_x - s_x) as f64;
let b = g_y as f64 - a * g_x as f64;
let ans = -b / a;
let g = (g.0, -g.1);
let dx = g.0 - s.0;
let dy = g.1 - s.1;
let a = dy / dx;
let b = -a * g.0 + g.1;
let x = -b / a;
let ans = x;
println!("{:.10}", ans);
}
24 changes: 14 additions & 10 deletions abc183/src/bin/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ use superslice::Ext;
fn main() {
input! {
n: usize,
k: u64,
t: [[u64; n]; n],
k: usize,
t: [[usize; n]; n],
};
let mut count = 0;

let mut count = 0_usize;
let mut is = (1..n).collect::<Vec<usize>>();
loop {
let mut sum = 0_u64;
let mut i = 0;
for &j in is.iter() {
sum += t[i][j];
i = j;
let mut time = 0_usize;
let mut prev = 0_usize;
for next in is.iter().copied() {
time += t[prev][next];
prev = next;
}
sum += t[i][0];
if sum == k {
time += t[prev][0];

if time == k {
count += 1;
}

if !is.next_permutation() {
break;
}
}

let ans = count;
println!("{}", ans);
}
23 changes: 9 additions & 14 deletions abc183/src/bin/d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ fn main() {
w: i64,
stp: [(usize, usize, i64); n],
};
let max_t = 2 * 100_000;
let mut sum = vec![0_i64; max_t + 1];
for (s_i, t_i, p_i) in stp {
sum[s_i] += p_i;
sum[t_i] -= p_i;
let mut used = vec![0; 200_000 + 1];
for (s, t, p) in stp {
used[s] += p;
used[t] -= p;
}
for i in 0..sum.len() - 1 {
sum[i + 1] += sum[i];
}
let mut all = true;
for &sum_i in sum.iter() {
if sum_i > w {
all = false;
}

for i in (0..used.len()).skip(1) {
used[i] += used[i - 1];
}
let ans = all;

let ans = used.into_iter().all(|u| u <= w);
println!("{}", if ans { "Yes" } else { "No" });
}
49 changes: 24 additions & 25 deletions abc183/src/bin/e.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
use modint::ModInt1000000007 as ModInt;
use proconio::input;
use proconio::marker::Chars;
use proconio::{input, marker::Chars};

fn main() {
input! {
h: usize,
w: usize,
s: [Chars; h],
};
let z = ModInt::new(0);
let o = ModInt::new(1);
let mut dp = vec![vec![z; w]; h];
let mut dp_x = vec![vec![z; w]; h];
let mut dp_y = vec![vec![z; w]; h];
let mut dp_z = vec![vec![z; w]; h];
dp[0][0] = o;
dp_x[0][0] = o;
dp_y[0][0] = o;
dp_z[0][0] = o;
for r in 0..h {
for c in 0..w {
if r == 0 && c == 0 {
let zero = ModInt::new(0);
let mut dp_x = vec![vec![zero; w]; h];
let mut dp_y = vec![vec![zero; w]; h];
let mut dp_z = vec![vec![zero; w]; h];
let mut dp = vec![vec![zero; w]; h];
dp[0][0] = ModInt::new(1);
dp_x[0][0] = ModInt::new(1);
dp_y[0][0] = ModInt::new(1);
dp_z[0][0] = ModInt::new(1);
for i in 0..h {
for j in 0..w {
if i == 0 && j == 0 {
continue;
}
if s[r][c] == '#' {
if s[i][j] == '#' {
continue;
}
dp_x[r][c] = if c > 0 { dp_x[r][c - 1] } else { z };
dp_y[r][c] = if r > 0 { dp_y[r - 1][c] } else { z };
dp_z[r][c] = if c > 0 && r > 0 {
dp_z[r - 1][c - 1]
let x = if j > 0 { dp_x[i][j - 1] } else { zero };
let y = if i > 0 { dp_y[i - 1][j] } else { zero };
let z = if i > 0 && j > 0 {
dp_z[i - 1][j - 1]
} else {
z
zero
};
dp[r][c] = dp_x[r][c] + dp_y[r][c] + dp_z[r][c];
dp_x[r][c] += dp[r][c];
dp_y[r][c] += dp[r][c];
dp_z[r][c] += dp[r][c];
dp[i][j] = x + y + z;
dp_x[i][j] = x + dp[i][j];
dp_y[i][j] = y + dp[i][j];
dp_z[i][j] = z + dp[i][j];
}
}

let ans = dp[h - 1][w - 1];
println!("{}", ans);
}
Expand Down
Loading

0 comments on commit 7a46a36

Please sign in to comment.