From 88a9abeaeb1a3288a81e0084b448fa44e64bf01f Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:56:09 +0900 Subject: [PATCH] Add atcoder/abc383/a.rs atcoder/abc383/b.rs atcoder/abc383/c.rs atcoder/abc383/d.rs atcoder/abc383/remain.txt --- atcoder/abc383/a.rs | 37 +++++++++++++++++++++ atcoder/abc383/b.rs | 61 +++++++++++++++++++++++++++++++++++ atcoder/abc383/c.rs | 67 +++++++++++++++++++++++++++++++++++++++ atcoder/abc383/d.rs | 63 ++++++++++++++++++++++++++++++++++++ atcoder/abc383/remain.txt | 3 ++ 5 files changed, 231 insertions(+) create mode 100644 atcoder/abc383/a.rs create mode 100644 atcoder/abc383/b.rs create mode 100644 atcoder/abc383/c.rs create mode 100644 atcoder/abc383/d.rs create mode 100644 atcoder/abc383/remain.txt diff --git a/atcoder/abc383/a.rs b/atcoder/abc383/a.rs new file mode 100644 index 00000000..c94c0086 --- /dev/null +++ b/atcoder/abc383/a.rs @@ -0,0 +1,37 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let n: usize = get(); + let mut cur = 0; + let mut s = 0; + for _ in 0..n { + let t: i64 = get(); + let v: i64 = get(); + s = 0.max(s - t + cur) + v; + cur = t; + } + println!("{}", s); +} diff --git a/atcoder/abc383/b.rs b/atcoder/abc383/b.rs new file mode 100644 index 00000000..389c7c37 --- /dev/null +++ b/atcoder/abc383/b.rs @@ -0,0 +1,61 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let h: usize = get(); + let w: usize = get(); + let d: i32 = get(); + let mut s = vec![]; + for _ in 0..h { + s.push(get_word().chars().collect::>()); + } + let mut ans = 0; + for i in 0..h { + for j in 0..w { + if s[i][j] == '#' { + continue; + } + for a in 0..h { + for b in 0..w { + if s[a][b] == '#' { + continue; + } + let mut cnt = 0; + for k in 0..h { + (0..w).filter(|&l| s[k][l] == '.').for_each(|l| { + let d1 = (i as i32 - k as i32).abs() + (j as i32 - l as i32).abs(); + let d2 = (a as i32 - k as i32).abs() + (b as i32 - l as i32).abs(); + if d1.min(d2) <= d { + cnt += 1; + } + }); + } + ans = ans.max(cnt); + } + } + } + } + println!("{ans}"); +} diff --git a/atcoder/abc383/c.rs b/atcoder/abc383/c.rs new file mode 100644 index 00000000..592aa236 --- /dev/null +++ b/atcoder/abc383/c.rs @@ -0,0 +1,67 @@ +use std::collections::*; +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let h: usize = get(); + let w: usize = get(); + let targ_d: i32 = get(); + let mut s = vec![]; + for _ in 0..h { + s.push(get_word().chars().collect::>()); + } + const INF: i32 = 1 << 30; + let mut dist = vec![vec![INF; w]; h]; + let mut que = VecDeque::new(); + for i in 0..h { + for j in 0..w { + if s[i][j] == 'H' { + que.push_back((0, i, j)); + } + } + } + let mut ans = 0; + while let Some((d, x, y)) = que.pop_front() { + if dist[x][y] <= d { + continue; + } + dist[x][y] = d; + if d <= targ_d { + ans += 1; + } + for &(dx, dy) in &[(1, 0), (-1, 0), (0, 1), (0, -1)] { + let nx = x.wrapping_add(dx as usize); + let ny = y.wrapping_add(dy as usize); + if nx >= h || ny >= w { + continue; + } + if s[nx][ny] == '#' { + continue; + } + que.push_back((d + 1, nx, ny)); + } + } + println!("{ans}"); +} diff --git a/atcoder/abc383/d.rs b/atcoder/abc383/d.rs new file mode 100644 index 00000000..a5e69c69 --- /dev/null +++ b/atcoder/abc383/d.rs @@ -0,0 +1,63 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + const W: usize = 2_000_001; + let mut is_prime = vec![true; W]; + is_prime[0] = false; + is_prime[1] = false; + for i in 2..W { + if is_prime[i] { + let mut j = i * 2; + while j < W { + is_prime[j] = false; + j += i; + } + } + } + let n: i64 = get(); + let mut ans = 0; + for p in 2..W { + if !is_prime[p] { + continue; + } + let p8 = p as i64 * p as i64; + let p8 = p8.saturating_mul(p8); + let p8 = p8.saturating_mul(p8); + if p8 <= n { + ans += 1; + } + for q in p + 1..(W - 1) / p + 1 { + if !is_prime[q] { + continue; + } + let pq = p as i64 * q as i64; + if pq * pq <= n { + ans += 1; + } + } + } + println!("{ans}"); +} diff --git a/atcoder/abc383/remain.txt b/atcoder/abc383/remain.txt new file mode 100644 index 00000000..20708814 --- /dev/null +++ b/atcoder/abc383/remain.txt @@ -0,0 +1,3 @@ +e +f +g