Skip to content

Commit

Permalink
Add atcoder/abc383/a.rs atcoder/abc383/b.rs atcoder/abc383/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc383/d.rs atcoder/abc383/remain.txt
  • Loading branch information
koba-e964 committed Dec 7, 2024
1 parent c63378e commit 88a9abe
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 0 deletions.
37 changes: 37 additions & 0 deletions atcoder/abc383/a.rs
Original file line number Diff line number Diff line change
@@ -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<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 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);
}
61 changes: 61 additions & 0 deletions atcoder/abc383/b.rs
Original file line number Diff line number Diff line change
@@ -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<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 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::<Vec<_>>());
}
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}");
}
67 changes: 67 additions & 0 deletions atcoder/abc383/c.rs
Original file line number Diff line number Diff line change
@@ -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<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 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::<Vec<_>>());
}
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}");
}
63 changes: 63 additions & 0 deletions atcoder/abc383/d.rs
Original file line number Diff line number Diff line change
@@ -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<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 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}");
}
3 changes: 3 additions & 0 deletions atcoder/abc383/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
e
f
g

0 comments on commit 88a9abe

Please sign in to comment.