Submission #204527

# Submission time Handle Problem Language Result Execution time Memory
204527 2020-02-26T08:41:33 Z Atill83 Tents (JOI18_tents) C++14
100 / 100
391 ms 71420 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
ll comb[10005];
ll dp[3005][3005];
ll do_it(ll satir, ll sutun){
    if(dp[satir][sutun] != -1) return dp[satir][sutun];
    if(sutun < 0 || satir < 0) return 0;
    if(satir <= 0){
        return 1;
    }
    ll ans = 0;
    ans = (ans + comb[sutun]*do_it(satir - 1, sutun - 2)%mod)%mod;
    ans = (ans + sutun*(satir - 1)%mod*do_it(satir - 2, sutun - 1)%mod)%mod;
    ans = (ans + 4*sutun*do_it(satir - 1, sutun - 1)%mod)%mod;
    ans = (ans + do_it(satir - 1, sutun))%mod;
    return dp[satir][sutun] = ans;
}




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

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif
    ll W, H;
    cin>>W>>H;
    memset(dp, -1, sizeof(dp));

    for(int i = 2; i <= 1e4; i++){
        comb[i] = i*(i - 1) / 2;
    }
    cout<< (do_it(H, W) - 1 + mod) % mod;


    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 45 ms 71036 KB Output is correct
2 Correct 44 ms 71160 KB Output is correct
3 Correct 47 ms 71112 KB Output is correct
4 Correct 45 ms 71160 KB Output is correct
5 Correct 47 ms 71032 KB Output is correct
6 Correct 44 ms 71032 KB Output is correct
7 Correct 45 ms 71032 KB Output is correct
8 Correct 45 ms 71160 KB Output is correct
9 Correct 45 ms 71032 KB Output is correct
10 Correct 48 ms 71036 KB Output is correct
11 Correct 44 ms 71164 KB Output is correct
12 Correct 48 ms 71160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 71036 KB Output is correct
2 Correct 44 ms 71160 KB Output is correct
3 Correct 47 ms 71112 KB Output is correct
4 Correct 45 ms 71160 KB Output is correct
5 Correct 47 ms 71032 KB Output is correct
6 Correct 44 ms 71032 KB Output is correct
7 Correct 45 ms 71032 KB Output is correct
8 Correct 45 ms 71160 KB Output is correct
9 Correct 45 ms 71032 KB Output is correct
10 Correct 48 ms 71036 KB Output is correct
11 Correct 44 ms 71164 KB Output is correct
12 Correct 48 ms 71160 KB Output is correct
13 Correct 48 ms 71160 KB Output is correct
14 Correct 45 ms 71032 KB Output is correct
15 Correct 203 ms 71288 KB Output is correct
16 Correct 61 ms 71288 KB Output is correct
17 Correct 93 ms 71160 KB Output is correct
18 Correct 88 ms 71160 KB Output is correct
19 Correct 238 ms 71312 KB Output is correct
20 Correct 204 ms 71288 KB Output is correct
21 Correct 167 ms 71288 KB Output is correct
22 Correct 132 ms 71260 KB Output is correct
23 Correct 57 ms 71160 KB Output is correct
24 Correct 379 ms 71376 KB Output is correct
25 Correct 281 ms 71420 KB Output is correct
26 Correct 332 ms 71416 KB Output is correct
27 Correct 391 ms 71240 KB Output is correct