結果
| 問題 | No.3556 KCPC or KUPC |
| コンテスト | |
| ユーザー |
Solalyth
|
| 提出日時 | 2026-05-29 19:05:27 |
| 言語 | Rust (1.94.0 + proconio + num + itertools) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 22,104 bytes |
| 記録 | |
| コンパイル時間 | 5,681 ms |
| コンパイル使用メモリ | 231,760 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-29 19:05:38 |
| 合計ジャッジ時間 | 8,387 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
| 純コード判定待ち |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 5 % | AC * 2 |
| 部分点2 | 5 % | AC * 2 |
| 部分点3 | 5 % | AC * 2 |
| 部分点4 | 5 % | AC * 2 |
| 部分点5 | 5 % | AC * 2 |
| 部分点6 | 6 % | AC * 2 |
| 部分点7 | 7 % | AC * 2 |
| 部分点8 | 8 % | AC * 2 |
| 部分点9 | 9 % | AC * 2 |
| 部分点10 | 10 % | AC * 2 |
| 部分点11 | 5 % | AC * 10 |
| 部分点12 | 5 % | AC * 10 |
| 部分点13 | 25 % | AC * 20 |
| 合計 | 100 点 |
ソースコード
#![allow(unused_must_use, non_snake_case, unused_labels, unused_imports, non_upper_case_globals)]
use external::*;
use cplib::prelude::*;
use nest as vec;
const INTERACTIVE: bool = false;
// const INTERACTIVE: bool = true; use input_interactive as input;
// #[allow(dead_code)] type Mint = ac_library::ModInt998244353;
fn solve() {
input! {
N: usize, S: [chars; N]
}
let K = N/11;
if S[0][9*K] == '#' { out << "KCPC"; } else { out << "KUPC"; }
}
fn main() {
out::init(INTERACTIVE || LOCAL);
solve();
out::print();
}
mod external { pub use { proconio::{ input, input_interactive, marker::{Chars as chars, Usize1 as usize1} }, itertools::{Itertools, iproduct}, num::integer::{gcd, lcm, Roots}, }; }
// my library: https://github.com/solalyth/cplib-rs
mod cplib { #![allow(unused_macros, dead_code)] pub const LOCAL: bool = false; pub mod prelude { pub use std::{ collections::{VecDeque, HashMap, HashSet, BTreeMap, BTreeSet, BinaryHeap}, cmp::{Ordering, Reverse}, mem::{replace, take} }; pub use crate::cplib::{ *, LOCAL, ds::{unionfind::UnionFind, segtree::*, csr::{CSR, Edge}}, algo::func::*, traits::prelude::*, util::output::{out, end}, }; } pub mod ds { pub mod unionfind { use std::fmt::Debug; pub trait Abelian { type T: Clone + Eq; fn e() -> Self::T; fn add(l: &Self::T, r: &Self::T) -> Self::T; fn inv(x: &Self::T) -> Self::T; fn sub(l: &Self::T, r: &Self::T) -> Self::T { Self::add(l, &Self::inv(r)) } } pub struct Xor; impl Abelian for Xor { type T = bool; fn e() -> bool { false } fn add(l: &bool, r: &bool) -> bool { l^r } fn inv(x: &bool) -> bool { *x } } pub struct UnionFind<Op: Abelian> { par: Vec<usize>, size: Vec<usize>, diff: Vec<Op::T>, next: Vec<usize> } impl UnionFind<Xor> { pub fn new_xor(len: usize) -> Self { Self::new(len) } } impl<Op: Abelian> UnionFind<Op> { pub fn new(len: usize) -> Self { UnionFind { par: (0..len).collect(), size: vec![1; len], diff: vec![Op::e(); len], next: (0..len).collect() } } pub fn clear(&mut self) { for i in 0..self.len() { self.par[i] = i; self.size[i] = 1; self.diff[i] = Op::e(); self.next[i] = i; } } pub fn len(&self) -> usize { self.par.len() } pub fn leader(&mut self, i: usize) -> usize { loop { let p = self.par[i]; let g = self.par[p]; if p == g { return g; } self.diff[i] = Op::add(&self.diff[i], &self.diff[p]); self.par[i] = g; } } pub fn size(&mut self, mut i: usize) -> usize { i = self.leader(i); self.size[i] } pub fn is_same(&mut self, i: usize, j: usize) -> bool { self.leader(i) == self.leader(j) } pub fn diff(&mut self, i: usize, j: usize) -> Op::T { assert!(self.is_same(i, j)); Op::sub(&self.diff[i], &self.diff[j]) } pub fn merge(&mut self, i: usize, j: usize, mut w: Op::T) -> (usize, usize) { let (mut old, mut new) = (self.leader(i), self.leader(j)); w = Op::sub(&Op::add(&w, &self.diff[j]), &self.diff[i]); if old == new { return if w == Op::e() { (old, !0) } else { (!0, !0) } } if !(self.size[old] <= self.size[new]) { (old, new) = (new, old); w = Op::inv(&w); } self.par[old] = new; self.diff[old] = w; self.size[new] += self.size[old]; self.next.swap(i, j); (new, old) } pub fn size_undo(&self, new: usize, old: usize) -> (usize, usize) { (self.size[new] - self.size[old], self.size[old]) } pub fn groups(&mut self) -> Vec<Vec<usize>> { let mut res = vec![vec![]; self.len()]; for i in 0..self.len() { res[self.leader(i)].push(i); } res } pub fn group(&self, i: usize) -> Vec<usize> { let (mut res, mut j) = (vec![i], self.next[i]); while j != i { res.push(j); j = self.next[j]; } res } pub fn leaders(&self) -> Vec<usize> { (0..self.len()).filter(|&i| self.par[i] == i).collect() } } impl<Op: Abelian> Clone for UnionFind<Op> { fn clone(&self) -> Self { Self { par: self.par.clone(), size: self.size.clone(), diff: self.diff.clone(), next: self.next.clone() } } } impl<Op: Abelian> std::fmt::Debug for UnionFind<Op> where Op::T: Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut s = String::new(); for g in self.clone().groups() { if !g.is_empty() { s += &format!("{g:?}, "); } } write!(f, "[ {} ]", &s[..s.len()-2]) } } } pub mod segtree { use std::{fmt::Debug, mem::replace, ops::{Index, RangeBounds}, slice::SliceIndex}; use crate::cplib::util::func::to_bounds; #[allow(unused_variables)] pub trait SegtreeOp: Sized { const BEATS: bool = false; type Value: Clone; type Lazy: Clone; fn id_value() -> Self::Value; fn prod_value(lhs: &Self::Value, rhs: &Self::Value) -> Self::Value; fn act_value(value: &mut Self::Value, lazy: &Self::Lazy) -> bool { true } fn prod_lazy(lazy: &mut Self::Lazy, ad: &Self::Lazy) {} fn segtree_new(len: usize) -> Segtree<Self> { Segtree::new(len) } fn segtree_from_iter(iter: impl ExactSizeIterator<Item = Self::Value>) -> Segtree<Self> { let mut seg = Segtree::new(iter.len()); let len = seg.len(); for (i, v) in iter.enumerate() { seg.tree[len+i] = v; } for i in (1..len).rev() { seg.update(i); } seg } } pub struct Segtree<Op: SegtreeOp> { tree: Vec<Op::Value>, lazy: Vec<Option<Op::Lazy>>, depth: u32 } impl<Op: SegtreeOp> Segtree<Op> { pub fn new(len: usize) -> Self { let depth = (len.max(2)-1).ilog2() + 2; Segtree { tree: vec![Op::id_value(); 1<<depth], lazy: vec![None; 1<<depth], depth } } pub fn len(&self) -> usize { 1 << self.depth-1 } pub fn get(&mut self, mut i: usize) -> &Op::Value { i += self.len(); for j in (1..self.depth).rev() { self.push(i >> j); } &self.tree[i] } #[track_caller] pub fn set<T>(&mut self, mut i: usize, f: impl FnOnce(&mut Op::Value) -> T) -> T { i += self.len(); for j in (1..self.depth).rev() { self.push(i >> j); } let res = f(&mut self.tree[i]); for j in 1..self.depth { self.update(i >> j); } res } pub fn push_all(&mut self) { for i in 1..self.len() { self.push(i); } } pub fn fold(&mut self, range: impl RangeBounds<usize>) -> Op::Value { let [mut l, mut r] = to_bounds(range, self.len()).map(|v| v+self.len()); if r == self.len() { return Op::id_value(); } let (mut rl, mut rr) = (Op::id_value(), Op::id_value()); for i in (1..self.depth).rev() { self.push(l >> i); self.push(r-1 >> i); } while l < r { if l&1 == 1 { rl = Op::prod_value(&rl, &self.tree[l]); l += 1; } if r&1 == 1 { rr = Op::prod_value(&self.tree[r-1], &rr); } l >>= 1; r >>= 1; } Op::prod_value(&rl, &rr) } pub fn apply(&mut self, range: impl RangeBounds<usize>, lazy: Op::Lazy) { let [l, r] = to_bounds(range, self.len()).map(|v| v + self.len()); if r == self.len() { return; } for i in (1..self.depth).rev() { self.push(l >> i); self.push(r-1 >> i); } let (mut s, mut t) = (l, r); while s < t { if s&1 == 1 { self.node_apply(s, &lazy); s += 1; } if t&1 == 1 { t -= 1; self.node_apply(t, &lazy); } s >>= 1; t >>= 1; } for i in 1..self.depth { if ((l >> i) << i) != l { self.update(l >> i); } if ((r >> i) << i) != r { self.update(r-1 >> i); } } } pub fn max_right(&mut self, l: usize, r_max: usize, f: impl Fn(&Op::Value) -> bool) -> usize { assert!(l <= self.len()); if l == self.len() { return self.len().min(r_max); } let (mut r, mut val) = (l + self.len(), Op::id_value()); for i in (1..self.depth).rev() { self.push(r >> i); } loop { while r&1 == 0 { r >>= 1; } let tmp = Op::prod_value(&val, &self.tree[r]); if !f(&tmp) { break; } val = tmp; r += 1; if r & r-1 == 0 { return self.len().min(r_max); } } while r < self.len() { self.push(r); r *= 2; let tmp = Op::prod_value(&val, &self.tree[r]); if f(&tmp) { val = tmp; r += 1; } } (r - self.len()).min(r_max) } pub fn min_left(&mut self, r: usize, f: impl Fn(&Op::Value) -> bool) -> usize { assert!(r <= self.len()); if r == 0 { return 0; } let (mut l, mut val) = (r + self.len(), Op::id_value()); for i in (1..self.depth).rev() { self.push(l-1 >> i); } loop { l -= 1; while l != 1 && l&1 == 1 { l >>= 1; } let tmp = Op::prod_value(&self.tree[l], &val); if !f(&tmp) { break; } val = tmp; if l & l-1 == 0 { return 0; } } while l < self.len() { self.push(l); l = 2*l + 1; let tmp = Op::prod_value(&self.tree[l], &val); if f(&tmp) { val = tmp; l -= 1; } } l+1 - self.len() } fn node_apply(&mut self, i: usize, lazy: &Op::Lazy) { if Op::BEATS { self.comp_lazy(i, lazy); if !Op::act_value(&mut self.tree[i], lazy) { self.push(i); self.update(i); } } else { let res = Op::act_value(&mut self.tree[i], lazy); debug_assert!(res, "you forgot SegTreeOp::BEATS"); self.comp_lazy(i, lazy); } } fn push(&mut self, i: usize) { debug_assert!(i < self.len()); let Some(lazy) = replace(&mut self.lazy[i], None) else { return }; self.node_apply(2*i, &lazy); self.node_apply(2*i+1, &lazy); } fn update(&mut self, i: usize) { debug_assert!(i < self.len()); debug_assert!(self.lazy[i].is_none()); self.tree[i] = Op::prod_value(&self.tree[2*i], &self.tree[2*i+1]); } fn comp_lazy(&mut self, i: usize, ad: &Op::Lazy) { if let Some(lazy) = &mut self.lazy[i] { Op::prod_lazy(lazy, ad); } else { self.lazy[i] = Some(ad.clone()); } } } impl<Op: SegtreeOp> Clone for Segtree<Op> { fn clone(&self) -> Self { Self { tree: self.tree.clone(), lazy: self.lazy.clone(), depth: self.depth.clone() } } } impl<Op: SegtreeOp> Debug for Segtree<Op> where Op::Value: Debug { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut seg = self.clone(); seg.push_all(); write!(f, "{:?}", &seg.tree[self.len()..]) } } impl<Op: SegtreeOp, I: SliceIndex<[Op::Value]>> Index<I> for Segtree<Op> { type Output = I::Output; fn index(&self, index: I) -> &Self::Output { Index::index(&self.tree[self.len()..], index) } } } pub mod csr { use std::{fmt::Debug, ops::{Index, IndexMut}}; #[derive(Clone)] pub struct CSR<T: Default> { pub dat: Vec<T>, pub idx: Vec<usize>, } pub type Edge = CSR<(usize, usize)>; impl Edge { pub fn from_edges(n: usize, und: bool, iter: impl IntoIterator<Item = (usize, usize)> + Clone) -> Self { let mut idx = vec![0; n+2]; for (i, j) in iter.clone() { idx[i+2] += 1; if und { idx[j+2] += 1; } } for i in 0..=n { idx[i+1] += idx[i]; } let mut dat = vec![(0, 0); idx.pop().unwrap()]; for (k, (i, j)) in iter.into_iter().enumerate() { dat[idx[i+1]] = (j, k); idx[i+1] += 1; if und && i != j { dat[idx[j+1]] = (i, k); idx[j+1] += 1; } } Self { dat, idx } } pub fn sort(&mut self) { for i in 0..self.idx_len() { self.dat[self.idx[i]..self.idx[i+1]].sort_unstable(); } } pub fn contains(&self, u: usize, v: usize) -> bool { self[u].binary_search_by_key(&v, |e| e.0).is_ok() } } impl<T: Default> CSR<T> { pub fn new() -> Self { Self { dat: vec![], idx: vec![0] } } pub fn idx_len(&self) -> usize { self.idx.len()-1 } pub fn dat_len(&self) -> usize { self.dat.len() } pub fn push(&mut self, x: T) { self.dat.push(x); *self.idx.last_mut().unwrap() += 1; } pub fn next_vec(&mut self) { self.idx.push(self.dat.len()); } } impl<T: Default> Index<usize> for CSR<T> { type Output = [T]; fn index(&self, i: usize) -> &Self::Output { &self.dat[self.idx[i]..self.idx[i+1]] } } impl<T: Default> IndexMut<usize> for CSR<T> { fn index_mut(&mut self, i: usize) -> &mut Self::Output { &mut self.dat[self.idx[i]..self.idx[i+1]] } } impl Debug for Edge { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut v = vec![]; for i in 0..self.idx_len() { for &(j, k) in &self[i] { v.push((i, j, k)); } } write!(f, "{v:?}") } } } } pub mod algo { pub mod func { pub fn next_permutation<T: Ord>(v: &mut [T]) -> bool { let Some(i) = v.windows(2).rposition(|w| w[0] < w[1]) else { return false; }; let j = v.iter().rposition(|e| e > &v[i]).unwrap(); v.swap(i, j); v[i+1..].reverse(); true } pub fn prev_permutation<T: Ord>(v: &mut [T]) -> bool { let Some(i) = v.windows(2).rposition(|w| w[0] > w[1]) else { return false; }; let j = v.iter().rposition(|e| e < &v[i]).unwrap(); v.swap(i, j); v[i+1..].reverse(); true } pub fn run_length<T: Eq>(iter: impl IntoIterator<Item = T>) -> Vec<(T, usize)> { let mut res = vec![]; for t in iter { let Some(l) = res.last_mut() else { res.push((t, 1)); continue; }; if t == l.0 { l.1 += 1; } else { res.push((t, 1)); } } res } pub fn dedup_inplace<T>(v: &mut Vec<T>, f: impl Fn(&mut T, &mut T) -> bool) { let mut l = 0; for r in 1..v.len() { let (sl, sr) = v.split_at_mut(r); if !f(&mut sl[l], &mut sr[0]) { v.swap(l+1, r); l += 1; } } v.truncate(l+1); } pub fn prefix_fold<T, U>(init: T, iter: impl IntoIterator<Item = U>, mut f: impl FnMut(&T, U) -> T) -> Vec<T> { let mut res = vec![init]; for u in iter { res.push(f(res.last().unwrap(), u)); } res } pub fn suffix_fold<T, U>(init: T, iter: impl Iterator<Item = U> + DoubleEndedIterator, mut f: impl FnMut(&T, U) -> T) -> Vec<T> { let mut res = vec![init]; for u in iter.rev() { res.push(f(res.last().unwrap(), u)); } res.reverse(); res } #[macro_export] macro_rules! binary_search { ($low:expr, $high:expr) => { if 1<$high.wrapping_sub($low) { Some($high.wrapping_add($low)/2) } else { None } } } } } pub mod graph { } pub mod math { pub mod func { pub fn gcd(mut a: usize, mut b: usize) -> usize { while b != 0 { (a, b) = (b, a%b); } a } pub fn lcm(a: usize, b: usize) -> usize { (a/gcd(a, b)).saturating_mul(b) } macro_rules! extgcd { ($a:expr, $b:expr) => {{ let (a, b) = ($a, $b); let (mut p0, mut q0, mut r0, mut p1, mut q1, mut r1) = (a.signum(), 0, a.abs(), 0, b.signum(), b.abs()); while r1 != 0 { let t = r0/r1; (p0, q0, r0, p1, q1, r1) = (p1, q1, r1, p0 - t*p1, q0 - t*q1, r0 - t*r1); } (p0, q0, r0) }}; } pub fn bezout(mut a: i64, mut b: i64, mut c: i64) -> Option<(i64, i64, i64, i64)> { assert!(b != 0 && a.max(b) < 4e9 as i64); let (x, _, g) = extgcd!(a, b); if c%g != 0 { return None; } (a, b, c) = (a/g, b/g, c/g); let x = (c%b)*x%b; Some((x, (c-a*x)/b, b.abs(), -a*b.signum())) } pub fn modpow(mut x: u128, mut n: u128, m: u128) -> u128 { if m == 1 { return 0; } if n == 0 { return 1; } x %= m; let mut res = 1; while n != 0 { if n&1 == 1 { res = res*x % m; } x = x*x % m; n /= 2; } res } pub fn into_ary(mut n: u64, base: u64) -> Vec<u64> { let mut res = vec![]; while n != 0 { res.push(n%base); n /= base; } res } pub fn from_ary(d: &[u64], base: u64) -> u64 { let mut res = 0; for &d in d { res = res*base + d; } res } pub fn rational(mut p: i128, mut q: i128) -> (i128, i128) { assert!((p, q) != (0, 0)); if q != 0 { if q < 0 { (p, q) = (-p, -q); } let g = gcd(p.abs() as usize, q.abs() as usize) as i128; (p/g, q/g) } else { (1, 0) } } pub fn into_uv([x, y]: [i128; 2], p: i128, q: i128) -> [i128; 2] { [q*x+p*y, q*y-p*x] } pub fn divisors(pe: &[(usize, usize)]) -> Vec<usize> { let mut res = vec![1]; for &(p, e) in pe.into_iter() { for i in 0..res.len() { let mut k = res[i]; for _ in 0..e { k *= p; res.push(k); } } } res } pub fn mex(mut v: Vec<usize>) -> usize { v.sort_unstable(); v.dedup(); for i in 0..v.len() { if v[i] != i { return i; } } v.len() } } } pub mod mod998 { } pub mod traits { pub mod prelude { pub use super::{ int_util::*, map_init::*, }; } pub mod int_util { pub fn floor<T: IntUtil>(l: T, r: T) -> T { l.floor(r).0 } pub fn ceil<T: IntUtil>(l: T, r: T) -> T { l.ceil(r).0 } pub trait IntUtil: Sized { fn floor(self, rhs: Self) -> (Self, Self); fn ceil(self, rhs: Self) -> (Self, Self); } macro_rules! int { ($($t:ty),+) => {$( impl IntUtil for $t { fn floor(self, rhs: Self) -> ($t, $t) { assert!(0 < rhs); let (q, r) = (self/rhs, self%rhs); if r < 0 { (q-1, r+rhs) } else { (q, r) } } fn ceil(self, rhs: Self) -> ($t, $t) { assert!(0 < rhs); let (q, r) = (self/rhs, self%rhs); if 0 < r { (q+1, rhs-r) } else { (q, -r) } } } )+}; } int!(i32, i64, i128, isize); macro_rules! uint { ($($t:ty),+) => {$( impl IntUtil for $t { fn floor(self, rhs: Self) -> ($t, $t) { (self/rhs, self%rhs) } fn ceil(self, rhs: Self) -> ($t, $t) { let q = (self+rhs-1)/rhs; (q, q*rhs-self) } } )+}; } uint!(u32, u64, u128, usize); } pub mod map_init { use std::collections::{BTreeMap, HashMap}; use std::hash::Hash; pub trait MapInit { type K; type V; fn init(&mut self, key: Self::K, init: Self::V) -> &mut Self::V; fn init_with(&mut self, key: Self::K, init: impl FnOnce() -> Self::V) -> &mut Self::V; } impl<K: Eq + Hash, V> MapInit for HashMap<K, V> { type K = K; type V = V; fn init(&mut self, key: K, init: V) -> &mut V { self.entry(key).or_insert(init) } fn init_with(&mut self, key: K, init: impl FnOnce() -> Self::V) -> &mut V { self.entry(key).or_insert_with(init) } } impl<K: Ord, V> MapInit for BTreeMap<K, V> { type K = K; type V = V; fn init(&mut self, key: K, init: V) -> &mut V { self.entry(key).or_insert(init) } fn init_with(&mut self, key: Self::K, init: impl FnOnce() -> Self::V) -> &mut Self::V { self.entry(key).or_insert_with(init) } } } } pub mod util { pub mod output { #![allow(static_mut_refs, non_camel_case_types)] use std::{mem::replace, ops::{Not, Shl}, fmt::Write}; static mut BUFFER: Buffer = Buffer { buf: String::new(), endp: false, prev: Previous::LineHead }; pub struct Buffer { buf: String, endp: bool, prev: Previous, } impl Buffer { fn print(&mut self) { if replace(&mut self.prev, Previous::LineHead) == Previous::LineHead { self.buf.pop(); } if crate::cplib::LOCAL { eprint!("\x1b[32m"); if self.buf.is_empty() { eprintln!("(empty)"); } else { println!("{}", self.buf); } eprint!("\x1b[0m"); } else { if !self.buf.is_empty() { println!("{}", self.buf); } } self.buf.clear(); } fn space(&mut self, sp: bool) { let prev = replace(&mut self.prev, if sp {Previous::Space} else {Previous::NoSpace}); if (sp || prev == Previous::Space) && prev != Previous::LineHead { self.buf.push(' '); } } } #[derive(Clone, Copy)] pub struct out; pub struct out_usp; pub struct end; #[derive(PartialEq, Eq, Clone, Copy)] enum Previous { Space, NoSpace, LineHead, } impl out { pub fn init(endp: bool) { unsafe { BUFFER.buf.reserve(1<<24); BUFFER.endp = endp; } } pub fn print() { unsafe { BUFFER.print(); } } fn push<T: Primitive>(v: &T) { unsafe { BUFFER.space(true); v.fmt(&mut BUFFER.buf); } } pub fn ln() { unsafe { BUFFER.buf.push('\n'); BUFFER.prev = Previous::LineHead; } } } impl out_usp { fn push<T: Primitive>(v: &T) { unsafe { BUFFER.space(false); v.fmt(&mut BUFFER.buf); } } } impl Not for out { type Output = out_usp; fn not(self) -> Self::Output { out_usp } } macro_rules! impl_outs { ($($t:ty),+) => { $( impl<T: Primitive> Shl<T> for $t { type Output = Self; fn shl(self, rhs: T) -> Self::Output { Self::push(&rhs); self } } impl Shl<end> for $t { type Output = Self; fn shl(self, _: end) -> Self::Output { unsafe { if BUFFER.endp { BUFFER.print(); } else { BUFFER.buf += "\n"; BUFFER.prev = Previous::LineHead; } } self } } )+ }; } impl_outs!(out, out_usp); macro_rules! impl_for_slices { ($($t:ty),+) => { $(impl_for_slices!($t; out, out_usp);)+ }; ($t:ty; $($u:ty),+) => { $( impl<T: Primitive> Shl<$t> for $u { type Output = Self; fn shl(self, rhs: $t) -> Self::Output { for v in rhs { Self::push(v); } self } } )+} } impl_for_slices!(&[T], &Vec<T>); trait Primitive { fn fmt(&self, buf: &mut String); } macro_rules! impl_primitive { ($($t:ty),+) => { $( impl Primitive for $t { fn fmt(&self, buf: &mut String) { write!(buf, "{self}").ok(); } } )+ } } impl_primitive!(char, u32, u64, u128, usize, i32, i64, i128, f32, f64, &str, &String, String); impl Primitive for u8 { fn fmt(&self, buf: &mut String) { buf.push(*self as char); } } impl Primitive for bool { fn fmt(&self, buf: &mut String) { *buf += if *self { "Yes" } else { "No" }; } } } pub mod macros { #[macro_export] macro_rules! nest { [void; $n:expr] => { std::vec![std::vec![]; $n] }; [void; $n:expr $(;$m:expr)+] => { std::vec![crate::nest![void$(;$m)+]; $n] }; [$($v:expr),*] => { std::vec![$($v),*] }; [$e:expr; $n:expr] => { std::vec![$e; $n] }; [$e:expr; $n:expr $(;$m:expr)+] => { std::vec![crate::nest![$e$(;$m)+]; $n] }; } #[macro_export] macro_rules! iota { ($range:expr) => { ($range).collect::<Vec<_>>() }; ($range:expr, $($f:tt)*) => { ($range).map($($f)*).collect::<Vec<_>>() }; } #[macro_export] macro_rules! min { ($($vl:expr),+) => { [$($vl),+].into_iter().reduce(|x,y| if x <= y {x} else {y}).unwrap() } } #[macro_export] macro_rules! max { ($($vl:expr),+) => { [$($vl),+].into_iter().reduce(|x,y| if x >= y {x} else {y}).unwrap() } } #[macro_export] macro_rules! minmax { ($v:expr, $w:expr) => {{ let (v, w) = ($v, $w); if v <= w { (v, w) } else { (w, v) } }}; ($($vl:expr),+) => {{ let l = [$($vl),+]; (l.iter().reduce(|x,y| if x <= y {x} else {y}).unwrap().clone(), l.iter().reduce(|x,y| if x >= y {x} else {y}).unwrap().clone()) }} } #[macro_export] macro_rules! chmin { ($dst:expr; $v:expr) => { { let v = $v; if v < $dst { $dst = v; true } else { false } } }; ($dst:expr; $($vl:expr),+) => { crate::chmin!($dst; crate::min!($($vl),+)) } } #[macro_export] macro_rules! chmax { ($dst:expr; $v:expr) => { { let v = $v; if $dst < v { $dst = v; true } else { false } } }; ($dst:expr; $($vl:expr),+) => { crate::chmax!($dst; crate::max!($($vl),+)) } } #[macro_export] macro_rules! swap { ($l:expr, $r:expr) => { ($l, $r) = ($r, $l); }; } #[macro_export] macro_rules! prefix { ($init:expr, $v:expr) => { { let mut res = vec![$init]; for x in $v.into_iter() { res.push(*res.last().unwrap()+x); } res } }; ($v:expr) => { prefix!(0, $v) } } #[macro_export] macro_rules! sum { ($init:expr; $v:expr) => { { let mut res = $init; for x in $v.into_iter() { res += x; } res } }; ($v:expr) => { sum!(0; $v) } } #[macro_export] macro_rules! vadd { ($v:expr; -$x:expr) => {{ let x = $x; for e in &mut $v { *e -= x; } }}; ($v:expr; $x:expr) => {{ let x = $x; for e in &mut $v { *e += x; } }} } #[macro_export] macro_rules! add { ($x:expr; $y:expr) => { let t = $y; $x += t; }; } } pub mod func { use std::ops::{RangeBounds, Bound}; pub fn to_bounds(range: impl RangeBounds<usize>, sup: usize) -> [usize; 2] { let l = match range.start_bound() { Bound::Included(&v) => v, Bound::Excluded(&v) => v+1, Bound::Unbounded => 0 }; let r = match range.end_bound() { Bound::Included(&v) => v+1, Bound::Excluded(&v) => v, Bound::Unbounded => sup }.min(sup); if l >= r { [0, 0] } else { [l, r] } } } pub mod debug { pub fn replace_inf_and_truncate(s: String) -> String { s } pub fn debug_table<T: std::fmt::Debug>(_: &Vec<Vec<T>>, _: usize, _: usize) {} #[macro_export] macro_rules! epr { ($($args:tt)*) => {} } #[macro_export] macro_rules! oj_local { ($oj:expr, $local:expr) => { if $crate::LOCAL { $local } else { $oj } }; } #[macro_export] macro_rules! table { ($t:expr, $x:expr, $y:expr) => {}; ($t:expr) => {}; } } } }
Solalyth