-
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/abc345/a.rs atcoder/abc345/b.rs atcoder/abc345/c.rs atcod…
…er/abc345/e.rs atcoder/abc345/f.rs atcoder/abc345/remain.txt
- Loading branch information
Showing
6 changed files
with
269 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,15 @@ | ||
fn getline() -> String { | ||
let mut ret = String::new(); | ||
std::io::stdin().read_line(&mut ret).ok().unwrap(); | ||
ret | ||
} | ||
|
||
fn main() { | ||
let s = getline().trim().chars().collect::<Vec<_>>(); | ||
let n = s.len(); | ||
println!("{}", if s[0] == '<' && s[n - 1] == '>' && s[1..n - 1].iter().all(|&c| c == '=') { | ||
"Yes" | ||
} else { | ||
"No" | ||
}); | ||
} |
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,33 @@ | ||
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: i64 = get(); | ||
let mut r = n % 10; | ||
if r > 0 { | ||
r -= 10; | ||
} | ||
println!("{}", (n - r) / 10); | ||
} |
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,23 @@ | ||
fn getline() -> String { | ||
let mut ret = String::new(); | ||
std::io::stdin().read_line(&mut ret).ok().unwrap(); | ||
ret | ||
} | ||
|
||
fn main() { | ||
let s = getline().trim().bytes().collect::<Vec<_>>(); | ||
let n = s.len() as i64; | ||
let mut f = [0; 26]; | ||
for s in s { | ||
f[(s - b'a') as usize] += 1i64; | ||
} | ||
let mut ans = n * (n - 1) / 2; | ||
let mut same = 0; | ||
for i in 0..26 { | ||
ans -= f[i] * (f[i] - 1) / 2; | ||
if f[i] >= 2 { | ||
same = 1; | ||
} | ||
} | ||
println!("{}", ans + same); | ||
} |
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,74 @@ | ||
// 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() { | ||
input! { | ||
n: usize, k: usize, | ||
cv: [(usize1, i64); n], | ||
} | ||
let vsum: i64 = cv.iter().map(|&(_, v)| v).sum(); | ||
const INF: i64 = 1 << 60; | ||
let mut dp = vec![[(n, INF); 2]; k + 1]; | ||
dp[0][0] = (n, 0); | ||
for (c, v) in cv { | ||
let mut ep = vec![[(n, INF); 2]; k + 1]; | ||
for i in 0..=k { | ||
let mut tmp = [(n, INF); 4]; | ||
for j in 0..2 { | ||
let (c0, v0) = dp[i][j]; | ||
if c0 != c { | ||
tmp[j] = (c, v0); | ||
} | ||
if i > 0 { | ||
let (c1, v1) = dp[i - 1][j]; | ||
tmp[2 + j] = (c1, v1 + v); | ||
} | ||
} | ||
tmp.sort_unstable_by_key(|x| x.1); | ||
ep[i][0] = tmp[0]; | ||
let mut idx = 1; | ||
while idx < 4 { | ||
if tmp[idx].0 != tmp[0].0 { | ||
break; | ||
} | ||
idx += 1; | ||
} | ||
if idx < 4 { | ||
ep[i][1] = tmp[idx]; | ||
} | ||
} | ||
dp = ep; | ||
} | ||
let ans = dp[k][0].1; | ||
println!("{}", if ans == INF { -1 } else { vsum - ans }); | ||
} |
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,122 @@ | ||
use std::cmp::*; | ||
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() { | ||
// In order to avoid potential stack overflow, spawn a new thread. | ||
let stack_size = 104_857_600; // 100 MB | ||
let thd = std::thread::Builder::new().stack_size(stack_size); | ||
thd.spawn(|| solve()).unwrap().join().unwrap(); | ||
} | ||
|
||
fn dfs(v: usize, g: &[Vec<(usize, usize)>], vis: &mut [bool], tree: &mut [Vec<(usize, usize)>], s: &mut Vec<usize>) { | ||
if vis[v] { return; } | ||
vis[v] = true; | ||
s.push(v); | ||
for &(w, eidx) in &g[v] { | ||
if vis[w] { continue; } | ||
tree[v].push((w, eidx)); | ||
tree[w].push((v, eidx)); | ||
dfs(w, g, vis, tree, s); | ||
} | ||
} | ||
|
||
fn dfs2(v: usize, pareidx: usize, g: &[Vec<(usize, usize)>], col: &mut [bool], picked: &mut Vec<usize>) -> bool { | ||
let mut ret = col[v]; | ||
for &(w, eidx) in &g[v] { | ||
if pareidx == eidx { continue; } | ||
ret ^= dfs2(w, eidx, g, col, picked); | ||
} | ||
if ret { | ||
picked.push(pareidx); | ||
} | ||
ret | ||
} | ||
|
||
fn solve() { | ||
let out = std::io::stdout(); | ||
let mut out = BufWriter::new(out.lock()); | ||
macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} | ||
macro_rules! putvec { | ||
($v:expr) => { | ||
for i in 0..$v.len() { | ||
puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "}); | ||
} | ||
} | ||
} | ||
input! { | ||
n: usize, m: usize, k: usize, | ||
ab: [(usize1, usize1); m], | ||
} | ||
let mut g = vec![vec![]; n]; | ||
for i in 0..m { | ||
let (a, b) = ab[i]; | ||
g[a].push((b, i + 1)); | ||
g[b].push((a, i + 1)); | ||
} | ||
let mut vis = vec![false; n]; | ||
let mut conn = vec![]; | ||
let mut tree = vec![vec![]; n]; | ||
for i in 0..n { | ||
if !vis[i] { | ||
let mut s = vec![]; | ||
dfs(i, &g, &mut vis, &mut tree, &mut s); | ||
conn.push((i, s)); | ||
} | ||
} | ||
let mut col = vec![false; n]; | ||
let mut k = k; | ||
if k % 2 != 0 { | ||
puts!("No\n"); | ||
return; | ||
} | ||
for v in &conn { | ||
let s = min(k, v.1.len() / 2 * 2); | ||
k -= s; | ||
for i in 0..s { | ||
col[v.1[i]] = true; | ||
} | ||
} | ||
if k > 0 { | ||
puts!("No\n"); | ||
return; | ||
} | ||
puts!("Yes\n"); | ||
let mut es = vec![]; | ||
for (i, _) in conn { | ||
dfs2(i, n, &tree, &mut col, &mut es); | ||
} | ||
puts!("{}\n", es.len()); | ||
putvec!(es); | ||
} |
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,2 @@ | ||
d | ||
g |