From b1b44351dde748c7184970bf94dd6d1cbe2b2edf Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:57:52 +0900 Subject: [PATCH] Add atcoder/abc360/a.rs atcoder/abc360/b.rs atcoder/abc360/c.rs atcoder/abc360/d.rs atcoder/abc360/e.rs atcoder/abc360/g.rs atcoder/abc360/remain.txt atcoder/abc362/a.rs atcoder/abc362/b.rs atcoder/abc364/a.rs atcoder/abc364/remain.txt atcoder/abc366/a.rs atcoder/abc366/remain.txt atcoder/abc367/a.rs atcoder/abc367/b.rs atcoder/abc367/remain.txt atcoder/abc370/a.rs atcoder/abc370/b.rs atcoder/abc370/remain.txt atcoder/abc371/a.rs atcoder/abc371/b.rs atcoder/abc371/remain.txt atcoder/abc373/a.rs atcoder/abc373/b.rs atcoder/abc373/remain.txt --- atcoder/abc360/a.rs | 14 ++++ atcoder/abc360/b.rs | 42 +++++++++++ atcoder/abc360/c.rs | 50 ++++++++++++ atcoder/abc360/d.rs | 95 +++++++++++++++++++++++ atcoder/abc360/e.rs | 155 ++++++++++++++++++++++++++++++++++++++ atcoder/abc360/g.rs | 151 +++++++++++++++++++++++++++++++++++++ atcoder/abc360/remain.txt | 1 + atcoder/abc362/a.rs | 43 +++++++++++ atcoder/abc362/b.rs | 46 +++++++++++ atcoder/abc362/remain.txt | 2 - atcoder/abc364/a.rs | 37 +++++++++ atcoder/abc364/remain.txt | 6 ++ atcoder/abc366/a.rs | 31 ++++++++ atcoder/abc366/remain.txt | 6 ++ atcoder/abc367/a.rs | 33 ++++++++ atcoder/abc367/b.rs | 20 +++++ atcoder/abc367/remain.txt | 5 ++ atcoder/abc370/a.rs | 34 +++++++++ atcoder/abc370/b.rs | 40 ++++++++++ atcoder/abc370/remain.txt | 6 ++ atcoder/abc371/a.rs | 18 +++++ atcoder/abc371/b.rs | 53 +++++++++++++ atcoder/abc371/remain.txt | 5 ++ atcoder/abc373/a.rs | 16 ++++ atcoder/abc373/b.rs | 19 +++++ atcoder/abc373/remain.txt | 5 ++ 26 files changed, 931 insertions(+), 2 deletions(-) create mode 100644 atcoder/abc360/a.rs create mode 100644 atcoder/abc360/b.rs create mode 100644 atcoder/abc360/c.rs create mode 100644 atcoder/abc360/d.rs create mode 100644 atcoder/abc360/e.rs create mode 100644 atcoder/abc360/g.rs create mode 100644 atcoder/abc360/remain.txt create mode 100644 atcoder/abc362/a.rs create mode 100644 atcoder/abc362/b.rs create mode 100644 atcoder/abc364/a.rs create mode 100644 atcoder/abc364/remain.txt create mode 100644 atcoder/abc366/a.rs create mode 100644 atcoder/abc366/remain.txt create mode 100644 atcoder/abc367/a.rs create mode 100644 atcoder/abc367/b.rs create mode 100644 atcoder/abc367/remain.txt create mode 100644 atcoder/abc370/a.rs create mode 100644 atcoder/abc370/b.rs create mode 100644 atcoder/abc370/remain.txt create mode 100644 atcoder/abc371/a.rs create mode 100644 atcoder/abc371/b.rs create mode 100644 atcoder/abc371/remain.txt create mode 100644 atcoder/abc373/a.rs create mode 100644 atcoder/abc373/b.rs create mode 100644 atcoder/abc373/remain.txt diff --git a/atcoder/abc360/a.rs b/atcoder/abc360/a.rs new file mode 100644 index 00000000..c9732881 --- /dev/null +++ b/atcoder/abc360/a.rs @@ -0,0 +1,14 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + let s = getline(); + if s.contains("RM") || s.contains("RSM") { + println!("Yes"); + } else { + println!("No"); + } +} diff --git a/atcoder/abc360/b.rs b/atcoder/abc360/b.rs new file mode 100644 index 00000000..0683b474 --- /dev/null +++ b/atcoder/abc360/b.rs @@ -0,0 +1,42 @@ +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 = 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 main() { + let s = get_word().chars().collect::>(); + let t = get_word().chars().collect::>(); + for c in 1..s.len() { + for w in c..s.len() { + let mut v = vec![]; + for chk in s.chunks(w) { + if chk.len() >= c { + v.push(chk[c - 1]); + } + } + if t == v { + println!("Yes"); + return; + } + } + } + println!("No"); +} diff --git a/atcoder/abc360/c.rs b/atcoder/abc360/c.rs new file mode 100644 index 00000000..706273d9 --- /dev/null +++ b/atcoder/abc360/c.rs @@ -0,0 +1,50 @@ +// 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::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + input! { + n: usize, + a: [usize; n], + w: [i64; n], + } + let mut buc = vec![vec![]; n]; + for i in 0..n { + buc[a[i] - 1].push(w[i]); + } + let mut ans = 0; + for i in 0..n { + if let Some(&ma) = buc[i].iter().max() { + let sum: i64 = buc[i].iter().sum(); + ans += sum - ma; + } + } + println!("{}", ans); +} diff --git a/atcoder/abc360/d.rs b/atcoder/abc360/d.rs new file mode 100644 index 00000000..829431ea --- /dev/null +++ b/atcoder/abc360/d.rs @@ -0,0 +1,95 @@ +// 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::>() + }; + ($next:expr, chars) => { + read_value!($next, String).chars().collect::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +trait Bisect { + fn lower_bound(&self, val: &T) -> usize; + fn upper_bound(&self, val: &T) -> usize; +} + +impl Bisect for [T] { + fn lower_bound(&self, val: &T) -> usize { + let mut pass = self.len() + 1; + let mut fail = 0; + while pass - fail > 1 { + let mid = (pass + fail) / 2; + if &self[mid - 1] >= val { + pass = mid; + } else { + fail = mid; + } + } + pass - 1 + } + fn upper_bound(&self, val: &T) -> usize { + let mut pass = self.len() + 1; + let mut fail = 0; + while pass - fail > 1 { + let mid = (pass + fail) / 2; + if &self[mid - 1] > val { + pass = mid; + } else { + fail = mid; + } + } + pass - 1 + } +} + +fn main() { + input! { + n: usize, t: i64, + s: chars, + x: [i64; n], + } + let mut rgt = vec![]; + let mut lft = vec![]; + for i in 0..n { + if s[i] == '0' { + lft.push(x[i]); + } else { + rgt.push(x[i]); + } + } + lft.sort(); + rgt.sort(); + let mut ans = 0; + for r in rgt { + let lo = lft.lower_bound(&r); + let hi = lft.upper_bound(&(r + 2 * t)); + if lo < hi { + ans += (hi - lo) as i64; + } + } + println!("{}", ans); +} diff --git a/atcoder/abc360/e.rs b/atcoder/abc360/e.rs new file mode 100644 index 00000000..7dc45a7a --- /dev/null +++ b/atcoder/abc360/e.rs @@ -0,0 +1,155 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +/// Verified by https://atcoder.jp/contests/abc198/submissions/21774342 +mod mod_int { + use std::ops::*; + pub trait Mod: Copy { fn m() -> i64; } + #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] + pub struct ModInt { pub x: i64, phantom: ::std::marker::PhantomData } + impl ModInt { + // x >= 0 + pub fn new(x: i64) -> Self { ModInt::new_internal(x % M::m()) } + fn new_internal(x: i64) -> Self { + ModInt { x: x, phantom: ::std::marker::PhantomData } + } + pub fn pow(self, mut e: i64) -> Self { + debug_assert!(e >= 0); + let mut sum = ModInt::new_internal(1); + let mut cur = self; + while e > 0 { + if e % 2 != 0 { sum *= cur; } + cur *= cur; + e /= 2; + } + sum + } + #[allow(dead_code)] + pub fn inv(self) -> Self { self.pow(M::m() - 2) } + } + impl Default for ModInt { + fn default() -> Self { Self::new_internal(0) } + } + impl>> Add for ModInt { + type Output = Self; + fn add(self, other: T) -> Self { + let other = other.into(); + let mut sum = self.x + other.x; + if sum >= M::m() { sum -= M::m(); } + ModInt::new_internal(sum) + } + } + impl>> Sub for ModInt { + type Output = Self; + fn sub(self, other: T) -> Self { + let other = other.into(); + let mut sum = self.x - other.x; + if sum < 0 { sum += M::m(); } + ModInt::new_internal(sum) + } + } + impl>> Mul for ModInt { + type Output = Self; + fn mul(self, other: T) -> Self { ModInt::new(self.x * other.into().x % M::m()) } + } + impl>> AddAssign for ModInt { + fn add_assign(&mut self, other: T) { *self = *self + other; } + } + impl>> SubAssign for ModInt { + fn sub_assign(&mut self, other: T) { *self = *self - other; } + } + impl>> MulAssign for ModInt { + fn mul_assign(&mut self, other: T) { *self = *self * other; } + } + impl Neg for ModInt { + type Output = Self; + fn neg(self) -> Self { ModInt::new(0) - self } + } + impl ::std::fmt::Display for ModInt { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + self.x.fmt(f) + } + } + impl ::std::fmt::Debug for ModInt { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + let (mut a, mut b, _) = red(self.x, M::m()); + if b < 0 { + a = -a; + b = -b; + } + write!(f, "{}/{}", a, b) + } + } + impl From for ModInt { + fn from(x: i64) -> Self { Self::new(x) } + } + // Finds the simplest fraction x/y congruent to r mod p. + // The return value (x, y, z) satisfies x = y * r + z * p. + fn red(r: i64, p: i64) -> (i64, i64, i64) { + if r.abs() <= 10000 { + return (r, 1, 0); + } + let mut nxt_r = p % r; + let mut q = p / r; + if 2 * nxt_r >= r { + nxt_r -= r; + q += 1; + } + if 2 * nxt_r <= -r { + nxt_r += r; + q -= 1; + } + let (x, z, y) = red(nxt_r, r); + (x, y - q * z, z) + } +} // mod mod_int + +macro_rules! define_mod { + ($struct_name: ident, $modulo: expr) => { + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] + pub struct $struct_name {} + impl mod_int::Mod for $struct_name { fn m() -> i64 { $modulo } } + } +} +const MOD: i64 = 998_244_353; +define_mod!(P, MOD); +type MInt = mod_int::ModInt

