-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add atcoder/abc341/b.rs atcoder/abc341/c.rs atcoder/abc341/d.rs atcod…
…er/abc341/e.rs atcoder/abc341/f.rs
- Loading branch information
Showing
6 changed files
with
358 additions
and
5 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 | ||
macro_rules! input { | ||
($($r:tt)*) => { | ||
let stdin = std::io::stdin(); | ||
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); | ||
let mut next = move || -> String{ | ||
bytes.by_ref().map(|r|r.unwrap() as char) | ||
.skip_while(|c|c.is_whitespace()) | ||
.take_while(|c|!c.is_whitespace()) | ||
.collect() | ||
}; | ||
input_inner!{next, $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! input_inner { | ||
($next:expr) => {}; | ||
($next:expr,) => {}; | ||
($next:expr, $var:ident : $t:tt $($r:tt)*) => { | ||
let $var = read_value!($next, $t); | ||
input_inner!{$next $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! read_value { | ||
($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; | ||
($next:expr, [ $t:tt ; $len:expr ]) => { | ||
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() | ||
}; | ||
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); | ||
} | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
a: [i64; n], | ||
st: [(i64, i64); n - 1], | ||
} | ||
let mut x = a[0]; | ||
for i in 0..n - 1 { | ||
let (s, t) = st[i]; | ||
x = x / s * t + a[i + 1]; | ||
} | ||
println!("{}", x); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 | ||
macro_rules! input { | ||
($($r:tt)*) => { | ||
let stdin = std::io::stdin(); | ||
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); | ||
let mut next = move || -> String{ | ||
bytes.by_ref().map(|r|r.unwrap() as char) | ||
.skip_while(|c|c.is_whitespace()) | ||
.take_while(|c|!c.is_whitespace()) | ||
.collect() | ||
}; | ||
input_inner!{next, $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! input_inner { | ||
($next:expr) => {}; | ||
($next:expr,) => {}; | ||
($next:expr, $var:ident : $t:tt $($r:tt)*) => { | ||
let $var = read_value!($next, $t); | ||
input_inner!{$next $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! read_value { | ||
($next:expr, [ $t:tt ; $len:expr ]) => { | ||
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() | ||
}; | ||
($next:expr, chars) => { | ||
read_value!($next, String).chars().collect::<Vec<char>>() | ||
}; | ||
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); | ||
} | ||
|
||
fn main() { | ||
input! { | ||
h: usize, w: usize, _n: usize, | ||
t: chars, | ||
s: [chars; h], | ||
} | ||
let mut ans = 0; | ||
for i in 0..h { | ||
for j in 0..w { | ||
if s[i][j] == '#' { continue; } | ||
let mut ok = true; | ||
let mut x = i; | ||
let mut y = j; | ||
for &c in &t { | ||
let (nx, ny) = match c { | ||
'U' => (x.wrapping_sub(1), y), | ||
'D' => (x + 1, y), | ||
'L' => (x, y.wrapping_sub(1)), | ||
'R' => (x, y + 1), | ||
_ => panic!(), | ||
}; | ||
if s[nx][ny] == '#' { | ||
ok = false; | ||
break; | ||
} | ||
x = nx; | ||
y = ny; | ||
} | ||
if ok { | ||
ans += 1; | ||
} | ||
} | ||
} | ||
println!("{ans}"); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::io::Read; | ||
|
||
fn get_word() -> String { | ||
let stdin = std::io::stdin(); | ||
let mut stdin=stdin.lock(); | ||
let mut u8b: [u8; 1] = [0]; | ||
loop { | ||
let mut buf: Vec<u8> = Vec::with_capacity(16); | ||
loop { | ||
let res = stdin.read(&mut u8b); | ||
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' { | ||
break; | ||
} else { | ||
buf.push(u8b[0]); | ||
} | ||
} | ||
if buf.len() >= 1 { | ||
let ret = String::from_utf8(buf).unwrap(); | ||
return ret; | ||
} | ||
} | ||
} | ||
|
||
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() } | ||
|
||
fn gcd(a: i64, b: i64) -> i64 { | ||
if b == 0 { | ||
a | ||
} else { | ||
gcd(b, a % b) | ||
} | ||
} | ||
|
||
fn main() { | ||
let n: i64 = get(); | ||
let m: i64 = get(); | ||
let k: i64 = get(); | ||
let g = gcd(n, m); | ||
let l = n / g * m; | ||
let mut fail = 0; | ||
let mut pass = n * k * 2; | ||
while pass - fail > 1 { | ||
let mid = (pass + fail) / 2; | ||
let cnt = mid / n + mid / m - mid / l * 2; | ||
if cnt >= k { | ||
pass = mid; | ||
} else { | ||
fail = mid; | ||
} | ||
} | ||
println!("{}", pass); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
use std::io::{Write, BufWriter}; | ||
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 | ||
macro_rules! input { | ||
($($r:tt)*) => { | ||
let stdin = std::io::stdin(); | ||
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); | ||
let mut next = move || -> String{ | ||
bytes.by_ref().map(|r|r.unwrap() as char) | ||
.skip_while(|c|c.is_whitespace()) | ||
.take_while(|c|!c.is_whitespace()) | ||
.collect() | ||
}; | ||
input_inner!{next, $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! input_inner { | ||
($next:expr) => {}; | ||
($next:expr,) => {}; | ||
($next:expr, $var:ident : $t:tt $($r:tt)*) => { | ||
let $var = read_value!($next, $t); | ||
input_inner!{$next $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! read_value { | ||
($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; | ||
($next:expr, [ $t:tt ; $len:expr ]) => { | ||
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() | ||
}; | ||
($next:expr, chars) => { | ||
read_value!($next, String).chars().collect::<Vec<char>>() | ||
}; | ||
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); | ||
} | ||
|
||
// Segment Tree. This data structure is useful for fast folding on intervals of an array | ||
// whose elements are elements of monoid I. Note that constructing this tree requires the identity | ||
// element of I and the operation of I. | ||
// Verified by: yukicoder No. 2220 (https://yukicoder.me/submissions/841554) | ||
struct SegTree<I, BiOp> { | ||
n: usize, | ||
orign: usize, | ||
dat: Vec<I>, | ||
op: BiOp, | ||
e: I, | ||
} | ||
|
||
impl<I, BiOp> SegTree<I, BiOp> | ||
where BiOp: Fn(I, I) -> I, | ||
I: Copy { | ||
pub fn new(n_: usize, op: BiOp, e: I) -> Self { | ||
let mut n = 1; | ||
while n < n_ { n *= 2; } // n is a power of 2 | ||
SegTree {n: n, orign: n_, dat: vec![e; 2 * n - 1], op: op, e: e} | ||
} | ||
// ary[k] <- v | ||
pub fn update(&mut self, idx: usize, v: I) { | ||
debug_assert!(idx < self.orign); | ||
let mut k = idx + self.n - 1; | ||
self.dat[k] = v; | ||
while k > 0 { | ||
k = (k - 1) / 2; | ||
self.dat[k] = (self.op)(self.dat[2 * k + 1], self.dat[2 * k + 2]); | ||
} | ||
} | ||
// [a, b) (half-inclusive) | ||
// http://proc-cpuinfo.fixstars.com/2017/07/optimize-segment-tree/ | ||
#[allow(unused)] | ||
pub fn query(&self, rng: std::ops::Range<usize>) -> I { | ||
let (mut a, mut b) = (rng.start, rng.end); | ||
debug_assert!(a <= b); | ||
debug_assert!(b <= self.orign); | ||
let mut left = self.e; | ||
let mut right = self.e; | ||
a += self.n - 1; | ||
b += self.n - 1; | ||
while a < b { | ||
if (a & 1) == 0 { | ||
left = (self.op)(left, self.dat[a]); | ||
} | ||
if (b & 1) == 0 { | ||
right = (self.op)(self.dat[b - 1], right); | ||
} | ||
a = a / 2; | ||
b = (b - 1) / 2; | ||
} | ||
(self.op)(left, right) | ||
} | ||
} | ||
|
||
fn main() { | ||
let out = std::io::stdout(); | ||
let mut out = BufWriter::new(out.lock()); | ||
macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} | ||
input! { | ||
n: usize, q: usize, | ||
s: chars, | ||
tlr: [(i32, usize, usize); q], | ||
} | ||
let mut st = SegTree::new(n, |x, y| x + y, 0); | ||
for i in 0..n - 1 { | ||
if s[i] == s[i + 1] { | ||
st.update(i, 1); | ||
} | ||
} | ||
for (t, l, r) in tlr { | ||
if t == 1 { | ||
if l >= 2 { | ||
let tmp = st.query(l - 2..l - 1); | ||
st.update(l - 2, tmp ^ 1); | ||
} | ||
if r < n { | ||
let tmp = st.query(r - 1..r); | ||
st.update(r - 1, tmp ^ 1); | ||
} | ||
} else { | ||
let sum = st.query(l - 1..r - 1); | ||
puts!("{}\n", if sum == 0 { "Yes" } else { "No" }); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 | ||
macro_rules! input { | ||
($($r:tt)*) => { | ||
let stdin = std::io::stdin(); | ||
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); | ||
let mut next = move || -> String{ | ||
bytes.by_ref().map(|r|r.unwrap() as char) | ||
.skip_while(|c|c.is_whitespace()) | ||
.take_while(|c|!c.is_whitespace()) | ||
.collect() | ||
}; | ||
input_inner!{next, $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! input_inner { | ||
($next:expr) => {}; | ||
($next:expr,) => {}; | ||
($next:expr, $var:ident : $t:tt $($r:tt)*) => { | ||
let $var = read_value!($next, $t); | ||
input_inner!{$next $($r)*} | ||
}; | ||
} | ||
|
||
macro_rules! read_value { | ||
($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; | ||
($next:expr, [ $t:tt ; $len:expr ]) => { | ||
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() | ||
}; | ||
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); | ||
} | ||
|
||
fn main() { | ||
input! { | ||
n: usize, m: usize, | ||
uv: [(usize, usize); m], | ||
w: [usize; n], | ||
a: [i64; n], | ||
} | ||
let mut g = vec![vec![]; n]; | ||
for &(u, v) in &uv { | ||
if w[u - 1] < w[v - 1] { | ||
g[v - 1].push(u - 1); | ||
} | ||
if w[u - 1] > w[v - 1] { | ||
g[u - 1].push(v - 1); | ||
} | ||
} | ||
let mut ord = vec![]; | ||
for i in 0..n { | ||
ord.push((w[i], i)); | ||
} | ||
ord.sort(); | ||
let mut dp = vec![0i64; n]; | ||
const W: usize = 5001; | ||
for (_, v) in ord { | ||
let mut ep = vec![0i64; W]; | ||
for &u in &g[v] { | ||
for i in (w[u]..W).rev() { | ||
ep[i] = ep[i].max(ep[i - w[u]] + dp[u]); | ||
} | ||
} | ||
dp[v] = ep[w[v] - 1] + 1; | ||
} | ||
let mut tot = 0; | ||
for i in 0..n { | ||
tot += dp[i] * a[i]; | ||
} | ||
println!("{}", tot); | ||
} |
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,6 +1 @@ | ||
b | ||
c | ||
d | ||
e | ||
f | ||
g |