Skip to content

Commit

Permalink
Add atcoder/abc379/a.rs atcoder/abc379/b.rs atcoder/abc379/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc379/d.rs atcoder/abc379/e.rs atcoder/abc379/f.rs atcoder/abc379/g.rs
  • Loading branch information
koba-e964 committed Nov 9, 2024
1 parent b1b4435 commit 324d28f
Show file tree
Hide file tree
Showing 7 changed files with 478 additions and 0 deletions.
15 changes: 15 additions & 0 deletions atcoder/abc379/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn main() {
let mut x: i64 = getline().trim().parse().ok().unwrap();
for _ in 0..2 {
x *= 10;
x += x / 1000;
x %= 1000;
println!("{x}");
}
}
49 changes: 49 additions & 0 deletions atcoder/abc379/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: usize, k: usize,
s: chars,
}
let mut cur = 0;
let mut ans = 0;
for c in s {
if c == 'O' {
cur += 1;
} else {
ans += cur / k;
cur = 0;
}
}
ans += cur / k;
println!("{ans}");
}
62 changes: 62 additions & 0 deletions atcoder/abc379/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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::<Vec<_>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: i64, m: usize,
x: [i64; m],
a: [i64; m],
}
let asum = a.iter().sum::<i64>();
if asum != n {
println!("-1");
return;
}
let mut xa = vec![];
for i in 0..m {
xa.push((x[i], a[i]));
}
xa.sort();
let mut tot = 0;
for i in (0..m).rev() {
let (x, a) = xa[i];
if tot + a + x > n + 1 {
println!("-1");
return;
}
tot += a;
}
let mut ans = n * (n + 1) / 2;
for (x, a) in xa {
ans -= x * a;
}
println!("{ans}");
}
47 changes: 47 additions & 0 deletions atcoder/abc379/d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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 q: i32 = get();
let mut s = BTreeSet::new();
let mut bias = 0;
for idx in 0..q {
let ty: i32 = get();
if ty == 1 {
s.insert((-bias, idx));
} else if ty == 2 {
let t: i64 = get();
bias += t;
} else {
let h: i64 = get();
let tmp = s.range((h - bias, 0)..).cloned().collect::<Vec<_>>();
println!("{}", tmp.len());
for t in tmp {
s.remove(&t);
}
}
}
}
45 changes: 45 additions & 0 deletions atcoder/abc379/e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
fn getline() -> String {
let mut ret = String::new();
std::io::stdin().read_line(&mut ret).ok().unwrap();
ret
}

fn quo(a: i64, b: i64) -> i64 {
assert!(b > 0);
let mut r = a % b;
if r < 0 {
r += b;
}
(a - r) / b
}

fn main() {
getline();
let s = getline().trim().bytes().collect::<Vec<_>>();
let n = s.len();
let mut dig = vec![0; n + 1];
for i in 0..n {
let d = (s[i] - b'0') as i64 * (i as i64 + 1);
dig[i] += d;
dig[n] -= d;
}
for i in (0..n).rev() {
let q = quo(dig[i + 1], 10);
dig[i] += q;
dig[i + 1] -= q * 10;
}
// /= 9
let mut carry = 0;
for i in 0..n + 1 {
let q = quo(dig[i] + carry * 10, 9);
carry = (dig[i] + carry * 10) - q * 9;
dig[i] = q;
}
while dig[0] == 0 {
dig.remove(0);
}
for d in dig {
print!("{d}");
}
println!();
}
70 changes: 70 additions & 0 deletions atcoder/abc379/f.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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::<Vec<_>>()
};
($next:expr, usize1) => (read_value!($next, usize) - 1);
($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)*););}
input! {
n: usize, q: usize,
h: [i64; n],
lr: [(usize1, usize1); q],
}
let mut qs = vec![vec![]; n];
for i in 0..q {
let (l, r) = lr[i];
qs[l].push((r, i));
}
let mut st: Vec<usize> = vec![];
let mut ans = vec![0; q];
for i in (0..n).rev() {
for &(r, idx) in qs[i].iter() {
let from = match st.binary_search_by(|x| r.cmp(x)) {
Ok(x) => x,
Err(x) => x,
};
ans[idx] = from;
}
while let Some(v) = st.pop() {
if h[i] < h[v] {
st.push(v);
break;
}
}
st.push(i);
}
for a in ans {
puts!("{a}\n");
}
}
Loading

0 comments on commit 324d28f

Please sign in to comment.