; + +fn main() { + let n: i64 = get(); + let k: i32 = get(); + let mut dp = [MInt::new(0); 2]; + dp[0] += 1; + let invn = MInt::new(n).inv(); + for _ in 0..k { + let mut ep = [MInt::new(0); 2]; + ep[0] += dp[0] * invn * invn * (n * n - 2 * n + 2); + ep[0] += dp[1] * invn * invn * (n - 1) * 2; + ep[1] += dp[0] * invn * invn * 2; + ep[1] += dp[1] * invn * invn * (n * n - 2); + dp = ep; + } + println!("{}", dp[0] + dp[1] * (n * n + n - 2) * MInt::new(2).inv()); +} diff --git a/atcoder/abc360/g.rs b/atcoder/abc360/g.rs new file mode 100644 index 00000000..b4043730 --- /dev/null +++ b/atcoder/abc360/g.rs @@ -0,0 +1,151 @@ +// 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::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +// Segment Tree. This data structure is useful for fast folding on intervals of an array +// whose elements are elements of monoid I. Note that constructing this tree requires the identity +// element of I and the operation of I. +// Verified by: yukicoder No. 2220 (https://yukicoder.me/submissions/841554) +struct SegTree { + n: usize, + orign: usize, + dat: Vec, + op: BiOp, + e: I, +} + +impl SegTree + where BiOp: Fn(I, I) -> I, + I: Copy { + pub fn new(n_: usize, op: BiOp, e: I) -> Self { + let mut n = 1; + while n < n_ { n *= 2; } // n is a power of 2 + SegTree {n: n, orign: n_, dat: vec![e; 2 * n - 1], op: op, e: e} + } + // ary[k] <- v + pub fn update(&mut self, idx: usize, v: I) { + debug_assert!(idx < self.orign); + let mut k = idx + self.n - 1; + self.dat[k] = v; + while k > 0 { + k = (k - 1) / 2; + self.dat[k] = (self.op)(self.dat[2 * k + 1], self.dat[2 * k + 2]); + } + } + // [a, b) (half-inclusive) + // http://proc-cpuinfo.fixstars.com/2017/07/optimize-segment-tree/ + #[allow(unused)] + pub fn query(&self, rng: std::ops::Range) -> I { + let (mut a, mut b) = (rng.start, rng.end); + debug_assert!(a <= b); + debug_assert!(b <= self.orign); + let mut left = self.e; + let mut right = self.e; + a += self.n - 1; + b += self.n - 1; + while a < b { + if (a & 1) == 0 { + left = (self.op)(left, self.dat[a]); + } + if (b & 1) == 0 { + right = (self.op)(self.dat[b - 1], right); + } + a = a / 2; + b = (b - 1) / 2; + } + (self.op)(left, right) + } +} + +fn lis(a: &[i64]) -> Vec { + let n = a.len(); + const INF: i64 = 1 << 40; + let mut mi = vec![INF; 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() { + input! { + n: usize, + a: [i64; n], + } + let al = lis(&a); + let bl = { + let mut b = a.clone(); + b.reverse(); + for v in &mut b { + *v = -*v; + } + let mut bl = lis(&b); + bl.reverse(); + bl + }; + eprintln!("{:?}, {:?}", al, bl); + let mut coo = a.clone(); + coo.sort(); coo.dedup(); + let m = coo.len(); + let mut st = SegTree::new(m, std::cmp::max, 0usize); + let &(mut ans) = al.iter().max().unwrap(); + for i in 0..n - 1 { + ans = ans.max(al[i] + 1); + ans = ans.max(bl[i + 1] + 1); + } + for i in 0..n - 1 { + let idx = coo.binary_search(&a[i + 1]).unwrap(); + // coo[..less] <= a[i] - 2 + let less = if idx >= 1 && coo[idx - 1] == a[i + 1] - 1 { + idx - 1 + } else { + idx + }; + let ma = st.query(0..less); + ans = ans.max(ma + bl[i + 1] + 1); + let idx = coo.binary_search(&a[i]).unwrap(); + let val = st.query(idx..idx + 1); + st.update(idx, val.max(al[i])); + } + println!("{}", ans); +} diff --git a/atcoder/abc360/remain.txt b/atcoder/abc360/remain.txt new file mode 100644 index 00000000..6a69f920 --- /dev/null +++ b/atcoder/abc360/remain.txt @@ -0,0 +1 @@ +f diff --git a/atcoder/abc362/a.rs b/atcoder/abc362/a.rs new file mode 100644 index 00000000..9d7a1980 --- /dev/null +++ b/atcoder/abc362/a.rs @@ -0,0 +1,43 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let mut x = vec![]; + for _ in 0..3 { + x.push(get::()); + } + let c = get_word(); + const INF: i32 = 1 << 30; + if c == "Red" { + x[0] = INF; + } + if c == "Green" { + x[1] = INF; + } + if c == "Blue" { + x[2] = INF; + } + println!("{}", x.iter().min().unwrap()); +} diff --git a/atcoder/abc362/b.rs b/atcoder/abc362/b.rs new file mode 100644 index 00000000..b45c8113 --- /dev/null +++ b/atcoder/abc362/b.rs @@ -0,0 +1,46 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn dist(x: (i64, i64), y: (i64, i64)) -> i64 { + let dx = x.0 - y.0; + let dy = x.1 - y.1; + dx * dx + dy * dy +} + +fn main() { + let mut p = vec![]; + for _ in 0..3 { + let x: i64 = get(); + let y: i64 = get(); + p.push((x, y)); + } + let mut d = [ + dist(p[0], p[1]), + dist(p[1], p[2]), + dist(p[2], p[0]), + ]; + d.sort(); + println!("{}", if d[0] + d[1] == d[2] { "Yes" } else { "No" }); +} diff --git a/atcoder/abc362/remain.txt b/atcoder/abc362/remain.txt index e3ec3688..9fcb84e1 100644 --- a/atcoder/abc362/remain.txt +++ b/atcoder/abc362/remain.txt @@ -1,5 +1,3 @@ -a -b d e f diff --git a/atcoder/abc364/a.rs b/atcoder/abc364/a.rs new file mode 100644 index 00000000..d084cf4f --- /dev/null +++ b/atcoder/abc364/a.rs @@ -0,0 +1,37 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let n: usize = get(); + let mut s = vec![]; + for _ in 0..n { + s.push(get_word()); + } + if (1..n - 1).any(|i| s[i - 1] == "sweet" && s[i] == "sweet") { + println!("No"); + } else { + println!("Yes"); + } +} diff --git a/atcoder/abc364/remain.txt b/atcoder/abc364/remain.txt new file mode 100644 index 00000000..9fbb6235 --- /dev/null +++ b/atcoder/abc364/remain.txt @@ -0,0 +1,6 @@ +b +c +d +e +f +g diff --git a/atcoder/abc366/a.rs b/atcoder/abc366/a.rs new file mode 100644 index 00000000..75521490 --- /dev/null +++ b/atcoder/abc366/a.rs @@ -0,0 +1,31 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let n: i32 = get(); + let t: i32 = get(); + let a: i32 = get(); + println!("{}", if (n - a > a) == (t > n - t) { "Yes" } else { "No" }); +} diff --git a/atcoder/abc366/remain.txt b/atcoder/abc366/remain.txt new file mode 100644 index 00000000..9fbb6235 --- /dev/null +++ b/atcoder/abc366/remain.txt @@ -0,0 +1,6 @@ +b +c +d +e +f +g diff --git a/atcoder/abc367/a.rs b/atcoder/abc367/a.rs new file mode 100644 index 00000000..2e0760aa --- /dev/null +++ b/atcoder/abc367/a.rs @@ -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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let a: i32 = get(); + let b: i32 = get(); + let c: i32 = get(); + let a = (a + 24 - b) % 24; + let c = (c + 24 - b) % 24; + println!("{}", if a > c { "Yes" } else { "No" }); +} diff --git a/atcoder/abc367/b.rs b/atcoder/abc367/b.rs new file mode 100644 index 00000000..4fa84270 --- /dev/null +++ b/atcoder/abc367/b.rs @@ -0,0 +1,20 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + let mut s = getline().trim().to_string(); + while let Some(c) = s.pop() { + if c == '0' { + continue; + } + s.push(c); + break; + } + if let Some(c) = s.pop() { + if c != '.' { s.push(c); } + } + println!("{s}"); +} diff --git a/atcoder/abc367/remain.txt b/atcoder/abc367/remain.txt new file mode 100644 index 00000000..3a91954e --- /dev/null +++ b/atcoder/abc367/remain.txt @@ -0,0 +1,5 @@ +c +d +e +f +g diff --git a/atcoder/abc370/a.rs b/atcoder/abc370/a.rs new file mode 100644 index 00000000..8cf8e081 --- /dev/null +++ b/atcoder/abc370/a.rs @@ -0,0 +1,34 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let l: usize = get(); + let r: usize = get(); + if l == r { + println!("Invalid"); + } else { + println!("{}", ["No", "Yes"][l]); + } +} diff --git a/atcoder/abc370/b.rs b/atcoder/abc370/b.rs new file mode 100644 index 00000000..d371a929 --- /dev/null +++ b/atcoder/abc370/b.rs @@ -0,0 +1,40 @@ +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 = 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 { get_word().parse().ok().unwrap() } + +fn main() { + let n: usize = get(); + let mut a = vec![vec![0; n]; n]; + for i in 0..n { + for j in 0..i + 1 { + a[i][j] = get::() - 1; + a[j][i] = a[i][j]; + } + } + let mut x = 0; + for i in 0..n { + x = a[x][i]; + } + println!("{}", x + 1); +} diff --git a/atcoder/abc370/remain.txt b/atcoder/abc370/remain.txt new file mode 100644 index 00000000..9fbb6235 --- /dev/null +++ b/atcoder/abc370/remain.txt @@ -0,0 +1,6 @@ +b +c +d +e +f +g diff --git a/atcoder/abc371/a.rs b/atcoder/abc371/a.rs new file mode 100644 index 00000000..6a565df6 --- /dev/null +++ b/atcoder/abc371/a.rs @@ -0,0 +1,18 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + let s = getline().trim().to_string(); + if s == "< < <" || s == "> > >" { + println!("B"); + } + if s == "> < <" || s == "< > >" { + println!("A"); + } + if s == "< < >" || s == "> > <" { + println!("C"); + } +} diff --git a/atcoder/abc371/b.rs b/atcoder/abc371/b.rs new file mode 100644 index 00000000..5671c43f --- /dev/null +++ b/atcoder/abc371/b.rs @@ -0,0 +1,53 @@ +// 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::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + input! { + n: usize, m: usize, + ab: [(usize, char); m], + } + let mut ans = vec!["No"; m]; + let mut seen = vec![false; n]; + for i in 0..m { + let (a, b) = ab[i]; + let a = a - 1; + if b == 'M' { + if !seen[a] { + seen[a] = true; + ans[i] = "Yes"; + } + } + } + for a in ans { + println!("{a}"); + } +} diff --git a/atcoder/abc371/remain.txt b/atcoder/abc371/remain.txt new file mode 100644 index 00000000..3a91954e --- /dev/null +++ b/atcoder/abc371/remain.txt @@ -0,0 +1,5 @@ +c +d +e +f +g diff --git a/atcoder/abc373/a.rs b/atcoder/abc373/a.rs new file mode 100644 index 00000000..0b77e64f --- /dev/null +++ b/atcoder/abc373/a.rs @@ -0,0 +1,16 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + let mut ans = 0; + for i in 1..13 { + let s = getline().trim().to_string(); + if s.len() == i { + ans += 1; + } + } + println!("{ans}"); +} diff --git a/atcoder/abc373/b.rs b/atcoder/abc373/b.rs new file mode 100644 index 00000000..7c6083f6 --- /dev/null +++ b/atcoder/abc373/b.rs @@ -0,0 +1,19 @@ +fn getline() -> String { + let mut ret = String::new(); + std::io::stdin().read_line(&mut ret).ok().unwrap(); + ret +} + +fn main() { + let s = getline().bytes().collect::>(); + let mut p = [0; 26]; + for i in 0..26 { + let idx = (s[i] - b'A') as usize; + p[idx] = i as i32; + } + let mut ans = 0; + for i in 0..25 { + ans += (p[i] - p[i + 1]).abs(); + } + println!("{ans}"); +} diff --git a/atcoder/abc373/remain.txt b/atcoder/abc373/remain.txt new file mode 100644 index 00000000..3a91954e --- /dev/null +++ b/atcoder/abc373/remain.txt @@ -0,0 +1,5 @@ +c +d +e +f +g