結果

問題 No.2792 Security Cameras on Young Diagram
ユーザー ikomaikoma
提出日時 2024-06-22 13:49:29
言語 Rust
(1.77.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 3,236 bytes
コンパイル時間 13,102 ms
コンパイル使用メモリ 405,112 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-06-24 18:48:48
合計ジャッジ時間 14,262 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 5 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 9 ms
6,656 KB
testcase_13 AC 8 ms
6,400 KB
testcase_14 AC 8 ms
6,528 KB
testcase_15 AC 7 ms
6,016 KB
testcase_16 AC 9 ms
6,656 KB
testcase_17 AC 9 ms
6,784 KB
testcase_18 AC 7 ms
6,016 KB
testcase_19 AC 7 ms
5,888 KB
testcase_20 AC 7 ms
6,400 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 11 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports, dead_code, unused_macros, unused_variables, non_snake_case, unused_parens)]
use proconio::{input,marker::{Bytes, Chars, Usize1,Isize1}};
use std::ops::*;
use std::cmp::*;
use std::mem::swap;
use std::collections::*;

const MOD:i64 = 998244353;
const INF:i64 = 0x3fff_ffff_ffff_ffff;

macro_rules! min {($a:expr $(,)*) => {{$a}};($a:expr, $b:expr $(,)*) => {{std::cmp::min($a, $b)}};($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::min($a, min!($($rest),+))}};}
macro_rules! max {($a:expr $(,)*) => {{$a}};($a:expr, $b:expr $(,)*) => {{std::cmp::max($a, $b)}};($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::max($a, max!($($rest),+))}};}
macro_rules! chmin {($base:expr, $($cmps:expr),+ $(,)*) => {{let cmp_min = min!($($cmps),+);if $base > cmp_min {$base = cmp_min;true} else {false}}};}
macro_rules! chmax {($base:expr, $($cmps:expr),+ $(,)*) => {{let cmp_max = max!($($cmps),+);if $base < cmp_max {$base = cmp_max;true} else {false}}};}
macro_rules! mulvec {($x:expr; $s:expr) => {vec![$x; $s]};($x:expr; $s0:expr; $( $s:expr );+) => {mulvec![vec![$x; $s0]; $( $s );+ ]};}
macro_rules! outputln {($var:expr)=>{println!("{}",$var)};($var:expr,$($vars:expr),+)=>{print!("{} ",$var);outputln!($($vars),+);};}
macro_rules! debug {($($a:expr),* $(,)*) => {eprintln!(concat!($("| ",stringify!($a), "={:?} "),*, "|"),$(&$a),*);};}


fn solve() {
    input! {
        n: usize,
		mut A:[usize;n],
    }
	let mut ah = vec![0;100_000+10];
	let cmb = combination::ModCombination::new(200_000+100);
    let mut ans = 0;
	for (h, &a) in A.iter().take(n).enumerate() {
		ah[a] += 1;
		ans += cmb.nCr(a+h-1, h);
		ans %= MOD;
	}
	let mut h = n;
	for x in 1..=100_000 {
		ans += cmb.nCr(x+h-2, h-1);
		ans %= MOD;
		h -= ah[x];
		if h == 0 {break;}
	}

    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(128 * 1024 * 1024)
        .spawn(|| solve()).unwrap()
        .join().unwrap();
}

pub mod combination {
	type Int = i64;
	const MOD: Int = 998244353;
	const fn pow_mod(x: Int, mut n: Int, m: Int) -> Int {
		if m == 1 {
			return 0;
		}
		let mut r: u64 = 1;
		let mut y: u64 = x.rem_euclid(m) as u64;
		while n != 0 {
			if (n & 1) > 0 {
				r = (r * y) % (m as u64);
			}
			y = (y * y) % (m as u64);
			n >>= 1;
		}
		r as Int
	}
	pub struct ModCombination {
		fac: Vec<Int>,
		ifac: Vec<Int>,
	}
	impl ModCombination {
		pub fn new(size: usize) -> Self {
			let mut fac = vec![1; size + 1];
			let mut f = 1;
			let mut i = 2;
			while i <= size {
				f = f * i as Int % MOD;
				fac[i] = f;
				i += 1;
			}
			let mut ifac = vec![1; size + 1];
			let mut f = pow_mod(fac[size], MOD - 2, MOD);
			ifac[size] = f;
			let mut i = size;
			while i > 0 {
				f = f * i as Int % MOD;
				i -= 1;
				ifac[i] = f;
			}
			Self { fac, ifac }
		}
		#[inline]
		pub fn nCr(&self, n: usize, r: usize) -> Int {
			if n < r {
				return 0;
			}
			self.fac[n] * self.ifac[r] % MOD * self.ifac[n - r] % MOD
		}
		#[inline]
		pub fn nPr(&self, n: usize, r: usize) -> Int {
			if n < r {
				return 0;
			}
			self.fac[n] * self.ifac[n - r] % MOD
		}
		#[inline]
		pub fn nHr(&self, n: usize, r: usize) -> Int {
			if n == 0 && r == 0 {
				return 1;
			}
			self.nCr(n + r - 1, r)
		}
	}
}
0