Submission #314311

# Submission time Handle Problem Language Result Execution time Memory
314311 2020-10-19T16:14:18 Z limabeans Tents (JOI18_tents) C++17
100 / 100
538 ms 71160 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 3001;
const ll mod = 1e9 + 7;

void add(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x += y;
    if (x>=mod) x%=mod;
}

int n,m;
ll dp[maxn][maxn];

ll choose2(ll x) {
    return x*(x-1)/2;
}

ll f(int i, int j) {
    if (i==0 || j==0) return 1;
    ll &res = dp[i][j];
    if (~res) return res;
    res = 0;
    add(res, f(i-1,j));
    add(res, 4ll*j*f(i-1,j-1));
    if (j>=2) add(res, choose2(j)*f(i-1,j-2));
    if (i>=2) add(res, 1ll*j*(i-1)*f(i-2,j-1));

    return res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);


    
    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    ll res = f(n,m);
    res--;
    res%=mod;
    res+=mod;
    res%=mod;
    cout<<res<<endl;    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 70776 KB Output is correct
2 Correct 42 ms 70776 KB Output is correct
3 Correct 42 ms 70776 KB Output is correct
4 Correct 43 ms 70784 KB Output is correct
5 Correct 48 ms 70776 KB Output is correct
6 Correct 43 ms 70816 KB Output is correct
7 Correct 42 ms 70784 KB Output is correct
8 Correct 41 ms 70776 KB Output is correct
9 Correct 41 ms 70776 KB Output is correct
10 Correct 43 ms 70776 KB Output is correct
11 Correct 41 ms 70776 KB Output is correct
12 Correct 47 ms 70892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 70776 KB Output is correct
2 Correct 42 ms 70776 KB Output is correct
3 Correct 42 ms 70776 KB Output is correct
4 Correct 43 ms 70784 KB Output is correct
5 Correct 48 ms 70776 KB Output is correct
6 Correct 43 ms 70816 KB Output is correct
7 Correct 42 ms 70784 KB Output is correct
8 Correct 41 ms 70776 KB Output is correct
9 Correct 41 ms 70776 KB Output is correct
10 Correct 43 ms 70776 KB Output is correct
11 Correct 41 ms 70776 KB Output is correct
12 Correct 47 ms 70892 KB Output is correct
13 Correct 42 ms 70844 KB Output is correct
14 Correct 42 ms 70912 KB Output is correct
15 Correct 329 ms 71160 KB Output is correct
16 Correct 45 ms 70776 KB Output is correct
17 Correct 70 ms 70920 KB Output is correct
18 Correct 104 ms 70904 KB Output is correct
19 Correct 375 ms 71160 KB Output is correct
20 Correct 296 ms 71028 KB Output is correct
21 Correct 188 ms 70904 KB Output is correct
22 Correct 211 ms 71012 KB Output is correct
23 Correct 138 ms 71064 KB Output is correct
24 Correct 538 ms 71160 KB Output is correct
25 Correct 375 ms 71032 KB Output is correct
26 Correct 438 ms 71040 KB Output is correct
27 Correct 497 ms 71032 KB Output is correct