Skip to content

Commit

Permalink
math-and-algorithm 086-088
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Mar 15, 2022
1 parent 5299622 commit 03304e8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
23 changes: 18 additions & 5 deletions math-and-algorithm/src/bin/086.rs
@@ -1,10 +1,23 @@
use proconio::{input, marker::Usize1};
use proconio::{input, marker::Chars};

fn main() {
input! {
n: usize,
a: [Usize1; n],
_n: usize,
s: Chars,
};
let ans = n - a.len();
println!("{}", ans);
let ans = (|| {
let mut depth = 0_i64;
for s_i in s {
match s_i {
'(' => depth += 1,
')' => depth -= 1,
_ => unreachable!(),
}
if depth < 0 {
return false;
}
}
depth == 0
})();
println!("{}", if ans { "Yes" } else { "No" });
}
7 changes: 4 additions & 3 deletions math-and-algorithm/src/bin/087.rs
@@ -1,10 +1,11 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
};
let ans = n - a.len();
let modp = 1_000_000_007;
let x = (1 + n) * n / 2 % modp;
let ans = x * x % modp;
println!("{}", ans);
}
11 changes: 7 additions & 4 deletions math-and-algorithm/src/bin/088.rs
@@ -1,10 +1,13 @@
use proconio::{input, marker::Usize1};
use proconio::input;

fn main() {
input! {
n: usize,
a: [Usize1; n],
a: usize,
b: usize,
c: usize,
};
let ans = n - a.len();
let modp = 998_244_353;
let f = |x| (x + 1) * x / 2 % modp;
let ans = f(a) * f(b) % modp * f(c) % modp;
println!("{}", ans);
}

0 comments on commit 03304e8

Please sign in to comment.