Submission #798329

# Submission time Handle Problem Language Result Execution time Memory
798329 2023-07-30T15:25:00 Z vjudge1 Tents (JOI18_tents) C++17
100 / 100
95 ms 70912 KB

#include <bits/stdc++.h>


using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"

const int N = 3e3 + 9 , mod = 1e9 + 7;
ll  d[N] = {} , a[N] = {}, dp[N][N] = {}, b[N] , c[N];

void add(ll &x , ll y){
    x += y;
    if(x >= mod)
        x %= mod;
    if(x < 0)
        x += mod;
}

void solve(){
    ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
    cin>>n>>m;
    for(i = 1; i <= n; i++)
        for(j = 1; j <= m; j++){
        if(i == 1) add(dp[i][j] , 1);
        else  add(dp[i][j] , dp[i - 1][j]);
        if(i > 1 && j > 1)
            add(dp[i][j] , dp[i - 1][j - 1] * 4 * j);
        else
            add(dp[i][j] , 4 * j);
        if(i >= 2 && i - 2 == 0 || j - 1 == 0) add(dp[i][j] , j * (i - 1));
        else if(i >= 2) add(dp[i][j] , (j * (i - 1)) * dp[i - 2][j - 1]);
        if(j >= 2 && j - 2 == 0 || i - 1 == 0) add(dp[i][j] , j * (j - 1) / 2);
        else if(j >= 2) add(dp[i][j] ,  dp[i - 1][j - 2] * (j * (j - 1)) / 2);
        }
    add(dp[n][m] , -1);
    cout<<dp[n][m]<<"\n";
}

int main(){
    /*
     TL;
     #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
     #endif
     */
int t = 1;
//cin>>t;

while(t--)
     {
     solve();
     }

}
// Author : حسن

Compilation message

tents.cpp: In function 'void solve()':
tents.cpp:45:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   45 |         if(i >= 2 && i - 2 == 0 || j - 1 == 0) add(dp[i][j] , j * (i - 1));
      |            ~~~~~~~^~~~~~~~~~~~~
tents.cpp:47:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   47 |         if(j >= 2 && j - 2 == 0 || i - 1 == 0) add(dp[i][j] , j * (j - 1) / 2);
      |            ~~~~~~~^~~~~~~~~~~~~
tents.cpp:35:8: warning: unused variable 'q' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |        ^
tents.cpp:35:26: warning: unused variable 'z' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                          ^
tents.cpp:35:30: warning: unused variable 's' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                              ^
tents.cpp:35:38: warning: unused variable 'f' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                      ^
tents.cpp:35:41: warning: unused variable 'l' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                         ^
tents.cpp:35:45: warning: unused variable 'r' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                             ^
tents.cpp:35:49: warning: unused variable 'k' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                                 ^
tents.cpp:35:53: warning: unused variable 'x' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                                     ^
tents.cpp:35:61: warning: unused variable 'y' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                                             ^
tents.cpp:35:65: warning: unused variable 'mn' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                                                 ^~
tents.cpp:35:78: warning: unused variable 'mx' [-Wunused-variable]
   35 |     ll q , i , j , m ,n, z , s  = 0, f, l , r , k , x = 0 , y , mn  = 1e18 , mx = -1;
      |                                                                              ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 820 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 1 ms 732 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 1364 KB Output is correct
7 Correct 1 ms 820 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 1 ms 732 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 2224 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 5 ms 9556 KB Output is correct
15 Correct 62 ms 55104 KB Output is correct
16 Correct 5 ms 3924 KB Output is correct
17 Correct 15 ms 12776 KB Output is correct
18 Correct 20 ms 17028 KB Output is correct
19 Correct 73 ms 62872 KB Output is correct
20 Correct 61 ms 50848 KB Output is correct
21 Correct 39 ms 33696 KB Output is correct
22 Correct 41 ms 35332 KB Output is correct
23 Correct 27 ms 26928 KB Output is correct
24 Correct 95 ms 70912 KB Output is correct
25 Correct 78 ms 61296 KB Output is correct
26 Correct 87 ms 66600 KB Output is correct
27 Correct 95 ms 69028 KB Output is correct