# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
509735 |
2022-01-14T09:05:41 Z |
hotboy2703 |
NoM (RMI21_nom) |
C++14 |
|
500 ms |
2416 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[maxn + 100][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 ++){
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[i][j] = 0;
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,x-j+k));
dp[i][j] %= MOD;
}
}
}
return dp[m][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 |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
0 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 |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
608 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
676 KB |
Output is correct |
16 |
Correct |
8 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
548 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
608 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
676 KB |
Output is correct |
16 |
Correct |
8 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
548 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
5 ms |
460 KB |
Output is correct |
20 |
Correct |
45 ms |
480 KB |
Output is correct |
21 |
Correct |
47 ms |
756 KB |
Output is correct |
22 |
Correct |
333 ms |
1992 KB |
Output is correct |
23 |
Correct |
116 ms |
488 KB |
Output is correct |
24 |
Correct |
315 ms |
1260 KB |
Output is correct |
25 |
Correct |
301 ms |
1844 KB |
Output is correct |
26 |
Correct |
140 ms |
460 KB |
Output is correct |
27 |
Execution timed out |
533 ms |
2416 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
608 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
676 KB |
Output is correct |
16 |
Correct |
8 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
548 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
5 ms |
460 KB |
Output is correct |
20 |
Correct |
45 ms |
480 KB |
Output is correct |
21 |
Correct |
47 ms |
756 KB |
Output is correct |
22 |
Correct |
333 ms |
1992 KB |
Output is correct |
23 |
Correct |
116 ms |
488 KB |
Output is correct |
24 |
Correct |
315 ms |
1260 KB |
Output is correct |
25 |
Correct |
301 ms |
1844 KB |
Output is correct |
26 |
Correct |
140 ms |
460 KB |
Output is correct |
27 |
Execution timed out |
533 ms |
2416 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
13 ms |
588 KB |
Output is correct |
12 |
Correct |
5 ms |
608 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
6 ms |
460 KB |
Output is correct |
15 |
Correct |
6 ms |
676 KB |
Output is correct |
16 |
Correct |
8 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
548 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
5 ms |
460 KB |
Output is correct |
20 |
Correct |
45 ms |
480 KB |
Output is correct |
21 |
Correct |
47 ms |
756 KB |
Output is correct |
22 |
Correct |
333 ms |
1992 KB |
Output is correct |
23 |
Correct |
116 ms |
488 KB |
Output is correct |
24 |
Correct |
315 ms |
1260 KB |
Output is correct |
25 |
Correct |
301 ms |
1844 KB |
Output is correct |
26 |
Correct |
140 ms |
460 KB |
Output is correct |
27 |
Execution timed out |
533 ms |
2416 KB |
Time limit exceeded |