-
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/abc354/c.rs atcoder/abc354/d.rs atcoder/abc354/e.rs atcod…
…er/abc354/f.rs yukicoder/2718.rs
- Loading branch information
Showing
6 changed files
with
348 additions
and
4 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,69 @@ | ||
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, $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, | ||
ac: [(i64, i64); n], | ||
} | ||
let mut aci = (0..n).map(|i| (ac[i].0, ac[i].1, i)).collect::<Vec<_>>(); | ||
aci.sort(); | ||
let mut st: Vec<(i64, i64, usize)> = vec![]; | ||
for v in aci { | ||
while let Some(&top) = st.last() { | ||
if top.1 >= v.1 { | ||
st.pop(); | ||
} else { | ||
break; | ||
} | ||
} | ||
st.push(v); | ||
} | ||
let mut ans = vec![]; | ||
for (_, _, i) in st { | ||
ans.push(i + 1); | ||
} | ||
ans.sort(); | ||
puts!("{}\n", ans.len()); | ||
putvec!(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 calc(a: i64, b: i64) -> i64 { | ||
let ra = (a % 4 + 4) % 4; | ||
let rb = (b % 2 + 2) % 2; | ||
let qa = (a - ra) / 4; | ||
let qb = (b - rb) / 2; | ||
let mut ans = 8 * qa * qb; | ||
ans += qb * [0, 3, 6, 7][ra as usize]; | ||
ans += 4 * qa * rb; | ||
ans += [[0; 4], [0, 2, 3, 3]][rb as usize][ra as usize]; | ||
ans | ||
} | ||
|
||
fn main() { | ||
let a: i64 = get(); | ||
let b: i64 = get(); | ||
let c: i64 = get(); | ||
let d: i64 = get(); | ||
println!("{}", calc(c, d) - calc(a, d) - calc(c, b) + calc(a, b)); | ||
} |
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,57 @@ | ||
// 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")); | ||
} | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
ab: [(i32, u32); n], | ||
} | ||
let mut dp = vec![false; 1 << n]; | ||
for bits in 3..1 << n { | ||
let mut win = false; | ||
for i in 0..n { | ||
for j in i + 1..n { | ||
if (bits & 1 << i) != 0 && (bits & 1 << j) != 0 { | ||
let (a, b) = ab[i]; | ||
let (c, d) = ab[j]; | ||
if a == c || b == d { | ||
if !dp[bits ^ 1 << i ^ 1 << j] { | ||
win = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
dp[bits] = win; | ||
} | ||
println!("{}", if dp[(1 << n) - 1] { "Takahashi" } else { "Aoki" }); | ||
} |
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,95 @@ | ||
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, [ $t:tt ]) => {{ | ||
let len = read_value!($next, usize); | ||
read_value!($next, [$t; len]) | ||
}}; | ||
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); | ||
} | ||
|
||
fn lis(a: &[usize]) -> Vec<usize> { | ||
let n = a.len(); | ||
let mut mi = vec![!0; n + 1]; | ||
mi[0] = 0; | ||
let mut dp = vec![0; n]; | ||
for i in 0..n { | ||
let mut pass = 0; | ||
let mut fail = n; | ||
while fail - pass > 1 { | ||
let mid = (pass + fail) / 2; | ||
if mi[mid] < a[i] { | ||
pass = mid; | ||
} else { | ||
fail = mid; | ||
} | ||
} | ||
dp[i] = pass + 1; | ||
mi[dp[i]] = mi[dp[i]].min(a[i]); | ||
} | ||
dp | ||
} | ||
|
||
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! { | ||
t: usize, | ||
a: [[usize]; t], | ||
} | ||
for a in a { | ||
let n = a.len(); | ||
let mut b = a.clone(); | ||
b.reverse(); | ||
for i in 0..n { | ||
b[i] = !b[i]; | ||
} | ||
let al = lis(&a); | ||
let mut bl = lis(&b); | ||
bl.reverse(); | ||
let ma = al.iter().max().copied().unwrap(); | ||
let mut ans = vec![]; | ||
for i in 0..n { | ||
if al[i] + bl[i] - 1 == ma { | ||
ans.push(i + 1); | ||
} | ||
} | ||
puts!("{}\n", ans.len()); | ||
putvec!(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 |
---|---|---|
@@ -1,5 +1 @@ | ||
c | ||
d | ||
e | ||
f | ||
g |
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,83 @@ | ||
// 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")); | ||
} | ||
|
||
// https://yukicoder.me/problems/no/2718 (3.5) | ||
// solved with hints | ||
// A_i が同じ楽器の調和度は簡単に計算できるので、A_i は相異なるとして良い。 | ||
// A_i の昇順に以下をやる。 | ||
// (i) 各 x について、max(dp[A_i * x], floor(B_i/x)) を得られた調和度の max に反映する。 | ||
// (ii) 各 x について、dp[A_i * x].chmax(floor(B_i/x)) をやる。 | ||
// -> 解説を見た。先述の方法だと lcm(A_i, A_j) >= 2 * 10^5 であるペアをうまく拾えない。gcd を見る必要がある。 | ||
// g | gcd(A_i, A_j) なるペアおよび g に対して min(floor(gB_i/A_j), floor(gB_j/A_i)) をとると、g を動かした時の最大値が i と j の調和度である。 | ||
// g を固定した時のこの値の最大値を求めるために、min の左側の値を全部試す必要がある。 | ||
// B_iA_i でソートしたあと、左側を (A_i, B_i), 右側を (A_j, B_j) として 2 個の値を組み合わせると、 | ||
// floor(gB_i/A_j) の方が小さい。したがって、各 j に対して max_{j < i}(B_i) をあらかじめ計算しておけば良い。 | ||
fn main() { | ||
input! { | ||
n: usize, | ||
ab: [(usize, i64); n], | ||
} | ||
const W: usize = 200_100; | ||
let mut ans = 0; | ||
let mut occ = vec![vec![]; W]; | ||
for (a, b) in ab { | ||
occ[a].push(b); | ||
} | ||
for i in 1..W { | ||
occ[i].sort(); | ||
occ[i].reverse(); | ||
if occ[i].len() >= 2 { | ||
ans = ans.max(occ[i][1]); | ||
} | ||
} | ||
for g in 1..W { | ||
let mut val = vec![]; | ||
for j in 1..(W - 1) / g + 1 { | ||
if occ[j * g].len() >= 1 { | ||
val.push((j, occ[j * g][0])); | ||
} | ||
} | ||
val.sort_by(|x, y| (x.1 * x.0 as i64).cmp(&(y.0 as i64 * y.1))); | ||
if val.len() >= 2 { | ||
let mut ma = vec![0; val.len()]; | ||
ma[0] = val[0].1; | ||
for i in 1..val.len() { | ||
ma[i] = ma[i - 1].max(val[i].1); | ||
} | ||
for i in 1..val.len() { | ||
let (a, _) = val[i]; | ||
ans = ans.max(ma[i - 1] / a as i64); | ||
} | ||
} | ||
} | ||
println!("{}", ans); | ||
} |