Skip to content

Commit

Permalink
abc037 a, b, c, d
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jan 13, 2023
1 parent 8c2feb3 commit e554e27
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 76 deletions.
88 changes: 86 additions & 2 deletions abc037/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 abc037/Cargo.toml
@@ -1,11 +1,11 @@
[package]
name = "abc037"
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
8 changes: 4 additions & 4 deletions abc037/src/bin/a.rs
Expand Up @@ -2,10 +2,10 @@ use proconio::input;

fn main() {
input! {
a: i64,
b: i64,
c: i64,
a: usize,
b: usize,
c: usize,
};
let ans = c / std::cmp::min(a, b);
let ans = c / a.min(b);
println!("{}", ans);
}
15 changes: 7 additions & 8 deletions abc037/src/bin/b.rs
@@ -1,19 +1,18 @@
use proconio::input;
use proconio::marker::Usize1;
use proconio::{input, marker::Usize1};

fn main() {
input! {
n: usize,
q: usize,
lrt: [(Usize1, Usize1, i64); q],
lrt: [(Usize1, Usize1, usize); q],
};
let mut a = vec![0_i64; n];
for &(l_i, r_i, t_i) in lrt.iter() {
for j in l_i..=r_i {
a[j] = t_i;
let mut a = vec![0_usize; n];
for (l, r, t) in lrt {
for i in l..=r {
a[i] = t;
}
}
for &a_i in a.iter() {
for a_i in a {
println!("{}", a_i);
}
}
18 changes: 11 additions & 7 deletions abc037/src/bin/c.rs
Expand Up @@ -4,14 +4,18 @@ fn main() {
input! {
n: usize,
k: usize,
a: [i64; n],
a: [usize; n],
};
let mut s = a[0..k].iter().sum::<i64>();
let mut ans = s;
for i_l in 0..n - k {
s -= a[i_l];
s += a[i_l + k];
ans += s;
let mut sum = 0_usize;
for i in 0..k {
sum += a[i];
}
let mut ans = sum;
for i in k..n {
sum += a[i];
sum -= a[i - k];
ans += sum;
}

println!("{}", ans);
}
83 changes: 29 additions & 54 deletions abc037/src/bin/d.rs
@@ -1,69 +1,44 @@
use std::collections::BinaryHeap;

use proconio::input;

fn main() {
input! {
h: usize,
w: usize,
a: [[i64; w]; h],
a: [[usize; w]; h],
};
let mut e_i = vec![vec![]; w * h];
let mut e_o = vec![vec![]; w * h];
for r in 0..h {
for c in 0..w {
let v = a[r][c];
let dir = vec![(-1, 0), (0, -1), (0, 1), (1, 0)];
for (d_r, d_c) in dir.iter() {
let (r_n, c_n) = (r as i64 + d_r, c as i64 + d_c);
if (0..h as i64).contains(&r_n) && (0..w as i64).contains(&c_n) {
let (r_n, c_n) = (r_n as usize, c_n as usize);
let v_n = a[r_n][c_n];
if v_n < v {
e_i[r * w + c].push(r_n * w + c_n);
} else if v_n > v {
e_o[r * w + c].push(r_n * w + c_n);
}
}
}
}
}
let mut b = vec![];
for r in 0..h {
for c in 0..w {
b.push((a[r][c], r, c));

let mut pq = BinaryHeap::new();
for i in 0..h {
for j in 0..w {
pq.push((a[i][j], i, j));
}
}
b.sort_by_key(|(v, _, _)| -v);
let mut done = vec![false; h * w];
let mut d = vec![0; h * w];
for &(_, br, bc) in b.iter() {
if done[br * w + bc] {
continue;
}
let mut q = std::collections::VecDeque::new();
q.push_back(br * w + bc);
while let Some(p) = q.pop_front() {
done[p] = true;
d[p] += 1;
d[p] %= 1_000_000_007;
for &p_i in e_i[p].iter() {
d[p_i] += d[p];
d[p_i] %= 1_000_000_007;
for j in 0..e_o[p_i].len() {
if e_o[p_i][j] == p {
e_o[p_i].remove(j);
break;
}
}
if e_o[p_i].is_empty() {
q.push_back(p_i);
}

let mut dp = vec![vec![1_usize; w]; h];
while let Some((_, i, j)) = pq.pop() {
let dir = vec![(-1, 0), (0, -1), (0, 1), (1, 0)];
for (dr, dc) in dir {
let (nr, nc) = (i as i64 + dr, j as i64 + dc);
if !(0..h as i64).contains(&nr) || !(0..w as i64).contains(&nc) {
continue;
}
let (nr, nc) = (nr as usize, nc as usize);
if a[nr][nc] >= a[i][j] {
continue;
}
dp[nr][nc] += dp[i][j];
dp[nr][nc] %= 1_000_000_007;
}
}
let mut ans = 0;
for &d_i in d.iter() {
ans += d_i;
ans %= 1_000_000_007;

let mut ans = 0_usize;
for i in 0..h {
for j in 0..w {
ans += dp[i][j];
ans %= 1_000_000_007;
}
}
println!("{}", ans);
}

0 comments on commit e554e27

Please sign in to comment.