From 1868a3bc76c54bd2c284ada448afede7ad769687 Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Sun, 25 Aug 2024 00:25:36 +0900 Subject: [PATCH] Add atcoder/abc368/a.rs atcoder/abc368/b.rs atcoder/abc368/c.rs atcoder/abc368/d.rs atcoder/abc368/e.rs atcoder/abc368/f.rs atcoder/abc368/remain.txt --- atcoder/abc368/a.rs | 51 ++++++++++++++++++++++ atcoder/abc368/b.rs | 46 ++++++++++++++++++++ atcoder/abc368/c.rs | 60 +++++++++++++++++++++++++ atcoder/abc368/d.rs | 69 +++++++++++++++++++++++++++++ atcoder/abc368/e.rs | 92 +++++++++++++++++++++++++++++++++++++++ atcoder/abc368/f.rs | 54 +++++++++++++++++++++++ atcoder/abc368/remain.txt | 1 + 7 files changed, 373 insertions(+) create mode 100644 atcoder/abc368/a.rs create mode 100644 atcoder/abc368/b.rs create mode 100644 atcoder/abc368/c.rs create mode 100644 atcoder/abc368/d.rs create mode 100644 atcoder/abc368/e.rs create mode 100644 atcoder/abc368/f.rs create mode 100644 atcoder/abc368/remain.txt diff --git a/atcoder/abc368/a.rs b/atcoder/abc368/a.rs new file mode 100644 index 00000000..98e2ad2d --- /dev/null +++ b/atcoder/abc368/a.rs @@ -0,0 +1,51 @@ +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 ; $len:expr ]) => { + (0..$len).map(|_| read_value!($next, $t)).collect::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + let out = std::io::stdout(); + let mut out = BufWriter::new(out.lock()); + macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} + macro_rules! putvec { + ($v:expr) => { + for i in 0..$v.len() { + puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "}); + } + } + } + input! { + n: usize, k: usize, + a: [i64; n], + } + let mut b = a[n - k..].to_vec(); + b.extend_from_slice(&a[..n - k]); + putvec!(b); +} diff --git a/atcoder/abc368/b.rs b/atcoder/abc368/b.rs new file mode 100644 index 00000000..3e5266d5 --- /dev/null +++ b/atcoder/abc368/b.rs @@ -0,0 +1,46 @@ +// 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::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + input! { + n: usize, + a: [i64; n], + } + let mut a = a; + let mut c = 0; + while a.iter().filter(|&&x| x > 0).count() > 1 { + a.sort(); a.reverse(); + a[0] -= 1; + a[1] -= 1; + c += 1; + } + println!("{}", c); +} diff --git a/atcoder/abc368/c.rs b/atcoder/abc368/c.rs new file mode 100644 index 00000000..e8eb693a --- /dev/null +++ b/atcoder/abc368/c.rs @@ -0,0 +1,60 @@ +// 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::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + input! { + n: usize, + h: [i64; n], + } + let mut t = 0; + for mut h in h { + while h > 0 && t % 3 != 0 { + if t % 3 == 2 { + h -= 3; + } else { + h -= 1; + } + t += 1; + } + let q = h / 5; + h -= q * 5; + t += q * 3; + while h > 0 { + if t % 3 == 2 { + h -= 3; + } else { + h -= 1; + } + t += 1; + } + } + println!("{}", t); +} diff --git a/atcoder/abc368/d.rs b/atcoder/abc368/d.rs new file mode 100644 index 00000000..c1acfa61 --- /dev/null +++ b/atcoder/abc368/d.rs @@ -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),* )) => { ($(read_value!($next, $t)),*) }; + ($next:expr, [ $t:tt ; $len:expr ]) => { + (0..$len).map(|_| read_value!($next, $t)).collect::>() + }; + ($next:expr, usize1) => (read_value!($next, usize) - 1); + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + input! { + n: usize, k: usize, + ab: [(usize1, usize1); n - 1], + v: [usize1; k], + } + let mut deg = vec![0; n]; + let mut g = vec![vec![]; n]; + for &(a, b) in &ab { + deg[a] += 1; + deg[b] += 1; + g[a].push(b); + g[b].push(a); + } + let mut ret = vec![false; n]; + for v in v { + ret[v] = true; + } + let mut que = vec![]; + for i in 0..n { + if deg[i] == 1 && !ret[i] { + que.push(i); + } + } + let mut ans = n; + while let Some(v) = que.pop() { + ans -= 1; + for &to in &g[v] { + deg[to] -= 1; + if deg[to] == 1 && !ret[to] { + que.push(to); + } + } + } + println!("{}", ans); +} diff --git a/atcoder/abc368/e.rs b/atcoder/abc368/e.rs new file mode 100644 index 00000000..22e11517 --- /dev/null +++ b/atcoder/abc368/e.rs @@ -0,0 +1,92 @@ +use std::collections::*; +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::>() + }; + ($next:expr, usize1) => (read_value!($next, usize) - 1); + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +// Tags: dual-of-linear-programming, shortest-path, dijkstra, extra-vertices +fn main() { + let out = std::io::stdout(); + let mut out = BufWriter::new(out.lock()); + macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} + macro_rules! putvec { + ($v:expr) => { + for i in 0..$v.len() { + puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "}); + } + } + } + input! { + n: usize, m: usize, x0: i64, + abst: [(usize1, usize1, i64, i64); m], + } + let mut occ = vec![vec![]; n]; + for i in 0..m { + let (a, b, s, t) = abst[i]; + occ[a].push((s, 1, i)); + occ[b].push((t, -1, i)); + } + let mut new = m; + let mut g = vec![vec![]; 2 * m]; + for i in 0..n { + occ[i].sort(); + let mut last: Option<(usize, i64)> = None; + for j in 0..occ[i].len() { + let now = occ[i][j]; + if now.1 == -1 { + if let Some((idx, time)) = last { + g[idx].push((new, now.0 - time)); + } + last = Some((new, now.0)); + g[now.2].push((new, 0)); + new += 1; + } else { + if let Some((idx, time)) = last { + g[idx].push((now.2, now.0 - time)); + } + } + } + } + let mut que = BinaryHeap::new(); + let mut dist = vec![0; 2 * m]; + que.push((x0, 0)); + while let Some((d, v)) = que.pop() { + if dist[v] >= d { + continue; + } + dist[v] = d; + for &(w, c) in &g[v] { + que.push(((d - c).max(0), w)); + } + } + putvec!(dist[1..m]); +} diff --git a/atcoder/abc368/f.rs b/atcoder/abc368/f.rs new file mode 100644 index 00000000..530fff2a --- /dev/null +++ b/atcoder/abc368/f.rs @@ -0,0 +1,54 @@ +// 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::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + input! { + n: usize, + a: [usize; n], + } + const W: usize = 100_001; + let mut g = vec![0; W]; + let mut seen = vec![vec![]; W]; + for i in 1..W { + seen[i].sort(); seen[i].dedup(); + while seen[i].binary_search(&g[i]).is_ok() { + g[i] += 1; + } + for j in 2..(W - 1) / i + 1 { + seen[i * j].push(g[i]); + } + } + let mut ans = 0; + for a in a { + ans ^= g[a]; + } + println!("{}", if ans == 0 { "Bruno" } else { "Anna" }); +} diff --git a/atcoder/abc368/remain.txt b/atcoder/abc368/remain.txt new file mode 100644 index 00000000..01058d84 --- /dev/null +++ b/atcoder/abc368/remain.txt @@ -0,0 +1 @@ +g