Submission #1161974

#TimeUsernameProblemLanguageResultExecution timeMemory
1161974trinm01Tents (JOI18_tents)C++20
100 / 100
184 ms71344 KiB
#include <bits/stdc++.h>
using namespace std;

#define int unsigned long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>

const ll mod = 1e9 + 7;
const ll MAXN = 3 * 1e3 + 5;
const ll oo = 1e10;
const ll base = 320;

int m, n, f[MAXN][MAXN];

int dp(int i, int j)
{
	if (i < 0 || j < 0)
		return 0;
	if (i == 0 || j == 0)
		return 1;
	if (f[i][j] != -1)
		return f[i][j];
	int a = 0;
	if (i >= 1 && j >= 2)
		a = ((dp(i - 1, j - 2) * ((j) * (j - 1) / 2) % mod)) % mod;
	int b = 0;
	if (i >= 2 && j >= 1)
		b = (dp(i - 2, j - 1) * (i - 1) * j) % mod;
	int c = 0;
	if (i >= 1)
		c = dp(i - 1, j);
	int d = 0;
	if (i >= 1 && j >= 1)
		d = ((dp(i - 1, j - 1) * (j * 4) % mod)) % mod;
	return f[i][j] = (a + b + c + d) % mod;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	if (fopen(".INP", "r"))
	{
		freopen(".INP", "r", stdin);
		freopen(".OUT", "w", stdout);
	}

	cin >> m >> n;
	memset(f, -1, sizeof f);
	cout << dp(m, n) - 1;

	return 0;
}

Compilation message (stderr)

tents.cpp: In function 'int main()':
tents.cpp:50:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |                 freopen(".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
tents.cpp:51:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |                 freopen(".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...