# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
236874 |
2020-06-03T15:37:10 Z |
anubhavdhar |
Tents (JOI18_tents) |
C++14 |
|
868 ms |
71288 KB |
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define F0R(i,n) for(int i=0;i<(n);++i)
#define F0Re(i,n) for(int i=1;i<=(n);++i)
#define F0Rr(i,a,b) for(ll i=(a);i<(b);++i)
#define F0Rrev(i,n) for(int i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define dbgLine cout<<"Line : "<<__LINE__<<'\n'
#define all(x) (x).begin(),(x).end()
using namespace std;
const short int __PRECISION = 10;
const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 3001;
const ll ROOTN = 320;
const ldd PI = acos(-1);
const ldd EPS = 1e-7;
ll dp[MAXN][MAXN];
#define C(a) ((((a)*(a-1))/2)%MOD)
ll DP(int i, int j)
{
if(i < 0 or j < 0) return 0;
ll& t = dp[i][j];
if(t != -1) return t;
t = 0;
t += 5*DP(i - 1, j - 1);
t += ((i-1)*DP(i-2, j-1))%MOD;
t += ((j-1)*DP(i-1, j-2))%MOD;
t += ((j-1)*((4*DP(i-1,j-2)+(i-1)*DP(i-2,j-2))%MOD))%MOD;
t += ((i-1)*((4*DP(i-2,j-1)+(j-1)*DP(i-2,j-2))%MOD))%MOD;
t += (DP(i-1,j-3)*C(j-1))%MOD;
t += (DP(i-3,j-1)*C(i-1))%MOD;
t += (((C(i-1)*(j-1))%MOD)*((4*DP(i-3,j-2)+(i-3)*DP(i-4,j-2))%MOD))%MOD;
t += (((C(j-1)*(i-1))%MOD)*((4*DP(i-2,j-3)+(j-3)*DP(i-2,j-4))%MOD))%MOD;
t += (((C(i-1)*C(j-1))%MOD)*DP(i-3,j-3))%MOD;
t += (((16*DP(i-2,j-2) + 4*(j-2)*DP(i-2,j-3) + 4*(i-2)*DP(i-3,j-2) + (i-2)*(j-2)*DP(i-3, j-3))%MOD) * ((i-1)*(j-1)))%MOD;
t %= MOD;
assert(t == dp[i][j]);
return t;
}
int main()
{
/*
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
*/
int i, j;
FOR(i, MAXN)
FOR(j, MAXN)
dp[i][j] = (i == 0 || j == 0) ? 1 : -1;
cin>>i>>j;
cout<<(DP(i, j) + MOD - 1) % MOD << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
70776 KB |
Output is correct |
2 |
Correct |
71 ms |
70776 KB |
Output is correct |
3 |
Correct |
54 ms |
70776 KB |
Output is correct |
4 |
Correct |
59 ms |
70776 KB |
Output is correct |
5 |
Correct |
43 ms |
70776 KB |
Output is correct |
6 |
Correct |
43 ms |
70776 KB |
Output is correct |
7 |
Correct |
58 ms |
70776 KB |
Output is correct |
8 |
Correct |
41 ms |
70892 KB |
Output is correct |
9 |
Correct |
60 ms |
70776 KB |
Output is correct |
10 |
Correct |
43 ms |
70912 KB |
Output is correct |
11 |
Correct |
41 ms |
70780 KB |
Output is correct |
12 |
Correct |
49 ms |
70776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
70776 KB |
Output is correct |
2 |
Correct |
71 ms |
70776 KB |
Output is correct |
3 |
Correct |
54 ms |
70776 KB |
Output is correct |
4 |
Correct |
59 ms |
70776 KB |
Output is correct |
5 |
Correct |
43 ms |
70776 KB |
Output is correct |
6 |
Correct |
43 ms |
70776 KB |
Output is correct |
7 |
Correct |
58 ms |
70776 KB |
Output is correct |
8 |
Correct |
41 ms |
70892 KB |
Output is correct |
9 |
Correct |
60 ms |
70776 KB |
Output is correct |
10 |
Correct |
43 ms |
70912 KB |
Output is correct |
11 |
Correct |
41 ms |
70780 KB |
Output is correct |
12 |
Correct |
49 ms |
70776 KB |
Output is correct |
13 |
Correct |
59 ms |
70776 KB |
Output is correct |
14 |
Correct |
43 ms |
70776 KB |
Output is correct |
15 |
Correct |
621 ms |
71116 KB |
Output is correct |
16 |
Correct |
52 ms |
70776 KB |
Output is correct |
17 |
Correct |
112 ms |
70904 KB |
Output is correct |
18 |
Correct |
163 ms |
70904 KB |
Output is correct |
19 |
Correct |
669 ms |
71160 KB |
Output is correct |
20 |
Correct |
510 ms |
71160 KB |
Output is correct |
21 |
Correct |
333 ms |
71032 KB |
Output is correct |
22 |
Correct |
335 ms |
71160 KB |
Output is correct |
23 |
Correct |
108 ms |
70908 KB |
Output is correct |
24 |
Correct |
868 ms |
71288 KB |
Output is correct |
25 |
Correct |
653 ms |
71180 KB |
Output is correct |
26 |
Correct |
723 ms |
71288 KB |
Output is correct |
27 |
Correct |
851 ms |
71288 KB |
Output is correct |