| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 38716 | wl2025 | 【BJ】T1 | C++ | 通过 | 100 | 1 MS | 292 KB | 8068 | 2025-10-21 15:57:14 |
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2005; const int mod = 1e9 + 7; int pw[N]; int n, m, x, y, res; signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); pw[0] = 1; for (int i = 1; i < N; i++) pw[i] = pw[i - 1] * 2 % mod; cin >> n >> m >> x >> y; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (i == 1 && j == 1) { res = (res + n * m) % mod; continue; } int ans = 0; if (i > 2 * x) { if (j > y) { for (int aa = 0; aa < 2; aa++) { for (int bb = 0; bb < 2; bb++) { int mul = 1, sum = 2 * x * y - 2; if (!aa) mul = mul * (pw[x - 1] - 1) % mod * (pw[y - 1] - 1) % mod, sum -= x - 1 + y - 1; if (!bb) mul = mul * (pw[x - 1] - 1) % mod * (pw[y - 1] - 1) % mod, sum -= x - 1 + y - 1; ans = (ans + 2 * mul % mod * pw[sum] % mod) % mod; } } } else { if (j == 1) { ans = (ans + pw[2 * x - 2]) % mod; res = (res + (n - i + 1) * (m - j + 1) * ans % mod) % mod; continue; } for (int aa = 0; aa < 2; aa++) { for (int bb = 0; bb < 2; bb++) { for (int cc = 0; cc < 2; cc++) { for (int dd = 0; dd < 2; dd++) { int mul = 1, sum = 2 * x * j - 4; if (!aa && !bb) mul = mul * (pw[2 * x - 2] - 1) % mod, sum -= 2 * x - 2; if (!aa && !cc) mul = mul * (pw[j - 2] - 1) % mod, sum -= j - 2; if (!cc && !dd) mul = mul * (pw[2 * x - 2] - 1) % mod, sum -= 2 * x - 2; if (!bb && !dd) mul = mul * (pw[j - 2] - 1) % mod, sum -= j - 2; ans = (ans + mul * pw[sum] % mod) % mod; } } } } } } else if (i > x) { if (j > 2 * y) { for (int aa = 0; aa < 2; aa++) { for (int bb = 0; bb < 2; bb++) { int mul = 1, sum = 2 * x * y - 2; if (!aa) mul = mul * (pw[x - 1] - 1) % mod * (pw[y - 1] - 1) % mod, sum -= x - 1 + y - 1; if (!bb) mul = mul * (pw[x - 1] - 1) % mod * (pw[y - 1] - 1) % mod, sum -= x - 1 + y - 1; ans = (ans + 2 * mul % mod * pw[sum] % mod) % mod; } } } else if (j > y) { for (int aa = 0; aa < 2; aa++) { for (int bb = 0; bb < 2; bb++) { int mul = 1, sum = 2 * x * y - (2 * x - i) * (2 * y - j) - 2; if (!aa) mul = mul * (pw[x - 1] - 1) % mod * (pw[y - 1] - 1) % mod, sum -= x - 1 + y - 1; if (!bb) mul = mul * (pw[x - 1] - 1) % mod * (pw[y - 1] - 1) % mod, sum -= x - 1 + y - 1; ans = (ans + 2 * mul % mod * pw[sum] % mod) % mod; } } int mul = (pw[2 * x - i] - 1) * (pw[2 * x - i] - 1) % mod * (pw[2 * y - j] - 1) % mod * (pw[2 * y - j] - 1) % mod; int sum = (2 * x - i) * (j - 2) + (2 * y - j) * (i - 2) - (2 * x - i) * (2 * y - j); ans = (ans - mul * pw[sum] % mod + mod) % mod; } else { if (j == 1) { ans = (ans + pw[i - 2]) % mod; res = (res + (n - i + 1) * (m - j + 1) * ans % mod) % mod; continue; } for (int aa = 0; aa < 2; aa++) { for (int bb = 0; bb < 2; bb++) { for (int cc = 0; cc < 2; cc++) { for (int dd = 0; dd < 2; dd++) { int mul = 1, sum = i * j - 4; if (!aa && !bb) mul = mul * (pw[i - 2] - 1) % mod, sum -= i - 2; if (!aa && !cc) mul = mul * (pw[j - 2] - 1) % mod, sum -= j - 2; if (!cc && !dd) mul = mul * (pw[i - 2] - 1) % mod, sum -= i - 2; if (!bb && !dd) mul = mul * (pw[j - 2] - 1) % mod, sum -= j - 2; ans = (ans + mul * pw[sum] % mod) % mod; } } } } } } else { if (j > 2 * y) { if (i == 1) { ans = (ans + pw[2 * y - 2]) % mod; res = (res + (n - i + 1) * (m - j + 1) * ans % mod) % mod; continue; } for (int aa = 0; aa < 2; aa++) { for (int bb = 0; bb < 2; bb++) { for (int cc = 0; cc < 2; cc++) { for (int dd = 0; dd < 2; dd++) { int mul = 1, sum = 2 * i * y - 4; if (!aa && !bb) mul = mul * (pw[2 * y - 2] - 1) % mod, sum -= 2 * y - 2; if (!aa && !cc) mul = mul * (pw[i - 2] - 1) % mod, sum -= i - 2; if (!cc && !dd) mul = mul * (pw[2 * y - 2] - 1) % mod, sum -= 2 * y - 2; if (!bb && !dd) mul = mul * (pw[i - 2] - 1) % mod, sum -= i - 2; ans = (ans + mul * pw[sum] % mod) % mod; } } } } } else { if (i == 1) { ans = (ans + pw[j - 2]) % mod; res = (res + (n - i + 1) * (m - j + 1) * ans % mod) % mod; continue; } else if (j == 1) { ans = (ans + pw[i - 2]) % mod; res = (res + (n - i + 1) * (m - j + 1) % mod * ans % mod) % mod; continue; } for (int aa = 0; aa < 2; aa++) { for (int bb = 0; bb < 2; bb++) { for (int cc = 0; cc < 2; cc++) { for (int dd = 0; dd < 2; dd++) { int mul = 1, sum = i * j - 4; if (!aa && !bb) mul = mul * (pw[i - 2] - 1) % mod, sum -= i - 2; if (!aa && !cc) mul = mul * (pw[j - 2] - 1) % mod, sum -= j - 2; if (!cc && !dd) mul = mul * (pw[i - 2] - 1) % mod, sum -= i - 2; if (!bb && !dd) mul = mul * (pw[j - 2] - 1) % mod, sum -= j - 2; ans = (ans + mul * pw[sum] % mod) % mod; } } } } } } //cout << i << ' ' << j << ' ' << ans << endl; res = (res + (n - i + 1) * (m - j + 1) * ans % mod) % mod; } } cout << (res + 1) % mod; return 0; }