Skip to content

Commit

Permalink
Add atcoder/abc347/a.rs atcoder/abc347/b.rs atcoder/abc347/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc347/d.rs atcoder/abc347/e.rs atcoder/abc347/remain.txt yukicoder/2613.rs
  • Loading branch information
koba-e964 committed Apr 26, 2024
1 parent 5db4ee7 commit 86f715c
Show file tree
Hide file tree
Showing 7 changed files with 577 additions and 0 deletions.
55 changes: 55 additions & 0 deletions atcoder/abc347/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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)*););}
macro_rules! putvec {
($v:expr) => {
for i in 0..$v.len() {
puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
}
}
}
input! {
n: i32, k: i32,
a: [i32; n],
}
let mut v = vec![];
for a in a {
if a % k == 0 {
v.push(a / k);
}
}
putvec!(v);
}
18 changes: 18 additions & 0 deletions atcoder/abc347/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::collections::*;

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 mut hs = HashSet::new();
for i in 0..s.len() + 1 {
for j in 0..i {
hs.insert(s[j..i].to_vec());
}
}
println!("{}", hs.len());
}
47 changes: 47 additions & 0 deletions atcoder/abc347/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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, a: i64, b: i64,
d: [i64; n],
}
let mut r = vec![];
for d in d {
r.push(d % (a + b));
}
r.sort();
let mut ok = r[n - 1] - r[0] <= a - 1;
for i in 1..n {
ok |= r[i] - r[i - 1] > b;
}
println!("{}", if ok { "Yes" } else { "No" })
}
55 changes: 55 additions & 0 deletions atcoder/abc347/d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 mut a: u32 = get();
let b: u32 = get();
let cc: i64 = get();
let c = cc.count_ones();
let ng = |a, b, c| a + b < c || 120 - a - b < c;
if ng(a, b, c) || ng(a, c, b) || ng(c, b, a) || (a + b + c) % 2 != 0 {
println!("-1");
return;
}
let mut aa = 0i64;
let mut k = (a + b - c) / 2;
for i in 0..60 {
if (cc >> i) & 1 == 1 {
if a > k {
aa |= 1 << i;
a -= 1;
}
} else {
if k > 0 {
aa |= 1 << i;
a -= 1;
k -= 1;
}
}
}
assert_eq!(a, 0);
assert_eq!(k, 0);
println!("{} {}", aa, cc ^ aa);
}
73 changes: 73 additions & 0 deletions atcoder/abc347/e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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)*););}
macro_rules! putvec {
($v:expr) => {
for i in 0..$v.len() {
puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
}
}
}
input! {
n: usize, q: usize,
x: [usize; q],
}
let mut a = vec![0; n];
let mut on = vec![false; n];
let mut card = 0i64;
let mut acc = vec![0; q + 1];
let mut occ = vec![vec![]; n];
for i in 0..q {
let x = x[i] - 1;
occ[x].push(i);
if on[x] {
on[x] = false;
card -= 1;
} else {
on[x] = true;
card += 1;
}
acc[i + 1] = acc[i] + card;
}
for i in 0..n {
for j in 0..(occ[i].len() + 1) / 2 {
let lo = occ[i][j * 2];
let hi = if 2 * j + 1 >= occ[i].len() { q } else { occ[i][2 * j + 1] };
a[i] += acc[hi] - acc[lo];
}
}
putvec!(a);
}
2 changes: 2 additions & 0 deletions atcoder/abc347/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
f
g
Loading

0 comments on commit 86f715c

Please sign in to comment.