Submission #472798

#TimeUsernameProblemLanguageResultExecution timeMemory
472798prvocisloTents (JOI18_tents)C++17
100 / 100
268 ms63312 KiB
#include <iostream> typedef long long ll; using namespace std; const int mod = 1e9 + 7, maxn = 3005; int add(const int& a, const int& b) { return (a + b) % mod; } int mul(const int& a, const int& b) { return (a * 1ll * b) % (ll)mod; } void upd(int& a, const int& b) { a = (a + b) % mod; } int dp[maxn][maxn], p[maxn][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); p[0][0] = 1; for (int i = 1; i < maxn; i++) { p[i][0] = p[i][i] = 1; for (int j = 1; j < i; j++) p[i][j] = add(p[i - 1][j - 1], p[i - 1][j]); } dp[0][0] = 1; int h, w; cin >> h >> w; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { upd(dp[i + 1][j + 1], mul(dp[i][j], mul(4, j + 1))); if (i + 2 <= h) upd(dp[i + 2][j + 1], mul(dp[i][j], mul(i + 1, j + 1))); if (j + 2 <= w) upd(dp[i + 1][j + 2], mul(dp[i][j], (j + 1) * (j + 2)/ 2)); } int ans = 0; for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) { int a = mul(dp[i][j], mul(p[h][i], p[w][j])); upd(ans, a); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...