Skip to content

Commit

Permalink
Add atcoder/abc360/a.rs atcoder/abc360/b.rs atcoder/abc360/c.rs atcod…
Browse files Browse the repository at this point in the history
…er/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
  • Loading branch information
koba-e964 committed Nov 9, 2024
1 parent a6c5455 commit b1b4435
Show file tree
Hide file tree
Showing 26 changed files with 931 additions and 2 deletions.
14 changes: 14 additions & 0 deletions atcoder/abc360/a.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
42 changes: 42 additions & 0 deletions atcoder/abc360/b.rs
Original file line number Diff line number Diff line change
@@ -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<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 main() {
let s = get_word().chars().collect::<Vec<_>>();
let t = get_word().chars().collect::<Vec<_>>();
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");
}
50 changes: 50 additions & 0 deletions atcoder/abc360/c.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>()
};
($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);
}
95 changes: 95 additions & 0 deletions atcoder/abc360/d.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>()
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

trait Bisect<T> {
fn lower_bound(&self, val: &T) -> usize;
fn upper_bound(&self, val: &T) -> usize;
}

impl<T: Ord> Bisect<T> 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);
}
155 changes: 155 additions & 0 deletions atcoder/abc360/e.rs
Original file line number Diff line number Diff line change
@@ -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<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() }

/// 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<M> { pub x: i64, phantom: ::std::marker::PhantomData<M> }
impl<M: Mod> ModInt<M> {
// 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<M: Mod> Default for ModInt<M> {
fn default() -> Self { Self::new_internal(0) }
}
impl<M: Mod, T: Into<ModInt<M>>> Add<T> for ModInt<M> {
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<M: Mod, T: Into<ModInt<M>>> Sub<T> for ModInt<M> {
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<M: Mod, T: Into<ModInt<M>>> Mul<T> for ModInt<M> {
type Output = Self;
fn mul(self, other: T) -> Self { ModInt::new(self.x * other.into().x % M::m()) }
}
impl<M: Mod, T: Into<ModInt<M>>> AddAssign<T> for ModInt<M> {
fn add_assign(&mut self, other: T) { *self = *self + other; }
}
impl<M: Mod, T: Into<ModInt<M>>> SubAssign<T> for ModInt<M> {
fn sub_assign(&mut self, other: T) { *self = *self - other; }
}
impl<M: Mod, T: Into<ModInt<M>>> MulAssign<T> for ModInt<M> {
fn mul_assign(&mut self, other: T) { *self = *self * other; }
}
impl<M: Mod> Neg for ModInt<M> {
type Output = Self;
fn neg(self) -> Self { ModInt::new(0) - self }
}
impl<M> ::std::fmt::Display for ModInt<M> {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
self.x.fmt(f)
}
}
impl<M: Mod> ::std::fmt::Debug for ModInt<M> {
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<M: Mod> From<i64> for ModInt<M> {
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<P>;

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());
}
Loading

0 comments on commit b1b4435

Please sign in to comment.