# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
810437 |
2023-08-06T09:46:06 Z |
winter0101 |
Tents (JOI18_tents) |
C++14 |
|
176 ms |
147120 KB |
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define eb emplace_back
const long long du=1e9+7;
long long f[3001][3001];
long long combi[3001][3001];
long long pw[3001];
long long fact[6001];
long long inv[6001];
long long g[3001][3001];
long long pow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int m,n;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
cin>>m>>n;
pw[0]=1;
for1(i,1,3000)pw[i]=(pw[i-1]*4)%du;
fact[0]=1;
for1(i,1,6000)fact[i]=(fact[i-1]*i)%du;
for1(i,0,6000){
inv[i]=pow(fact[i],du-2,du);
}
combi[0][0]=1;
for1(i,1,3000){
combi[i][0]=1;
for1(j,1,3000){
combi[i][j]=(combi[i-1][j-1]+combi[i-1][j])%du;
}
}
f[0][0]=1;
for1(i,0,m){
for1(j,0,n){
if (!f[i][j])continue;
int t1=j*2+i,t2=i*2+j;
if (t1>m||t2>n){
f[i][j]=0;
continue;
}
if (t1+1<=m&&t2+2<=n){
long long dd=(combi[m-t1][1]*combi[n-t2][2])%du;
f[i+1][j]=(f[i+1][j]+f[i][j]*dd)%du;
}
if (t1+2<=m&&t2+1<=n){
long long dd=(combi[m-t1][2]*combi[n-t2][1])%du;
f[i][j+1]=(f[i][j+1]+f[i][j]*dd)%du;
}
}
}
for1(i,0,m){
for1(j,0,n){
if (!f[i][j])continue;
f[i][j]=(f[i][j]*inv[i+j])%du;
}
}
long long ans=0;
for1(i,0,m){
for1(j,0,n){
if (!f[i][j])continue;
int t1=j*2+i,t2=i*2+j;
int l1=m-t1,l2=n-t2;
/*for1(k,min(l1,l2),min(l1,l2)){
long long dd=(pw[k]*combi[l1][k])%du;
dd=(dd*combi[l2][k])%du;
dd=(dd*fact[k])%du;
ans=(ans+f[i][j]*dd)%du;
}*/
g[t1][t2]=(g[t1][t2]+f[i][j])%du;
}
}
for1(i,0,m){
for1(j,0,n){
if (!g[i][j])continue;
if (i+1<=m){
g[i+1][j]=(g[i+1][j]+g[i][j])%du;
}
if (i+1<=m&&j+1<=n){
g[i+1][j+1]=(g[i+1][j+1]+g[i][j]*4*(n-j))%du;
}
}
}
for1(i,m,m){
for1(j,0,n){
ans=(ans+g[i][j])%du;
}
}
cout<<(ans-1+du)%du;
}
Compilation message
tents.cpp: In function 'int main()':
tents.cpp:89:9: warning: unused variable 'l1' [-Wunused-variable]
89 | int l1=m-t1,l2=n-t2;
| ^~
tents.cpp:89:17: warning: unused variable 'l2' [-Wunused-variable]
89 | int l1=m-t1,l2=n-t2;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70812 KB |
Output is correct |
2 |
Correct |
37 ms |
70836 KB |
Output is correct |
3 |
Correct |
38 ms |
71028 KB |
Output is correct |
4 |
Correct |
38 ms |
71716 KB |
Output is correct |
5 |
Correct |
38 ms |
71412 KB |
Output is correct |
6 |
Correct |
40 ms |
72112 KB |
Output is correct |
7 |
Correct |
39 ms |
71624 KB |
Output is correct |
8 |
Correct |
40 ms |
72156 KB |
Output is correct |
9 |
Correct |
39 ms |
71356 KB |
Output is correct |
10 |
Correct |
40 ms |
72668 KB |
Output is correct |
11 |
Correct |
39 ms |
70896 KB |
Output is correct |
12 |
Correct |
41 ms |
73292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
70812 KB |
Output is correct |
2 |
Correct |
37 ms |
70836 KB |
Output is correct |
3 |
Correct |
38 ms |
71028 KB |
Output is correct |
4 |
Correct |
38 ms |
71716 KB |
Output is correct |
5 |
Correct |
38 ms |
71412 KB |
Output is correct |
6 |
Correct |
40 ms |
72112 KB |
Output is correct |
7 |
Correct |
39 ms |
71624 KB |
Output is correct |
8 |
Correct |
40 ms |
72156 KB |
Output is correct |
9 |
Correct |
39 ms |
71356 KB |
Output is correct |
10 |
Correct |
40 ms |
72668 KB |
Output is correct |
11 |
Correct |
39 ms |
70896 KB |
Output is correct |
12 |
Correct |
41 ms |
73292 KB |
Output is correct |
13 |
Correct |
38 ms |
70848 KB |
Output is correct |
14 |
Correct |
45 ms |
80380 KB |
Output is correct |
15 |
Correct |
129 ms |
128832 KB |
Output is correct |
16 |
Correct |
41 ms |
73244 KB |
Output is correct |
17 |
Correct |
52 ms |
81156 KB |
Output is correct |
18 |
Correct |
63 ms |
88896 KB |
Output is correct |
19 |
Correct |
143 ms |
136532 KB |
Output is correct |
20 |
Correct |
119 ms |
123668 KB |
Output is correct |
21 |
Correct |
85 ms |
104524 KB |
Output is correct |
22 |
Correct |
92 ms |
108616 KB |
Output is correct |
23 |
Correct |
67 ms |
99020 KB |
Output is correct |
24 |
Correct |
176 ms |
147120 KB |
Output is correct |
25 |
Correct |
139 ms |
133572 KB |
Output is correct |
26 |
Correct |
165 ms |
140516 KB |
Output is correct |
27 |
Correct |
168 ms |
144668 KB |
Output is correct |