#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
//#define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
#define mod 1000000007
int h,w;
ll dp[2][3005][3005];
int main(){
sf("%d%d",&h,&w);
if(h>w)swap(h,w);
int t=0;
for(int i=0;i<=h;++i){
for(int j=0;j<=h;++j)dp[1-t][i][j]=1;
}
for(int c=w;c>=1;--c){
for(int f=0;f<=h;++f){
for(int u=0;u+f<=h;++u){
if(c!=w||f!=h)dp[t][f][u]=dp[1-t][f][u];
if(f>=2)dp[t][f][u]+=dp[1-t][f-2][u]*f*(f-1)/2,dp[t][f][u]%=mod;
if(u>=1)dp[t][f][u]+=dp[1-t][f][u-1]*u,dp[t][f][u]%=mod;
if(f>0)dp[t][f][u]+=3*f*dp[1-t][f-1][u]+f*dp[1-t][f-1][u+1],dp[t][f][u]%=mod;
}
}
//pf("%lld %lld\n",dp[t][1][0],dp[t][0][1]);
t=1-t;
}
pf("%lld\n",dp[1-t][h][0]);
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:47:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | sf("%d%d",&h,&w);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
8 ms |
844 KB |
Output is correct |
6 |
Correct |
13 ms |
1108 KB |
Output is correct |
7 |
Correct |
13 ms |
1100 KB |
Output is correct |
8 |
Correct |
7 ms |
828 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
44 ms |
1612 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
178 ms |
3788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
8 ms |
844 KB |
Output is correct |
6 |
Correct |
13 ms |
1108 KB |
Output is correct |
7 |
Correct |
13 ms |
1100 KB |
Output is correct |
8 |
Correct |
7 ms |
828 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
44 ms |
1612 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
178 ms |
3788 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Execution timed out |
2081 ms |
64476 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |