Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
138 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |