Submission #151071

#TimeUsernameProblemLanguageResultExecution timeMemory
151071karmaTents (JOI18_tents)C++14
48 / 100
11 ms8440 KiB
#include <bits/stdc++.h> #define ll long long #define pb emplace_back #define mp make_pair #define fi first #define se second using namespace std; const int N = int(1e3) + 2; const int mod = int(1e9) + 7; int f[N][N], n, m; int add(int& x, int y) {if((x += y) >= mod) x -= mod;} int mul(int x, int y) {return 1ll * x * y % mod;} int DP(int r, int c) { if(f[r][c] != -1) return f[r][c]; if(r * c == 0) return f[r][c] = 1; int& res = f[r][c]; res = DP(r - 1, c); // 0 in row r add(res, mul(DP(r - 1, c - 1), 4 * c)); // 1 in row r if(r >= 2) add(res, mul(DP(r - 2, c - 1), (r - 1) * c)); // 1 in row r, 1 in (r - 1) rows, same column if(c >= 2) add(res, mul(DP(r - 1, c - 2), c * (c - 1) / 2)); // same row r return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if(fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } memset(&f, -1, sizeof f); cin >> n >> m; cout << (DP(n, m) - 1 + mod) % mod; }

Compilation message (stderr)

tents.cpp: In function 'int add(int&, int)':
tents.cpp:15:54: warning: no return statement in function returning non-void [-Wreturn-type]
 int add(int& x, int y) {if((x += y) >= mod) x -= mod;}
                                                      ^
tents.cpp: In function 'int main()':
tents.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...