# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
703376 |
2023-02-27T07:49:35 Z |
Nursik |
NoM (RMI21_nom) |
C++14 |
|
68 ms |
27972 KB |
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <random>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
const ll maxn = 2e3 + 10, maxm = 1e7 + 1;
const ll mod = 1e9 + 7, cmod = 998244353, inf = 1e9, blcok = 400, p2 = 31;
const ld eps = 1e-9;
int is[maxn];
int fact[maxn * 2], rfact[maxn * 2];
int c[maxn][maxn];
int dp[maxn][maxn];
int bp(ll a, ll n){
ll res = 1;
while (n > 0){
if (n & 1)
res *= a;
a *= a, n >>= 1;
res %= mod, a %= mod;
}
return res;
}
inline void add(int& x, int y){
x += y;
if (x >= mod)
x -= mod;
x %= mod;
}
int n, m;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
// freopen("paths.in", "r", stdin);
// freopen("paths.out", "w", stdout);
cin >> n >> m;
fact[0] = 1;
rfact[0] = 1;
for (int i = 1; i <= n * 2; ++i){
fact[i] = fact[i - 1] * 1ll * i % mod;
int z = i % m + 1;
is[z] += 1;
rfact[i] = bp(fact[i], mod - 2);
}
for (int i = 0; i <= n; ++i){
c[i][0] = 1;
c[i][i] = 1;
for (int j = 1; j < i; ++j){
int x = c[i - 1][j], y = c[i - 1][j - 1];
add(c[i][j], c[i - 1][j]);
add(c[i][j], c[i - 1][j - 1]);
}
}
dp[0][0] = 1;
for (int i = 1; i <= m; ++i){
for (int j = 0; j <= n; ++j){
if (dp[i - 1][j] > 0){
for (int k = 0; k * 2 <= is[i]; ++k){
if (j + k <= n){
int x = (dp[i - 1][j] * 1ll * c[j + k][k] % mod * fact[is[i]] % mod * rfact[is[i] - 2 * k] % mod);
add(dp[i][j + k], x);
}
else{
break;
}
}
}
else{
break;
}
}
}
ll ans = fact[2 * n];
int cur = 1;
//cout << ans << '\n';
for (int i = 1; i <= n; ++i){
ll del = cur * c[n][i] % mod * fact[2 * n - 2 * i] % mod * dp[m][i] % mod;
cur *= -1;
// cout << c[n][i] << " " << fact[2 * n - 2 * i] << " " << dp[m][i] << '\n';
ans = (ans - del + mod) % mod;
}
cout << ans;
}
/*
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:84:17: warning: unused variable 'x' [-Wunused-variable]
84 | int x = c[i - 1][j], y = c[i - 1][j - 1];
| ^
Main.cpp:84:34: warning: unused variable 'y' [-Wunused-variable]
84 | int x = c[i - 1][j], y = c[i - 1][j - 1];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
3 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
1476 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
1492 KB |
Output is correct |
27 |
Correct |
3 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
3 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
1476 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
1492 KB |
Output is correct |
27 |
Correct |
3 ms |
3028 KB |
Output is correct |
28 |
Correct |
6 ms |
3668 KB |
Output is correct |
29 |
Correct |
8 ms |
5588 KB |
Output is correct |
30 |
Correct |
9 ms |
6740 KB |
Output is correct |
31 |
Correct |
6 ms |
3668 KB |
Output is correct |
32 |
Correct |
8 ms |
5844 KB |
Output is correct |
33 |
Correct |
9 ms |
7612 KB |
Output is correct |
34 |
Correct |
15 ms |
10708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
840 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
852 KB |
Output is correct |
16 |
Correct |
1 ms |
724 KB |
Output is correct |
17 |
Correct |
1 ms |
724 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
3 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
1476 KB |
Output is correct |
24 |
Correct |
2 ms |
2260 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
1492 KB |
Output is correct |
27 |
Correct |
3 ms |
3028 KB |
Output is correct |
28 |
Correct |
6 ms |
3668 KB |
Output is correct |
29 |
Correct |
8 ms |
5588 KB |
Output is correct |
30 |
Correct |
9 ms |
6740 KB |
Output is correct |
31 |
Correct |
6 ms |
3668 KB |
Output is correct |
32 |
Correct |
8 ms |
5844 KB |
Output is correct |
33 |
Correct |
9 ms |
7612 KB |
Output is correct |
34 |
Correct |
15 ms |
10708 KB |
Output is correct |
35 |
Correct |
24 ms |
11300 KB |
Output is correct |
36 |
Correct |
50 ms |
23748 KB |
Output is correct |
37 |
Correct |
23 ms |
11108 KB |
Output is correct |
38 |
Correct |
35 ms |
16940 KB |
Output is correct |
39 |
Correct |
39 ms |
20684 KB |
Output is correct |
40 |
Correct |
68 ms |
27972 KB |
Output is correct |