Submission #236878

#TimeUsernameProblemLanguageResultExecution timeMemory
236878nishkarshTents (JOI18_tents)C++14
100 / 100
244 ms70904 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define pii pair<int,int> #define pll pair<ll,ll> #define pcc pair<char,char> #define vi vector <int> #define vl vector <ll> #define sd(x) scanf("%d",&x) #define slld(x) scanf("%lld",&x) #define pd(x) printf("%d",x) #define plld(x) printf("%lld",x) #define pds(x) printf("%d ",x) #define pllds(x) printf("%lld ",x) #define pdn(x) printf("%d\n",x) #define plldn(x) printf("%lld\n",x) #define INF 2e9 #define INFLL 4e18 using namespace std; ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9 ll ans=1; while(exponent){ if(exponent&1)ans=(ans*base)%mod; base=(base*base)%mod; exponent/=2; } return ans; } ll gcd(ll a, ll b){ if(b==0) return a; else return gcd(b,a%b); } const int upperlimit = 3e3+1; const int mod = 1e9+7; ll dp[upperlimit][upperlimit]; int main() { // freopen(".in","r",stdin);freopen(".out","w",stdout); for(int i = 0; i < upperlimit; i++){ dp[i][0]=dp[0][i]=1; } for(int i = 1; i < upperlimit; i++){ dp[i][1]=dp[1][i]=((i*(i-1))/2)+(4*i)+1; } for(int i = 2; i < upperlimit; i++){ for(int j = 2; j < upperlimit; j++){ dp[i][j]=4*dp[i-1][j-1]; ll calc=i-1;calc*=dp[i-2][j-1];calc%=mod; dp[i][j]+=calc;dp[i][j]%=mod; calc=j-1;calc*=dp[i-1][j-2];calc%=mod; dp[i][j]+=calc;dp[i][j]%=mod; calc=i-1;calc*=i-2;calc>>=1;calc*=dp[i-2][j-1];calc%=mod; dp[i][j]+=calc;dp[i][j]%=mod; calc=i-1;calc*=4;calc*=dp[i-1][j-1];calc%=mod; dp[i][j]+=calc;dp[i][j]%=mod; calc=i-1;calc*=j-1;calc*=dp[i-1][j-2];calc%=mod; dp[i][j]+=calc;dp[i][j]%=mod; dp[i][j]+=dp[i][j-1];dp[i][j]%=mod; } } int h,w; sd(h);sd(w); plld(dp[h][w]-1); return 0; }

Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
tents.cpp:64:2: note: in expansion of macro 'sd'
  sd(h);sd(w);
  ^~
tents.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
tents.cpp:64:8: note: in expansion of macro 'sd'
  sd(h);sd(w);
        ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...