Skip to content

Commit

Permalink
Add atcoder/abc356/a.rs atcoder/abc356/b.rs atcoder/abc356/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/abc356/d.rs atcoder/abc356/e.rs atcoder/abc356/remain.txt
  • Loading branch information
koba-e964 committed Jun 2, 2024
1 parent d94cfc6 commit 5947e07
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 0 deletions.
47 changes: 47 additions & 0 deletions atcoder/abc356/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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: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, l: usize, r: usize,
}
let mut a = (1..n + 1).collect::<Vec<_>>();
a[l - 1..r].reverse();
putvec!(a);
}
45 changes: 45 additions & 0 deletions atcoder/abc356/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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, m: usize,
a: [i32; m],
x: [[i32; m]; n],
}
let mut a = a;
for i in 0..n {
for j in 0..m {
a[j] -= x[i][j];
}
}
println!("{}", if a.iter().all(|&x| x <= 0) { "Yes" } else { "No" });
}
63 changes: 63 additions & 0 deletions atcoder/abc356/c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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:tt ]) => {{
let len = read_value!($next, usize);
read_value!($next, [$t; len])
}};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: usize, m: usize, k: usize,
ar: [([usize1], char); m],
}
let mut ans = 0;
for bits in 0..1 << n {
let mut ok = true;
for &(ref a, r) in &ar {
let mut cnt = 0;
for &a in a {
if (bits & 1 << a) != 0 {
cnt += 1;
}
}
if (r == 'o') != (cnt >= k) {
ok = false;
break;
}
}
if ok {
ans += 1;
}
}
println!("{}", ans);
}
44 changes: 44 additions & 0 deletions atcoder/abc356/d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 n: i64 = get();
let m: i64 = get();
n += 1;
const MOD: i64 = 998_244_353;
let mut tot = 0;
while n > 0 {
let l = n & (n - 1);
let height = (n - l - 1).count_ones() as i64;
let x = (n - l) % MOD;
tot += ((l & m) >> height).count_ones() as i64 * x % MOD;
if height >= 1 {
tot += (m & ((1 << height) - 1)).count_ones() as i64 * (((n - l) / 2) % MOD) % MOD;
}
tot %= MOD;
n = l;
}
println!("{}", tot);
}
55 changes: 55 additions & 0 deletions atcoder/abc356/e.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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: [usize; n],
}
const W: usize = 1_000_001;
let mut f = vec![0i64; W];
for a in a {
f[a] += 1;
}
let mut acc = vec![0; W + 1];
for i in 0..W {
acc[i + 1] = acc[i] + f[i];
}
let mut tot = 0;
for i in 1..W {
tot += f[i] * (f[i] - 1) / 2;
for j in 1..(W - 1) / i + 1 {
let c = acc[((j + 1) * i).min(W)] - acc[(j * i).max(i + 1)];
tot += f[i] * c * j as i64;
}
}
println!("{}", tot);
}
2 changes: 2 additions & 0 deletions atcoder/abc356/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
f
g

0 comments on commit 5947e07

Please sign in to comment.