# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
421369 | juggernaut | Tents (JOI18_tents) | C++17 | 463 ms | 70760 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
typedef long long ll;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef IOI2021SG
#define printl(args...)printf(args)
#else
#define printl(args...)((void)0)
#endif
ll dp[3005][3005];
ll mod=1e9+7;
inline ll add(ll a,ll b){
return (a+b)%mod;
}
inline ll mult(ll a,ll b){
return (a*b)%mod;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
if(n>m)swap(n,m);
for(int i=0;i<=n;i++)dp[i][0]=1;
for(int i=0;i<=m;i++)dp[0][i]=1;
for(int i=1;i<=n;i++)dp[i][1]=4*i+i*(i-1)/2+1;
for(int i=1;i<=m;i++)dp[1][i]=4*i+i*(i-1)/2+1;
for(int i=2;i<=n;i++)
for(int j=2;j<=m;j++){
dp[i][j]=add(dp[i][j],dp[i-1][j]);
dp[i][j]=add(dp[i][j],mult(4*j,dp[i-1][j-1]));
dp[i][j]=add(dp[i][j],mult(dp[i-1][j-2],j*(j-1)/2));
dp[i][j]=add(dp[i][j],mult(dp[i-2][j-1],j*(i-1)));
}
ll ans=dp[n][m];
if(ans==0)ans=mod-1;
else ans--;
printf("%lld",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |