Skip to content

Commit

Permalink
Add atcoder/abc322/a.rs atcoder/abc322/b.rs atcoder/abc322/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc322/e.rs atcoder/abc322/f.rs atcoder/abc322/remain.txt
  • Loading branch information
koba-e964 committed Apr 22, 2024
1 parent e79db46 commit 59fd46d
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 0 deletions.
17 changes: 17 additions & 0 deletions atcoder/abc322/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();
for i in 0..s.len() - 2 {
if &s[i..i + 3] == "ABC" {
println!("{}", i + 1);
return;
}
}
println!("-1");
}
19 changes: 19 additions & 0 deletions atcoder/abc322/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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().to_string();
let t = getline().trim().to_string();
let mut a = 0;
if t.strip_prefix(&s).is_none() {
a += 2;
}
if t.strip_suffix(&s).is_none() {
a += 1;
}
println!("{}", a);
}
51 changes: 51 additions & 0 deletions atcoder/abc322/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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, m: usize,
a: [usize; m],
}
let mut v = vec![n + 1; n + 1];
for a in a {
v[a] = a;
}
for i in (0..n).rev() {
v[i] = std::cmp::min(v[i], v[i + 1]);
}
for i in 1..n + 1 {
puts!("{}\n", v[i] - i);
}
}
67 changes: 67 additions & 0 deletions atcoder/abc322/e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use std::collections::*;
// 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: i64 = 1 << 58;

fn rec(ca: &[(i64, Vec<usize>)], i: usize, v: Vec<usize>, p: usize, memo: &mut HashMap<(usize, Vec<usize>), i64>) -> i64 {
if i == ca.len() {
for &v in &v {
if v < p {
return INF;
}
}
return 0;
}
if let Some(&mi) = memo.get(&(i, v.clone())) {
return mi;
}
let mut mi = rec(ca, i + 1, v.clone(), p, memo);
let (ci, ref ai) = ca[i];
let mut nv = v.clone();
for j in 0..v.len() {
nv[j] = std::cmp::min(v[j] + ai[j], p);
}
mi = std::cmp::min(mi, rec(ca, i + 1, nv, p, memo) + ci);
memo.insert((i, v), mi);
mi
}

fn main() {
input! {
n: usize, k: usize, p: usize,
ca: [(i64, [usize; k]); n],
}
let mut memo = HashMap::new();
let ans = rec(&ca, 0, vec![0; k], p, &mut memo);
println!("{}", if ans >= INF { -1 } else { ans });
}
Loading

0 comments on commit 59fd46d

Please sign in to comment.