답안 #640519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640519 2022-09-14T19:32:59 Z Tenis0206 NoM (RMI21_nom) C++11
100 / 100
33 ms 500 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int Mod = 1e9 + 7;
const int vmax = 1e4;

int n,m;

int fact[vmax + 5], invfact[vmax + 5];

int dp[2005],aux[2005];

int nr[2005];

int lgput(int a, int b)
{
    int p = 1;
    while(b)
    {
        if(b % 2 == 0)
        {
            b/=2;
            a = 1LL * a * a % Mod;
        }
        else
        {
            --b;
            p = 1LL * p * a % Mod;
        }
    }
    return p;
}

int invmod(int x)
{
    return lgput(x,Mod-2) % Mod;
}

int comb(int n, int k)
{
    return 1LL * fact[n] * invfact[k] % Mod * invfact[n - k] % Mod;
}

int aranj(int n, int k)
{
    return 1LL * fact[n] * invfact[n - k] % Mod;
}

void precalc()
{
    fact[0] = 1;
    for(int i=1;i<=vmax;i++)
    {
        fact[i] = 1LL * fact[i-1] * i % Mod;
    }
    invfact[vmax] = invmod(fact[vmax]);
    for(int i=vmax-1;i>=0;i--)
    {
        invfact[i] = 1LL * invfact[i + 1] * (i + 1) % Mod;
    }
}

void calc_dp()
{
    int nr_tot = (2 * n) / m;
    int rest = (2 * n) % m;
    for(int r=0;r<m;r++)
    {
        nr[r] = nr_tot;
        if(r<=rest && r!=0)
        {
            ++nr[r];
        }
    }
    for(int i=0;2*i<=nr[0];i++)
    {
        dp[i] = aranj(nr[0],2*i) * invfact[i] % Mod;
    }
    int Max = nr[0] / 2;
    for(int r=1;r<m;r++)
    {
        for(int i=0;i<=Max;i++)
        {
            aux[i] = 0;
        }
        for(int i=0;i<=Max;i++)
        {
            for(int j=0;2*j<=nr[r] && i+j<=Max+nr[r]/2;j++)
            {
                aux[i + j] += dp[i] * aranj(nr[r],2*j) % Mod * invfact[j] % Mod;
                aux[i + j] %= Mod;
            }
        }
        for(int i=0;i<=n;i++)
        {
            dp[i] = aux[i];
        }
        Max += nr[r] / 2;
    }
}

signed main()
{
    cin>>n>>m;
    precalc();
    calc_dp();
    int rez = 0;
    for(int i=0;i<=n;i++)
    {
        if(i % 2 == 0)
        {
            rez += dp[i] * fact[2 * (n - i)] % Mod * aranj(n,i) % Mod;
            rez %= Mod;
        }
        else
        {
            rez -= dp[i] * fact[2 * (n - i)] % Mod * aranj(n,i) % Mod;
            rez %= Mod;
            if(rez < 0)
            {
                rez += Mod;
            }
        }
    }
    cout<<rez<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 432 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 432 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 432 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 432 KB Output is correct
25 Correct 1 ms 436 KB Output is correct
26 Correct 2 ms 432 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 432 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 432 KB Output is correct
25 Correct 1 ms 436 KB Output is correct
26 Correct 2 ms 432 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 4 ms 472 KB Output is correct
33 Correct 5 ms 488 KB Output is correct
34 Correct 8 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 432 KB Output is correct
2 Correct 1 ms 436 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 436 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 432 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 432 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 432 KB Output is correct
25 Correct 1 ms 436 KB Output is correct
26 Correct 2 ms 432 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 4 ms 472 KB Output is correct
33 Correct 5 ms 488 KB Output is correct
34 Correct 8 ms 436 KB Output is correct
35 Correct 11 ms 496 KB Output is correct
36 Correct 30 ms 500 KB Output is correct
37 Correct 11 ms 468 KB Output is correct
38 Correct 19 ms 436 KB Output is correct
39 Correct 20 ms 496 KB Output is correct
40 Correct 33 ms 500 KB Output is correct