Skip to content

Commit

Permalink
Add atcoder/abc375/a.rs atcoder/abc375/b.rs atcoder/abc375/d.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc375/e.rs atcoder/abc375/remain.txt
  • Loading branch information
koba-e964 committed Nov 8, 2024
1 parent 2a731fb commit ce61405
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
17 changes: 17 additions & 0 deletions atcoder/abc375/a.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>();
let mut ans = 0;
for i in 2..s.len() {
if &s[i - 2..i + 1] == b"#.#" {
ans += 1;
}
}
println!("{ans}");
}
51 changes: 51 additions & 0 deletions atcoder/abc375/b.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>()
};
($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}");
}
20 changes: 20 additions & 0 deletions atcoder/abc375/d.rs
Original file line number Diff line number Diff line change
@@ -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}");
}
65 changes: 65 additions & 0 deletions atcoder/abc375/e.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>()
};
($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::<usize>();
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 });
}
3 changes: 3 additions & 0 deletions atcoder/abc375/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
c
f
g

0 comments on commit ce61405

Please sign in to comment.