Submission #1283662

#TimeUsernameProblemLanguageResultExecution timeMemory
1283662iamhereforfunTents (JOI18_tents)C++20
100 / 100
160 ms196660 KiB
// Starcraft 2 enjoyer + luv kd // #include <bits/stdc++.h> using namespace std; #define LSOne(X) ((X) & -(X)) const int N = 5e3 + 5; const int Q = 1e6 + 5; const int M = 1e6 + 5; const int K = 21; const int LG = 20; const int B = 320; const int P = 37; const int INF = 1e9 + 5; const int MOD = 1e9 + 7; const int nx[] = {0, 1, 0, -1}, ny[] = {1, 0, -1, 0}; int n, m; long long dp[N][N]; void solve() { cin >> n >> m; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int x = 0; x <= n; x++) { for (int y = 0; y <= m; y++) { int rx = (n - x), ry = (m - y); dp[x + 2][y + 1] += dp[x][y] * ((rx - 1) * ry) % MOD; dp[x + 1][y + 2] += dp[x][y] * ((ry * (ry - 1)) / 2) % MOD; dp[x + 1][y + 1] += 4 * dp[x][y] * ry; dp[x + 1][y] += dp[x][y]; dp[x + 2][y + 1] %= MOD; dp[x + 1][y + 2] %= MOD; dp[x + 1][y + 1] %= MOD; dp[x + 1][y] %= MOD; // cout << dp[x][y] << " " << x << " " << y << "\n"; } } long long ans = 0; for (int x = 1; x <= m; x++) { ans += dp[n][x]; ans %= MOD; } cout << ans; } signed main() { // freopen("art2.in", "r", stdin); // freopen("art2.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; for (int x = 1; x <= t; x++) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...