-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add atcoder/abc322/a.rs atcoder/abc322/b.rs atcoder/abc322/c.rs atcod…
…er/abc322/e.rs atcoder/abc322/f.rs atcoder/abc322/remain.txt
- Loading branch information
Showing
7 changed files
with
445 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
Oops, something went wrong.