Submission #509743

# Submission time Handle Problem Language Result Execution time Memory
509743 2022-01-14T09:14:15 Z hotboy2703 NoM (RMI21_nom) C++14
34 / 100
500 ms 456 KB
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long maxn = 2000;
long long fac[maxn * 2 + 100];
long long fiv[maxn * 2 + 100];
long long ml(long long x, long long y){
    return (x * y) % MOD;
}
long long pow_mod(long long x,long long y){
    if (y == 0)return 1;
    long long r = pow_mod(x,y/2);
    r = ml(r,r);
    if (y % 2)r = ml(r,x);
    return r;
}
long long dp[2][maxn + 100];
long long choose(long long k,long long n){
    return ml(ml(fac[n],fiv[k]),fiv[n - k]);
}
long long n,m;
long long cal(long long x){
    for (int j = 1;j <= n;j ++)dp[0][j] = 0;
    dp[0][0] = 1;
    for (long long i = 1;i <= m;i ++){
        bool o = i & 1;
        long long am;
        if (i <= (2 * n) % m){
            am = (2 * n) / m + 1;
        }
        else{
            am = (2 * n) / m;
        }
        long long buck = am / 2;
        for (long long j = 0;j <= x;j ++){
            dp[o][j] = 0;
            for (long long k = 0;k <= j && k <= buck;k ++){
                dp[o][j] += ml(ml(ml(dp[!o][j - k], choose(k * 2,am)),fac[k*2]),choose(k,x-j+k));
                dp[o][j] %= MOD;
            }
        }
    }
    return dp[m & 1][x];
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("NOM.INP","r",stdin);
    //freopen("NOM.OUT","w",stdout);
    fac[0] = 1;
    for (long long i = 1;i <= 2 * maxn;i ++){
        fac[i] = ml(fac[i-1],i);
    }
    fiv[maxn * 2] = pow_mod(fac[2 * maxn],MOD - 2);
    for (long long i = maxn * 2 - 1;i >= 0;i --){
        fiv[i] = ml(fiv[i + 1],i + 1);
    }
    cin>>n>>m;
    /*dp[0][0] = 1;
    dp[0][1] = 0;
    for (long long i = 1;i <= m;i ++){
        long long am;
        if (i <= (2 * n) % m){
            am = (2 * n) / m + 1;
        }
        else{
            am = (2 * n) / m;
        }
        long long buck = am / 2;
        for (long long j = 0;j <= n;j ++){
            for (long long k = 0;k <= j && k <= buck;k ++){
                dp[i][j] += ml(ml(ml(dp[i - 1][j - k], choose(k * 2,am)),fac[k*2]),choose(k,n-j+k));
                dp[i][j] %= MOD;
            }
        }
    }*/
    long long ans = 1;
    for (long long i = 1;i <= 2 * n;i ++){
        ans = ml(ans,i);
    }
    for (long long j = 1;j <= n;j ++){
        if (j % 2){
            ans -= ml(ml(choose(j,n),cal(j)),fac[2 * (n - j)]) + MOD;

        }
        else{
                ans += ml(ml(choose(j,n),cal(j)),fac[2 * (n - j)]);
        }
        ans %= MOD;
    }
    cout<<(ans + MOD) % MOD;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 13 ms 332 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 284 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 6 ms 332 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 13 ms 332 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 284 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 6 ms 332 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 44 ms 360 KB Output is correct
21 Correct 49 ms 364 KB Output is correct
22 Correct 334 ms 332 KB Output is correct
23 Correct 119 ms 356 KB Output is correct
24 Correct 319 ms 332 KB Output is correct
25 Correct 308 ms 376 KB Output is correct
26 Correct 142 ms 364 KB Output is correct
27 Correct 493 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 13 ms 332 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 284 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 6 ms 332 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 44 ms 360 KB Output is correct
21 Correct 49 ms 364 KB Output is correct
22 Correct 334 ms 332 KB Output is correct
23 Correct 119 ms 356 KB Output is correct
24 Correct 319 ms 332 KB Output is correct
25 Correct 308 ms 376 KB Output is correct
26 Correct 142 ms 364 KB Output is correct
27 Correct 493 ms 456 KB Output is correct
28 Execution timed out 1087 ms 332 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 13 ms 332 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
13 Correct 4 ms 332 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 284 KB Output is correct
17 Correct 5 ms 332 KB Output is correct
18 Correct 6 ms 332 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 44 ms 360 KB Output is correct
21 Correct 49 ms 364 KB Output is correct
22 Correct 334 ms 332 KB Output is correct
23 Correct 119 ms 356 KB Output is correct
24 Correct 319 ms 332 KB Output is correct
25 Correct 308 ms 376 KB Output is correct
26 Correct 142 ms 364 KB Output is correct
27 Correct 493 ms 456 KB Output is correct
28 Execution timed out 1087 ms 332 KB Time limit exceeded
29 Halted 0 ms 0 KB -