Submission #899056

#TimeUsernameProblemLanguageResultExecution timeMemory
899056lovrotTents (JOI18_tents)C++17
100 / 100
270 ms71880 KiB
#include <cstdio> #include <cstring> using namespace std; typedef long long ll; const int N = 3010; const int MOD = 1e9 + 7; inline int add(int a, int b) { if(a + b < MOD) return a + b; return a + b - MOD; } inline int mult(int a, int b) { return (ll) a * b % MOD; } inline int pot(int a, int b) { int ret = 1; for(; b; b /= 2, a = mult(a, a)) if(b & 1) ret = mult(ret, a); return ret; } inline int inv(int a) { return pot(a, MOD - 2); } int w, h; int C[N][N], DP[N][N]; int choose(int a, int b) { if(a == b|| !b) return 1; if(C[a][b] != -1) return C[a][b]; return C[a][b] = add(choose(a - 1, b), choose(a - 1, b - 1)); } int dp(int n, int m) { if(!n || !m) return 1; if(DP[n][m] != -1) return DP[n][m]; int a = 0, b = 0, c = 0, d = 0; a = dp(n - 1, m); b = mult(mult(4, m), dp(n - 1, m - 1)); if(m > 1) c = mult(choose(m, 2), dp(n - 1, m - 2)); if(n > 1) d = mult(mult(m, n - 1), dp(n - 2, m - 1)); // printf("%d %d %d %d %d %d\n", n, m, a, b, c, d); return DP[n][m] = add(a, add(b, add(c, d))); } int main() { memset(C, -1, sizeof(C)); memset(DP, -1, sizeof(DP)); scanf("%d%d", &h, &w); printf("%d\n", add(MOD - 1, dp(h, w))); return 0; }

Compilation message (stderr)

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