# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
509626 |
2022-01-14T07:35:49 Z |
minhcool |
NoM (RMI21_nom) |
C++17 |
|
137 ms |
23088 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 2005;
const int oo = 1e18 + 7, mod = 1e9 + 7;
int n, m, dp[N][N], pw2[N << 2];
int fac[N << 2], inv[N << 2];
int binpw(int base, int pw){
int ans = 1;
while(pw){
if(pw & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
pw >>= 1;
}
return ans;
}
void prep(){
fac[0] = 1;
for(int i = 1; i <= 8000; i++) fac[i] = (fac[i - 1] * i) % mod;
for(int i = 0; i <= 8000; i++) inv[i] = binpw(fac[i], mod - 2);
pw2[0] = 1;
for(int i = 1; i <= 8000; i++) pw2[i] = (pw2[i - 1] * 2) % mod;
}
int c(int n, int k){
if(k < 0 || n < k) return 0;
int temp = (fac[n] * inv[k]) % mod;
return (temp * inv[n - k]) % mod;
}
void add(int &a, int b){
a = (a + b) % mod;
}
void process(){
prep();
cin >> n >> m;
dp[0][n] = 1;
int tol = 0;
for(int i = 1; i <= m; i++){
int mx = (2 * n) / m;
if(((2 * n) % m) >= i) mx++;
tol += mx;
for(int two = 0; two <= n; two++){
int one = (n - two) * 2 - tol;
if(one < 0) break;
for(int two2 = two; two2 <= min(n, two + mx); two2++){
int one2 = (mx - two2 + two);
int temp = c(two2, two2 - two) * c(one + one2 - (two2 - two), one2);
temp %= mod;
temp = (temp * fac[mx]) % mod;
//cout << temp << "\n";
temp = (temp * pw2[two2 - two]) % mod;
//cout << two2 << " " << temp << "\n";
add(dp[i][two], temp * dp[i - 1][two2]);
}
//cout << i << " " << two << " " << dp[i][two] << "\n";
}
}
cout << dp[m][0] << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
process();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
716 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
716 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
844 KB |
Output is correct |
22 |
Correct |
4 ms |
1660 KB |
Output is correct |
23 |
Correct |
3 ms |
588 KB |
Output is correct |
24 |
Correct |
4 ms |
1140 KB |
Output is correct |
25 |
Correct |
5 ms |
1740 KB |
Output is correct |
26 |
Correct |
3 ms |
476 KB |
Output is correct |
27 |
Correct |
5 ms |
1964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
716 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
844 KB |
Output is correct |
22 |
Correct |
4 ms |
1660 KB |
Output is correct |
23 |
Correct |
3 ms |
588 KB |
Output is correct |
24 |
Correct |
4 ms |
1140 KB |
Output is correct |
25 |
Correct |
5 ms |
1740 KB |
Output is correct |
26 |
Correct |
3 ms |
476 KB |
Output is correct |
27 |
Correct |
5 ms |
1964 KB |
Output is correct |
28 |
Correct |
9 ms |
588 KB |
Output is correct |
29 |
Correct |
14 ms |
2636 KB |
Output is correct |
30 |
Correct |
16 ms |
4168 KB |
Output is correct |
31 |
Correct |
10 ms |
524 KB |
Output is correct |
32 |
Correct |
17 ms |
2720 KB |
Output is correct |
33 |
Correct |
18 ms |
4656 KB |
Output is correct |
34 |
Correct |
30 ms |
7236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
2 ms |
716 KB |
Output is correct |
12 |
Correct |
2 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
588 KB |
Output is correct |
15 |
Correct |
2 ms |
716 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
2 ms |
588 KB |
Output is correct |
18 |
Correct |
2 ms |
716 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
588 KB |
Output is correct |
21 |
Correct |
2 ms |
844 KB |
Output is correct |
22 |
Correct |
4 ms |
1660 KB |
Output is correct |
23 |
Correct |
3 ms |
588 KB |
Output is correct |
24 |
Correct |
4 ms |
1140 KB |
Output is correct |
25 |
Correct |
5 ms |
1740 KB |
Output is correct |
26 |
Correct |
3 ms |
476 KB |
Output is correct |
27 |
Correct |
5 ms |
1964 KB |
Output is correct |
28 |
Correct |
9 ms |
588 KB |
Output is correct |
29 |
Correct |
14 ms |
2636 KB |
Output is correct |
30 |
Correct |
16 ms |
4168 KB |
Output is correct |
31 |
Correct |
10 ms |
524 KB |
Output is correct |
32 |
Correct |
17 ms |
2720 KB |
Output is correct |
33 |
Correct |
18 ms |
4656 KB |
Output is correct |
34 |
Correct |
30 ms |
7236 KB |
Output is correct |
35 |
Correct |
47 ms |
592 KB |
Output is correct |
36 |
Correct |
107 ms |
18212 KB |
Output is correct |
37 |
Correct |
46 ms |
568 KB |
Output is correct |
38 |
Correct |
77 ms |
8960 KB |
Output is correct |
39 |
Correct |
87 ms |
15280 KB |
Output is correct |
40 |
Correct |
137 ms |
23088 KB |
Output is correct |