Submission #509639

# Submission time Handle Problem Language Result Execution time Memory
509639 2022-01-14T07:44:31 Z socpite NoM (RMI21_nom) C++14
100 / 100
327 ms 251780 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

const int maxn = 4e3+5;
const int mod = 1e9+7;

typedef long long ll;

int n, m;

ll dp[maxn][maxn][2];
int pos[maxn];

ll f(int i, int j, int k){
    if(i == n)return k==0;
    else if(dp[i][j][k] != -1)return dp[i][j][k];
    else{
        int gap = pos[i]-i;
        dp[i][j][k] = 0;
        int p2 = n/2 - j - (i-j)/2;
        if(p2)dp[i][j][k]+=f(i+1, j+1, k)*p2*2%mod;
        if(j)dp[i][j][k]+=f(i+1, j-1, k)*j%mod;
        if(gap >= 2)dp[i][j][k]+=f(i+2, j, k^1)*p2*2%mod*(gap-1)%mod;
        dp[i][j][k]%=mod;
        //cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
        return dp[i][j][k];
    }
}

int main(){
    memset(dp, -1, sizeof(dp));
    cin >> n >> m;
    n*=2;
    int crr = 0;
    for(int i = 0; i < m-n%m; i++){
        int st = crr+n/m;
        for(int j = 0; j < n/m; j++)pos[crr++]=st;
    }
    for(int i = 0; i < n%m; i++){
        int st = crr+n/m+1;
        for(int j = 0; j < n/m+1; j++)pos[crr++]=st;
    }
    ll ans = f(0, 0, 0)- f(0, 0, 1);
    if(ans < 0)ans+=mod;
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 90 ms 251392 KB Output is correct
2 Correct 87 ms 251328 KB Output is correct
3 Correct 90 ms 251308 KB Output is correct
4 Correct 97 ms 251332 KB Output is correct
5 Correct 91 ms 251288 KB Output is correct
6 Correct 89 ms 251360 KB Output is correct
7 Correct 104 ms 251548 KB Output is correct
8 Correct 96 ms 251312 KB Output is correct
9 Correct 99 ms 251288 KB Output is correct
10 Correct 87 ms 251388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 251392 KB Output is correct
2 Correct 87 ms 251328 KB Output is correct
3 Correct 90 ms 251308 KB Output is correct
4 Correct 97 ms 251332 KB Output is correct
5 Correct 91 ms 251288 KB Output is correct
6 Correct 89 ms 251360 KB Output is correct
7 Correct 104 ms 251548 KB Output is correct
8 Correct 96 ms 251312 KB Output is correct
9 Correct 99 ms 251288 KB Output is correct
10 Correct 87 ms 251388 KB Output is correct
11 Correct 90 ms 251424 KB Output is correct
12 Correct 90 ms 251352 KB Output is correct
13 Correct 101 ms 251332 KB Output is correct
14 Correct 93 ms 251356 KB Output is correct
15 Correct 94 ms 251300 KB Output is correct
16 Correct 91 ms 251400 KB Output is correct
17 Correct 88 ms 251304 KB Output is correct
18 Correct 89 ms 251292 KB Output is correct
19 Correct 92 ms 251332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 251392 KB Output is correct
2 Correct 87 ms 251328 KB Output is correct
3 Correct 90 ms 251308 KB Output is correct
4 Correct 97 ms 251332 KB Output is correct
5 Correct 91 ms 251288 KB Output is correct
6 Correct 89 ms 251360 KB Output is correct
7 Correct 104 ms 251548 KB Output is correct
8 Correct 96 ms 251312 KB Output is correct
9 Correct 99 ms 251288 KB Output is correct
10 Correct 87 ms 251388 KB Output is correct
11 Correct 90 ms 251424 KB Output is correct
12 Correct 90 ms 251352 KB Output is correct
13 Correct 101 ms 251332 KB Output is correct
14 Correct 93 ms 251356 KB Output is correct
15 Correct 94 ms 251300 KB Output is correct
16 Correct 91 ms 251400 KB Output is correct
17 Correct 88 ms 251304 KB Output is correct
18 Correct 89 ms 251292 KB Output is correct
19 Correct 92 ms 251332 KB Output is correct
20 Correct 91 ms 251304 KB Output is correct
21 Correct 107 ms 251348 KB Output is correct
22 Correct 101 ms 251384 KB Output is correct
23 Correct 108 ms 251404 KB Output is correct
24 Correct 100 ms 251492 KB Output is correct
25 Correct 95 ms 251432 KB Output is correct
26 Correct 96 ms 251332 KB Output is correct
27 Correct 126 ms 251356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 251392 KB Output is correct
2 Correct 87 ms 251328 KB Output is correct
3 Correct 90 ms 251308 KB Output is correct
4 Correct 97 ms 251332 KB Output is correct
5 Correct 91 ms 251288 KB Output is correct
6 Correct 89 ms 251360 KB Output is correct
7 Correct 104 ms 251548 KB Output is correct
8 Correct 96 ms 251312 KB Output is correct
9 Correct 99 ms 251288 KB Output is correct
10 Correct 87 ms 251388 KB Output is correct
11 Correct 90 ms 251424 KB Output is correct
12 Correct 90 ms 251352 KB Output is correct
13 Correct 101 ms 251332 KB Output is correct
14 Correct 93 ms 251356 KB Output is correct
15 Correct 94 ms 251300 KB Output is correct
16 Correct 91 ms 251400 KB Output is correct
17 Correct 88 ms 251304 KB Output is correct
18 Correct 89 ms 251292 KB Output is correct
19 Correct 92 ms 251332 KB Output is correct
20 Correct 91 ms 251304 KB Output is correct
21 Correct 107 ms 251348 KB Output is correct
22 Correct 101 ms 251384 KB Output is correct
23 Correct 108 ms 251404 KB Output is correct
24 Correct 100 ms 251492 KB Output is correct
25 Correct 95 ms 251432 KB Output is correct
26 Correct 96 ms 251332 KB Output is correct
27 Correct 126 ms 251356 KB Output is correct
28 Correct 121 ms 251412 KB Output is correct
29 Correct 135 ms 251500 KB Output is correct
30 Correct 113 ms 251412 KB Output is correct
31 Correct 110 ms 251448 KB Output is correct
32 Correct 110 ms 251488 KB Output is correct
33 Correct 115 ms 251520 KB Output is correct
34 Correct 132 ms 251588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 251392 KB Output is correct
2 Correct 87 ms 251328 KB Output is correct
3 Correct 90 ms 251308 KB Output is correct
4 Correct 97 ms 251332 KB Output is correct
5 Correct 91 ms 251288 KB Output is correct
6 Correct 89 ms 251360 KB Output is correct
7 Correct 104 ms 251548 KB Output is correct
8 Correct 96 ms 251312 KB Output is correct
9 Correct 99 ms 251288 KB Output is correct
10 Correct 87 ms 251388 KB Output is correct
11 Correct 90 ms 251424 KB Output is correct
12 Correct 90 ms 251352 KB Output is correct
13 Correct 101 ms 251332 KB Output is correct
14 Correct 93 ms 251356 KB Output is correct
15 Correct 94 ms 251300 KB Output is correct
16 Correct 91 ms 251400 KB Output is correct
17 Correct 88 ms 251304 KB Output is correct
18 Correct 89 ms 251292 KB Output is correct
19 Correct 92 ms 251332 KB Output is correct
20 Correct 91 ms 251304 KB Output is correct
21 Correct 107 ms 251348 KB Output is correct
22 Correct 101 ms 251384 KB Output is correct
23 Correct 108 ms 251404 KB Output is correct
24 Correct 100 ms 251492 KB Output is correct
25 Correct 95 ms 251432 KB Output is correct
26 Correct 96 ms 251332 KB Output is correct
27 Correct 126 ms 251356 KB Output is correct
28 Correct 121 ms 251412 KB Output is correct
29 Correct 135 ms 251500 KB Output is correct
30 Correct 113 ms 251412 KB Output is correct
31 Correct 110 ms 251448 KB Output is correct
32 Correct 110 ms 251488 KB Output is correct
33 Correct 115 ms 251520 KB Output is correct
34 Correct 132 ms 251588 KB Output is correct
35 Correct 245 ms 251700 KB Output is correct
36 Correct 261 ms 251724 KB Output is correct
37 Correct 271 ms 251616 KB Output is correct
38 Correct 241 ms 251708 KB Output is correct
39 Correct 232 ms 251780 KB Output is correct
40 Correct 327 ms 251780 KB Output is correct