Submission #1068156

# Submission time Handle Problem Language Result Execution time Memory
1068156 2024-08-21T08:07:27 Z 정민찬(#11128) NoM (RMI21_nom) C++17
9 / 100
1 ms 604 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll mod = 1e9 + 7;

ll fastpow(ll a, ll b) {
	ll ret = 1;
	while (b) {
		if (b % 2) ret = ret * a % mod;
		a = a * a % mod;
		b /= 2;
	}
	return ret;
}

ll fac[4010], inv[4010];
ll dp[4010][4010];

ll C(ll n, ll r) {
	return fac[n] * inv[r] % mod * inv[n-r] % mod;
}

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    fac[0] = 1;
    for (ll i=1; i<=4000; i++) {
    	fac[i] = fac[i-1] * i % mod;
    }
    inv[4000] = fastpow(fac[4000], mod-2);
    for (ll i=4000-1; i>=0; i--) {
    	inv[i] = inv[i+1] * (i+1) % mod;
    }
    ll N, M;
    cin >> N >> M;
    dp[0][0] = 1;
    for (ll i=1; i<=M; i++) {
    	ll cnt = 2*N / M;
    	if (2*N % M >= i) cnt ++;
    	for (ll k=0; k<=cnt/2; k++) {
    		for (ll j=0; j<=N-k; j++) {
    			dp[i][j+k] += dp[i-1][j] * C(N-j, k) % mod * C(cnt, 2*k) % mod 
    						* fac[2*k] % mod;
    			dp[i][j+k] %= mod;
    		}
    	}
    }
    ll ans = 0;
    for (ll i=0; i<=N; i++) {
    	if (i % 2) {
    		ans -= dp[M][i] * fac[2*N-2*i] % mod;
    	}
    	else {
    		ans += dp[M][i] * fac[2*N-2*i] % mod;
    	}
    }
    cout << ans % mod << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Incorrect 1 ms 604 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Incorrect 1 ms 604 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Incorrect 1 ms 604 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Incorrect 1 ms 604 KB Output isn't correct
13 Halted 0 ms 0 KB -