Skip to content

Commit

Permalink
Add atcoder/abc344/b.rs atcoder/abc344/c.rs atcoder/abc344/d.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc344/f.rs
  • Loading branch information
koba-e964 committed Apr 30, 2024
1 parent eae05f4 commit b9d58c0
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 4 deletions.
20 changes: 20 additions & 0 deletions atcoder/abc344/b.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 a = vec![];
loop {
let s = getline();
a.push(s.clone());
if s == "0\n" {
break;
}
}
a.reverse();
for a in a {
print!("{}", a);
}
}
59 changes: 59 additions & 0 deletions atcoder/abc344/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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 ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($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,
a: [i64; n],
m: usize,
b: [i64; m],
l: usize,
c: [i64; l],
q: usize,
x: [i64; q],
}
let mut sum = vec![];
for a in &a {
for &b in &b {
for &c in &c {
sum.push(a + b + c);
}
}
}
sum.sort_unstable(); sum.dedup();
for &x in &x {
puts!("{}\n", if sum.binary_search(&x).is_ok() { "Yes" } else { "No" });
}
}
62 changes: 62 additions & 0 deletions atcoder/abc344/d.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, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, [ $t:tt ]) => {{
let len = read_value!($next, usize);
read_value!($next, [$t; len])
}};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
const INF: i64 = 1 << 58;
input! {
t: chars,
n: usize,
s: [[chars]; n],
}
let m = t.len();
let mut dp = vec![INF; m + 1];
dp[0] = 0;
for s in s {
let mut ep = dp.clone();
for s in s {
let l = s.len();
for i in 0..(m + 1).max(l) - l {
if t[i..i + l] == s {
ep[i + l] = ep[i + l].min(dp[i] + 1);
}
}
}
dp = ep;
}
println!("{}", if dp[m] >= INF { -1 } else { dp[m] })
}
90 changes: 90 additions & 0 deletions atcoder/abc344/f.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use std::cmp::*;
// 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: usize,
p: [[i64; n]; n],
r: [[i64; n - 1]; n],
d: [[i64; n]; n - 1],
}
let mut coo = vec![];
for i in 0..n {
for j in 0..n {
coo.push(p[i][j]);
}
}
coo.push(0);
coo.sort(); coo.dedup();
let m = coo.len();
let mut mapped = vec![vec![0; n]; n];
for i in 0..n {
for j in 0..n {
mapped[i][j] = coo.binary_search(&p[i][j]).unwrap();
}
}
let mut dist = vec![(INF, Reverse(INF)); n * n * m];
const INF: i64 = 1 << 58;
dist[0] = (0, Reverse(0));
for x in 0..n {
for y in 0..n {
for k in 0..m {
let idx = (x * n + y) * m + k;
let (cost, Reverse(money)) = dist[idx];
let nk = k.max(mapped[x][y]);
let ma = coo[nk];
let nidx = (x * n + y) * m + nk;
if x + 1 < n {
let q = if money >= d[x][y] {
0
} else {
(d[x][y] - money + ma - 1) / ma
};
dist[nidx + n * m] = dist[nidx + n * m].min((cost + q + 1, Reverse(money + q * ma - d[x][y])));
}
if y + 1 < n {
let q = if money >= r[x][y] {
0
} else {
(r[x][y] - money + ma - 1) / ma
};
dist[nidx + m] = dist[nidx + m].min((cost + q + 1, Reverse(money + q * ma - r[x][y])));
}
}
}
}
let mut mi = INF;
for i in 0..m {
mi = mi.min(dist[(n * n - 1) * m + i].0);
}
println!("{}", mi);
}
4 changes: 0 additions & 4 deletions atcoder/abc344/remain.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
b
c
d
e
f
g

0 comments on commit b9d58c0

Please sign in to comment.