답안 #857096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857096 2023-10-05T11:28:48 Z alexdd NoM (RMI21_nom) C++17
52 / 100
16 ms 14940 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
int n,m;
int dp[2005][2005];
int cntr[2005];
int pref[2005];
int fact[5005];
int invf[5005];
int put2[5005];
int put(int a, int exp)
{
    if(exp==0)
        return 1;
    if(exp%2==0)
        return put((a*a)%MOD,exp/2);
    else
        return (put((a*a)%MOD,exp/2)*a)%MOD;
}
int comb(int x, int y)
{
    if(x<y)
        return 0;
    return ((((fact[x]*invf[y])%MOD)*invf[x-y])%MOD);
}
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=2*n;i++)
        cntr[i%m+1]++;
    fact[0]=1;
    put2[0]=1;
    for(int i=1;i<=5*n;i++)
    {
        fact[i]=(fact[i-1]*i)%MOD;
        put2[i]=(put2[i-1]*2)%MOD;
    }
    invf[n*5] = put(fact[n*5], MOD-2);
    for(int i=n*5-1;i>=0;i--)
        invf[i]=(invf[i+1]*(i+1))%MOD;
    dp[0][0]=1;
    for(int i=1;i<=m;i++)
    {
        pref[i]=(pref[i-1]+cntr[i])%MOD;
        for(int cntp=0;cntp<=pref[i]/2;cntp++)
        {
            dp[i][cntp]=0;
            for(int x=0;x<=min(cntp,cntr[i]);x++)
            {
                dp[i][cntp] += (((((dp[i-1][cntp-x] * fact[cntr[i]])%MOD) * comb(pref[i-1] - 2*(cntp-x), x))%MOD) * (put2[cntr[i]-x] * comb(n - (pref[i-1] - 2*(cntp-x) - x) - (cntp-x) - x, cntr[i]-x)%MOD))%MOD;
                dp[i][cntp] %= MOD;
            }
            //cout<<i<<" "<<cntp<<"  "<<dp[i][cntp]<<"\n";
        }
    }
    cout<<dp[m][n];
    return 0;
}
/**

dp[i][cntp] = numarul de moduri de a plasa pietre pe primele i resturi a.i. sa fi plasat cntp perechi de pietre
cntr[i] = nr de pozitii cu restul i
pref[i] = sum(cntr[x]), x = 1..i
dp[i][cntp] = sum(dp[i-1][cntp-x] * fact[cntr[i]] * comb(pref[i-1] - 2*cntp, x) * comb(n - (pref[i-1] - 2*cntp - x) - cntp - x, cntr[i]-x)


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 3 ms 6492 KB Output is correct
28 Correct 6 ms 2396 KB Output is correct
29 Correct 7 ms 6488 KB Output is correct
30 Correct 9 ms 10584 KB Output is correct
31 Correct 5 ms 2396 KB Output is correct
32 Correct 8 ms 6492 KB Output is correct
33 Correct 11 ms 10796 KB Output is correct
34 Correct 16 ms 14940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 1 ms 2392 KB Output is correct
27 Correct 3 ms 6492 KB Output is correct
28 Correct 6 ms 2396 KB Output is correct
29 Correct 7 ms 6488 KB Output is correct
30 Correct 9 ms 10584 KB Output is correct
31 Correct 5 ms 2396 KB Output is correct
32 Correct 8 ms 6492 KB Output is correct
33 Correct 11 ms 10796 KB Output is correct
34 Correct 16 ms 14940 KB Output is correct
35 Runtime error 1 ms 604 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -