# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
236878 |
2020-06-03T15:46:58 Z |
nishkarsh |
Tents (JOI18_tents) |
C++14 |
|
244 ms |
70904 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
228 ms |
70904 KB |
Output is correct |
2 |
Correct |
230 ms |
70788 KB |
Output is correct |
3 |
Correct |
234 ms |
70740 KB |
Output is correct |
4 |
Correct |
223 ms |
70776 KB |
Output is correct |
5 |
Correct |
236 ms |
70776 KB |
Output is correct |
6 |
Correct |
222 ms |
70776 KB |
Output is correct |
7 |
Correct |
222 ms |
70904 KB |
Output is correct |
8 |
Correct |
233 ms |
70776 KB |
Output is correct |
9 |
Correct |
218 ms |
70776 KB |
Output is correct |
10 |
Correct |
222 ms |
70776 KB |
Output is correct |
11 |
Correct |
217 ms |
70776 KB |
Output is correct |
12 |
Correct |
218 ms |
70776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
70904 KB |
Output is correct |
2 |
Correct |
230 ms |
70788 KB |
Output is correct |
3 |
Correct |
234 ms |
70740 KB |
Output is correct |
4 |
Correct |
223 ms |
70776 KB |
Output is correct |
5 |
Correct |
236 ms |
70776 KB |
Output is correct |
6 |
Correct |
222 ms |
70776 KB |
Output is correct |
7 |
Correct |
222 ms |
70904 KB |
Output is correct |
8 |
Correct |
233 ms |
70776 KB |
Output is correct |
9 |
Correct |
218 ms |
70776 KB |
Output is correct |
10 |
Correct |
222 ms |
70776 KB |
Output is correct |
11 |
Correct |
217 ms |
70776 KB |
Output is correct |
12 |
Correct |
218 ms |
70776 KB |
Output is correct |
13 |
Correct |
228 ms |
70904 KB |
Output is correct |
14 |
Correct |
229 ms |
70776 KB |
Output is correct |
15 |
Correct |
218 ms |
70776 KB |
Output is correct |
16 |
Correct |
217 ms |
70776 KB |
Output is correct |
17 |
Correct |
224 ms |
70776 KB |
Output is correct |
18 |
Correct |
223 ms |
70776 KB |
Output is correct |
19 |
Correct |
222 ms |
70780 KB |
Output is correct |
20 |
Correct |
220 ms |
70776 KB |
Output is correct |
21 |
Correct |
230 ms |
70776 KB |
Output is correct |
22 |
Correct |
244 ms |
70776 KB |
Output is correct |
23 |
Correct |
222 ms |
70776 KB |
Output is correct |
24 |
Correct |
216 ms |
70780 KB |
Output is correct |
25 |
Correct |
223 ms |
70776 KB |
Output is correct |
26 |
Correct |
216 ms |
70776 KB |
Output is correct |
27 |
Correct |
225 ms |
70776 KB |
Output is correct |