Submission #198252

#TimeUsernameProblemLanguageResultExecution timeMemory
198252quocnguyen1012Tents (JOI18_tents)C++14
100 / 100
287 ms35832 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int maxn = 3e3 + 5, mod = 1e9 + 7; void add(int & a, int b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } int mul(int a, int b) { return 1ll * a * b % mod; } int N, M; int f[maxn][maxn]; signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } cin >> N >> M; for (int i = 0; i < maxn; ++i) f[i][0] = 1, f[0][i] = 1; for (int i = 1; i <= N; ++i){ for (int j = 1; j <= M; ++j){ int & res = f[i][j]; add(res,f[i - 1][j]); add(res,mul(f[i - 1][j - 1],4 * j)); if (i > 1) add(res,mul(f[i - 2][j - 1],j * (i - 1))); if (j > 1) add(res,mul(f[i - 1][j - 2],j * (j - 1) / 2)); } } add(f[N][M], -1); cout << f[N][M] << '\n'; }

Compilation message (stderr)

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