Submission #798329

#TimeUsernameProblemLanguageResultExecution timeMemory
798329vjudge1Tents (JOI18_tents)C++17
100 / 100
95 ms70912 KiB


#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...