Submission #1034011

# Submission time Handle Problem Language Result Execution time Memory
1034011 2024-07-25T08:42:03 Z vjudge1 Tents (JOI18_tents) C++17
100 / 100
290 ms 139604 KB
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) begin(v), end(v)
#define pi pair<int, int>
#define vi vector<int>
using namespace std;
const ll mod=1e9+7, maxn = 3e3+3;
ll n, m, nn, mm, dp[maxn][maxn], dp2[maxn][maxn];
bool c[maxn][maxn], c2[maxn][maxn];
 
ll solve2(ll n,ll m){
    if(m==0) return 1;
    if(c2[n][m]) return dp2[n][m];
    c2[n][m]=true;

    dp2[n][m] = solve2(n,m-1);
    if(n>=1)dp2[n][m] += solve2(n-1,m-1)*n*4;
    if(n>=2)dp2[n][m] += solve2(n-2,m-1)*n*(n-1)/2;

    return dp2[n][m] = dp2[n][m]%mod;
}
 
ll solve(ll n,ll m){
    if(n==0) return solve2(nn-(mm-m)/2,m);
    if(c[n][m]) return dp[n][m];
    c[n][m]=true;

    dp[n][m] = solve(n-1,m);
    if(m>=2) dp[n][m] += solve(n-1,m-2)*m*(m-1)/2;

    return dp[n][m] = dp[n][m]%mod;    
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    nn=n, mm=m;
    cout << solve(n,m)-1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 1880 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 2 ms 3160 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 3 ms 4856 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 4 ms 5572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 1880 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 2 ms 3160 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 3 ms 4856 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 4 ms 5572 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 6 ms 16732 KB Output is correct
15 Correct 184 ms 107140 KB Output is correct
16 Correct 9 ms 8540 KB Output is correct
17 Correct 37 ms 24116 KB Output is correct
18 Correct 48 ms 35664 KB Output is correct
19 Correct 210 ms 117076 KB Output is correct
20 Correct 172 ms 96596 KB Output is correct
21 Correct 115 ms 64596 KB Output is correct
22 Correct 106 ms 71248 KB Output is correct
23 Correct 39 ms 48468 KB Output is correct
24 Correct 290 ms 139604 KB Output is correct
25 Correct 220 ms 115792 KB Output is correct
26 Correct 261 ms 127056 KB Output is correct
27 Correct 272 ms 135504 KB Output is correct