-
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/abc356/a.rs atcoder/abc356/b.rs atcoder/abc356/c.rs atcod…
…er/abc356/d.rs atcoder/abc356/e.rs atcoder/abc356/remain.txt
- Loading branch information
Showing
6 changed files
with
256 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,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); | ||
} |
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,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" }); | ||
} |
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,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); | ||
} |
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,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); | ||
} |
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,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); | ||
} |
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 @@ | ||
f | ||
g |