diff --git a/atcoder/abc375/a.rs b/atcoder/abc375/a.rs new file mode 100644 index 00000000..77be7976 --- /dev/null +++ b/atcoder/abc375/a.rs @@ -0,0 +1,17 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + getline(); + let s = getline().trim().bytes().collect::>(); + let mut ans = 0; + for i in 2..s.len() { + if &s[i - 2..i + 1] == b"#.#" { + ans += 1; + } + } + println!("{ans}"); +} diff --git a/atcoder/abc375/b.rs b/atcoder/abc375/b.rs new file mode 100644 index 00000000..166a6958 --- /dev/null +++ b/atcoder/abc375/b.rs @@ -0,0 +1,51 @@ +// 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, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + input! { + n: usize, + xy: [(f64, f64); n], + } + let mut xy = xy; + xy.push((0.0, 0.0)); + let mut ans = 0.0; + for i in 0..n + 1 { + let j = (i + 1) % (n + 1); + let (x1, y1) = xy[i]; + let (x2, y2) = xy[j]; + let dx = x2 - x1; + let dy = y2 - y1; + let dist = (dx * dx + dy * dy).sqrt(); + ans += dist; + } + println!("{ans}"); +} diff --git a/atcoder/abc375/d.rs b/atcoder/abc375/d.rs new file mode 100644 index 00000000..20d053ef --- /dev/null +++ b/atcoder/abc375/d.rs @@ -0,0 +1,20 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + let mut occ = vec![vec![]; 26]; + for (i, c) in getline().trim().bytes().enumerate() { + occ[(c - b'A') as usize].push(i as i64); + } + let mut ans = 0; + for occ in occ { + let m = occ.len(); + for i in 0..m { + ans += occ[i] * (2 * i as i64 - m as i64 + 1) - i as i64; + } + } + println!("{ans}"); +} diff --git a/atcoder/abc375/e.rs b/atcoder/abc375/e.rs new file mode 100644 index 00000000..7e167fd3 --- /dev/null +++ b/atcoder/abc375/e.rs @@ -0,0 +1,65 @@ +// 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, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +const INF: i32 = 1 << 28; + +fn main() { + input! { + n: usize, + ab: [(i32, usize); n], + } + const W: usize = 501; + let bsum = ab.iter().map(|&(_, b)| b).sum::(); + if bsum % 3 != 0 { + println!("-1"); + return; + } + let mut dp = vec![vec![INF; W]; W]; + dp[0][0] = 0; + for (a, b) in ab { + let mut ep = vec![vec![INF; W]; W]; + for i in 0..W { + for j in 0..W { + ep[i][j] = ep[i][j].min(dp[i][j] + (a != 3) as i32); + if i + b < W { + ep[i + b][j] = ep[i + b][j].min(dp[i][j] + (a != 1) as i32); + } + if j + b < W { + ep[i][j + b] = ep[i][j + b].min(dp[i][j] + (a != 2) as i32); + } + } + } + dp = ep; + } + let ans = dp[bsum / 3][bsum / 3]; + println!("{}", if ans == INF { -1 } else { ans }); +} diff --git a/atcoder/abc375/remain.txt b/atcoder/abc375/remain.txt new file mode 100644 index 00000000..8c6a0e56 --- /dev/null +++ b/atcoder/abc375/remain.txt @@ -0,0 +1,3 @@ +c +f +g