Submission #68726727


Source Code Expand

#![allow(unused_imports,non_snake_case,dead_code)]
use std::{cmp::Reverse as Rev,ops::Range,collections::*,iter::*,mem::swap};
use rustc_hash::{FxHashSet as HashSet,FxHashMap as HashMap};
use ac_library::{*,modint::ModIntBase,ModInt998244353 as M};
use {proconio::{marker::*,*},itertools::*};



#[fastout]
fn main(){
    input!{
        N:usize,
        K:usize,
        X:usize,
    }

    let pre=Pre::<M>::new(500);
    let mut dp=vec![vec![[M::new(0);2];300];300];

    let ng=0;
    let ok=1;
    dp[0][0][ng]+=1;

    for i in 0..299{
        for j in 0..300{
            let [mut ngs,oks]=dp[i][j];
            if i==K{
                ngs=M::new(0);
            }

            let need=if i<K{
                j+X
            } else{
                j
            };
            let isok=i<K;

            for k in 0..=N{
                let coeff=pre.choose(N,k);
                let ngs=ngs*coeff;
                let oks=oks*coeff;
                if isok && (ngs!=M::new(0) || oks!=M::new(0)){
                    // eprintln!("i = {}",i);
                    // eprintln!("j = {}",j);
                    // eprintln!("k = {}",k);
                    // eprintln!("need = {}",need);
                    // eprintln!("ngs = {}",ngs);
                    // eprintln!("oks = {}",oks);
                    // eprintln!();
                }
                
                if k<need{
                    if (need-k)%2==0{
                        if (i+1,(need-k)/2,ok)==(1,0,1){
                            // eprintln!("a: {}",ngs+oks);
                        }
                        dp[i+1][(need-k)/2][ok]+=ngs+oks;
                    } else{
                        if isok{
                            if (i+1,(need-k+1)/2,ng)==(1,0,1){
                                // eprintln!("b: {}",ngs);
                            }
                            dp[i+1][(need-k+1)/2][ng]+=ngs;
                            if (i+1,(need-k+1)/2,ok)==(1,0,1){
                                // eprintln!("x: {}",oks);
                            }
                            dp[i+1][(need-k+1)/2][ok]+=oks;
                        }
                    }
                } else if k==need{
                    if (i+1,0,ok)==(1,0,1){
                        // eprintln!("c: {}",ngs+oks);
                    }
                    dp[i+1][0][ok]+=ngs+oks;
                } else if k==need+1{
                    if isok{
                        if (i+1,0,ng)==(1,0,1){
                            // eprintln!("d: {}",ngs);
                        }
                        dp[i+1][0][ng]+=ngs;
                        if (i+1,0,ok)==(1,0,1){
                            // eprintln!("e: {}",oks);
                        }
                        dp[i+1][0][ok]+=oks;
                    }
                } else{
                    if isok{
                        if (i+1,0,ng)==(1,0,1){
                            // eprintln!("f: {}",ngs+oks);
                        }
                        dp[i+1][0][ng]+=ngs+oks;
                    }
                }
            }
        }
    }

    // for i in 0..5{
    //     for j in 0..5{
    //         eprint!("{:?} ",dp[i][j]);
    //     }
    //     // eprintln!();
    // }

    let ans=dp[299][0][ok];
    println!("{ans}");
}



// Modを超える数はpanicする
// 注意:
//      Modは素数
//      multi_choose(n,k)を使うときは,fac(n+k-1)まで必要になる
struct Pre<M:ModIntBase>{
    fac:Vec<M>,
    finv:Vec<M>,
}
impl<M:ModIntBase> Pre<M>{
    fn new(n:usize)->Self{
        assert!(n<M::modulus() as usize);

        let mut fac=vec![M::new(1);n+1];
        for i in 1..=n{
            fac[i]=fac[i-1]*M::new(i);
        }

        let mut finv=vec![M::new(0);n+1];
        finv[n]=fac[n].inv();
        for i in (1..=n).rev(){
            finv[i-1]=finv[i]*M::new(i);
        }
        
        Self{fac,finv}
    }

    fn fac(&self,n:usize)->M{
        self.fac[n]
    }

    fn finv(&self,n:usize)->M{
        self.finv[n]
    }

    fn inv(&self,n:usize)->M{
        assert!(n!=0);
        self.finv[n]*self.fac[n-1]
    }

    fn perm(&self,n:usize,k:usize)->M{
        if n<k || (n as i64)<0 || (k as i64)<0{
            return M::new(0);
        }
        self.fac(n)*self.finv(n-k)
    }

    fn choose(&self,n:usize,k:usize)->M{
        if n<k || (n as i64)<0 || (k as i64)<0{
            return M::new(0);
        }
        self.fac(n)*self.finv(k)*self.finv(n-k)
    }

    fn multi_choose(&self,n:usize,k:usize)->M{
        if (n as i64)<0 || (k as i64)<0{
            return M::new(0);
        }
        if n==0 && k==0{
            return M::new(1);
        }
        self.choose(n+k-1,k)
    }
}

Submission Info

Submission Time
Task A - CatCoder Binary Contest
User rhoo
Language Rust (rustc 1.70.0)
Score 700
Code Size 4887 Byte
Status AC
Exec Time 142 ms
Memory 2700 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 21
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 139 ms 2584 KiB
01-02.txt AC 139 ms 2632 KiB
01-03.txt AC 142 ms 2668 KiB
01-04.txt AC 56 ms 2476 KiB
01-05.txt AC 123 ms 2620 KiB
01-06.txt AC 142 ms 2668 KiB
01-07.txt AC 2 ms 2676 KiB
01-08.txt AC 2 ms 2600 KiB
01-09.txt AC 2 ms 2700 KiB
01-10.txt AC 2 ms 2564 KiB
01-11.txt AC 112 ms 2496 KiB
01-12.txt AC 2 ms 2680 KiB
01-13.txt AC 142 ms 2576 KiB
01-14.txt AC 112 ms 2696 KiB
01-15.txt AC 128 ms 2680 KiB
01-16.txt AC 136 ms 2676 KiB
01-17.txt AC 137 ms 2624 KiB
01-18.txt AC 139 ms 2596 KiB
sample-01.txt AC 3 ms 2636 KiB
sample-02.txt AC 2 ms 2696 KiB
sample-03.txt AC 141 ms 2604 KiB