Submission #25596340


Source Code Expand

/*~Rainybunny~*/

#include <bits/stdc++.h>

#define rep( i, l, r ) for ( int i = l, rep##i = r; i <= rep##i; ++i )
#define per( i, r, l ) for ( int i = r, per##i = l; i >= per##i; --i )

const int MAXN = 5e3, MOD = 998244353;
int n, m, f[MAXN + 5], fac[MAXN + 5], ifac[MAXN + 5];

inline void subeq( int& a, const int b ) { ( a -= b ) < 0 && ( a += MOD ); }
inline int sub( int a, const int b ) { return ( a -= b ) < 0 ? a + MOD : a; }
inline int mul( const long long a, const int b ) { return int( a * b % MOD ); }
inline int add( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }
inline void addeq( int& a, const int b ) { ( a += b ) >= MOD && ( a -= MOD ); }
inline int mpow( int a, int b ) {
    int ret = 1;
    for ( ; b; a = mul( a, a ), b >>= 1 ) ret = mul( ret, b & 1 ? a : 1 );
    return ret;
}

inline void init() {
    fac[0] = 1;
    rep ( i, 1, n ) fac[i] = mul( i, fac[i - 1] );
    ifac[n] = mpow( fac[n], MOD - 2 );
    per ( i, n - 1, 0 ) ifac[i] = mul( ifac[i + 1], i + 1 );
}

inline int comb( const int a, const int b ) {
    return a < b ? 0 : mul( fac[a], mul( ifac[b], ifac[a - b] ) );
}

int main() {
    scanf( "%d %d", &n, &m ), init();
    rep ( i, 1, n ) {
        int c = n / m;
        f[i] = mul( mpow( mul( comb( i, c ), fac[c] ), m - n % m ),
          mpow( mul( comb( i, c + 1 ), fac[c + 1] ), n % m ) );
    }
    rep ( i, 1, n ) {
        rep ( j, 1, i - 1 )
            subeq( f[i], mul( f[j], mul( comb( i, j ), fac[j] ) ) );
        f[i] = mul( f[i], ifac[i] );
        printf( "%d\n", f[i] );
    }
    return 0;
}

Submission Info

Submission Time
Task G - Groups
User Rainybunny
Language C++ (GCC 9.2.1)
Score 600
Code Size 1621 Byte
Status AC
Exec Time 161 ms
Memory 3888 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:34:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   34 |     scanf( "%d %d", &n, &m ), init();
      |     ~~~~~^~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 68 ms 3876 KiB
random_02.txt AC 37 ms 3664 KiB
random_03.txt AC 79 ms 3816 KiB
random_04.txt AC 154 ms 3776 KiB
random_05.txt AC 133 ms 3656 KiB
random_06.txt AC 47 ms 3628 KiB
random_07.txt AC 25 ms 3752 KiB
random_08.txt AC 81 ms 3780 KiB
random_09.txt AC 116 ms 3636 KiB
random_10.txt AC 15 ms 3612 KiB
random_11.txt AC 14 ms 3860 KiB
random_12.txt AC 69 ms 3872 KiB
random_13.txt AC 2 ms 3612 KiB
random_14.txt AC 2 ms 3696 KiB
random_15.txt AC 3 ms 3740 KiB
random_16.txt AC 37 ms 3680 KiB
random_17.txt AC 45 ms 3764 KiB
random_18.txt AC 49 ms 3772 KiB
random_19.txt AC 105 ms 3816 KiB
random_20.txt AC 160 ms 3780 KiB
random_21.txt AC 161 ms 3876 KiB
random_22.txt AC 101 ms 3820 KiB
random_23.txt AC 160 ms 3888 KiB
random_24.txt AC 159 ms 3784 KiB
sample_01.txt AC 2 ms 3692 KiB
sample_02.txt AC 2 ms 3596 KiB
sample_03.txt AC 2 ms 3640 KiB