Submission #906816

#TimeUsernameProblemLanguageResultExecution timeMemory
906816lightonTents (JOI18_tents)C++17
100 / 100
237 ms119460 KiB
#include<bits/stdc++.h>
#define forf(i,a,b) for(int i = a; i<=b; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
int N,M;
ll dp[5005][5005]; // +2
ll c2(ll x){
    return x*(x-1)/2 %mod;
}
int main(){
    scanf("%d %d" , &N ,&M);
    forf(i,2,N+2) dp[i][2] = 1;
    forf(j,2,M+2) dp[2][j] = 1;
    forf(i,3,N+2){
        forf(j,3,M+2){
            ll ri = i-2;
            ll rj = j-2;
            ll d1 = 2 * ri * dp[i-1][j-1] % mod;
            d1 += ri * (rj-1) * dp[i-1][j-2]; d1 %= mod;

            ll d2 = 2 * ri * dp[i-1][j-1] % mod;
            d2 += c2(ri) * dp[i-2][j-1]; d1 %= mod;

            ll d3 = dp[i][j-1] % mod;

            dp[i][j] = (d1+d2+d3) % mod;

        }
    }
    printf("%lld" , dp[N+2][M+2]-1);
}

Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d" , &N ,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...