# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
574380 |
2022-06-08T12:59:28 Z |
urosk |
NoM (RMI21_nom) |
C++14 |
|
500 ms |
3484 KB |
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
#define mod 1000000007
#define maxn 4005
ll n,m;
ll fact[maxn];
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
ll mul(vector<ll> v){
if(sz(v)==1) return v[0];
if(sz(v)==0) return 1LL;
ll ans = 1;
for(ll x : v) ans = mul(ans,x);
return ans;
}
ll po(ll x,ll y){
if(y==0) return 1LL;
if(y==1) return x;
ll ans = po(x,y/2);
ans = mul(ans,ans);
if(y&1) ans = mul(ans,x);
return ans;
}
ll inv(ll x){return po(x,mod-2);}
ll ch(ll x,ll y){
if(x<y) return 0;
return mul({fact[x],inv(fact[x-y]),inv(fact[y])});
}
ll f(ll i){
if((i&1)) return 1;
return -1;
}
ll dp[maxn][maxn];
ll rem[maxn];
int main(){
daj_mi_malo_vremena
fact[0] = 1;
for(ll i = 1;i<=maxn-1;i++) fact[i] = mul(fact[i-1],i);
cin >> n >> m;
for(ll i = 1;i<=2*n;i++) rem[i%m]++;
rem[m] = rem[0];
dp[0][0] = 1;
for(ll i = 1;i<=m;i++){
ll ni = rem[i];
for(ll j = 0;j<=n;j++){
for(ll k = 0;2*k<=ni&&j>=k;k++){
dp[i][j] = add(dp[i][j],mul({dp[i-1][j-k],ch(ni,k),ch(ni-k,k),fact[k]}));
}
}
}
ll ans = 0;
for(ll i = 1;i<=n;i++) ans = add(ans,mul({ch(n,i),fact[2*n-2*i],dp[m][i],fact[i],f(i)}));
ans = add(fact[2*n],-ans);
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
14 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
488 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
464 KB |
Output is correct |
15 |
Correct |
9 ms |
608 KB |
Output is correct |
16 |
Correct |
8 ms |
412 KB |
Output is correct |
17 |
Correct |
7 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
580 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
14 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
488 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
464 KB |
Output is correct |
15 |
Correct |
9 ms |
608 KB |
Output is correct |
16 |
Correct |
8 ms |
412 KB |
Output is correct |
17 |
Correct |
7 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
580 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
20 |
Correct |
29 ms |
508 KB |
Output is correct |
21 |
Correct |
34 ms |
668 KB |
Output is correct |
22 |
Correct |
126 ms |
1856 KB |
Output is correct |
23 |
Correct |
53 ms |
416 KB |
Output is correct |
24 |
Correct |
117 ms |
1208 KB |
Output is correct |
25 |
Correct |
117 ms |
1760 KB |
Output is correct |
26 |
Correct |
72 ms |
496 KB |
Output is correct |
27 |
Correct |
167 ms |
2204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
14 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
488 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
464 KB |
Output is correct |
15 |
Correct |
9 ms |
608 KB |
Output is correct |
16 |
Correct |
8 ms |
412 KB |
Output is correct |
17 |
Correct |
7 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
580 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
20 |
Correct |
29 ms |
508 KB |
Output is correct |
21 |
Correct |
34 ms |
668 KB |
Output is correct |
22 |
Correct |
126 ms |
1856 KB |
Output is correct |
23 |
Correct |
53 ms |
416 KB |
Output is correct |
24 |
Correct |
117 ms |
1208 KB |
Output is correct |
25 |
Correct |
117 ms |
1760 KB |
Output is correct |
26 |
Correct |
72 ms |
496 KB |
Output is correct |
27 |
Correct |
167 ms |
2204 KB |
Output is correct |
28 |
Correct |
359 ms |
448 KB |
Output is correct |
29 |
Execution timed out |
582 ms |
3484 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
1 ms |
356 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
356 KB |
Output is correct |
11 |
Correct |
14 ms |
596 KB |
Output is correct |
12 |
Correct |
8 ms |
488 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
464 KB |
Output is correct |
15 |
Correct |
9 ms |
608 KB |
Output is correct |
16 |
Correct |
8 ms |
412 KB |
Output is correct |
17 |
Correct |
7 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
580 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
20 |
Correct |
29 ms |
508 KB |
Output is correct |
21 |
Correct |
34 ms |
668 KB |
Output is correct |
22 |
Correct |
126 ms |
1856 KB |
Output is correct |
23 |
Correct |
53 ms |
416 KB |
Output is correct |
24 |
Correct |
117 ms |
1208 KB |
Output is correct |
25 |
Correct |
117 ms |
1760 KB |
Output is correct |
26 |
Correct |
72 ms |
496 KB |
Output is correct |
27 |
Correct |
167 ms |
2204 KB |
Output is correct |
28 |
Correct |
359 ms |
448 KB |
Output is correct |
29 |
Execution timed out |
582 ms |
3484 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |