QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#628285 | #8049. Equal Sums | lycc | ML | 1ms | 4140kb | C++20 | 2.2kb | 2024-10-10 19:28:23 | 2024-10-10 19:28:24 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define pb emplace_back
#define For(i, x, y) for (int i = (x); i <= (y); i ++)
#define rep(i, x, y) for (int i = (x); i >= (y); i --)
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define sz(v) (int)((v).size())
#define ull unsigned long long
#define uint unsigned int
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mp make_pair
#define i128 __int128
#define db long double
#define vi vector< int >
#define mem(v, x) memset(v, x, sizeof(v))
#define A3 array< int, 3 >
using namespace std;
//mt19937_64 rnd(time(0));
template< typename T > void cmin(T &x, T y) { return x = min(x, y), void(); }
template< typename T > void cmax(T &x, T y) { return x = max(x, y), void(); }
int ksm(int x, int y, int p) {
int v = 1; x %= p;
while (y) v = 1ll * v * ((y & 1) ? x : 1) % p, x = 1ll * x * x % p, y >>= 1;
return (v % p + p) % p;
}
bool MemoryST;
const int N = 505, V = 500;
const int mod = 998244353;
const long long INF = 1e18;
const int base = 13131;
int n, m, a[N][2], b[N][2], dp[N][N][N * 2];
#define f(i, j, k) dp[i][j][k + 503]
void solve() {
cin >> n >> m;
For (i, 1, n) cin >> a[i][0] >> a[i][1];
For (i, 1, m) cin >> b[i][0] >> b[i][1];
f(0, 0, 0) = 1; f(0, 0, 1) = mod - 1;
For (i, 0, n) {
For (j, 0, m) {
For (k, -V, V) {
(f(i, j, k) += f(i, j, k - 1)) %= mod;
if (k < 0) {
(f(i + 1, j, k + a[i + 1][0]) += f(i, j, k)) %= mod;
(f(i + 1, j, k + a[i + 1][1] + 1) += mod - f(i, j, k)) %= mod;
} else {
(f(i, j + 1, k - b[j + 1][1]) += f(i, j, k)) %= mod;
(f(i, j + 1, k - b[j + 1][0] + 1) += mod - f(i, j, k)) %= mod;
}
}
if (i && j) cout << f(i, j, 0) << ' ';
}
if (i) cout << '\n';
}
return;
}
bool MemoryED;
signed main() {
ios :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cerr << fixed << setprecision(6) << (&MemoryST - &MemoryED) / 1048576.0 << "MB\n";
int TESTCNT = 1;
// cin >> TESTCNT;
while (TESTCNT --) solve();
cerr << endl << 1e3 * clock() / CLOCKS_PER_SEC << "ms";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4140kb
input:
2 3 1 2 2 3 1 4 2 2 1 3
output:
2 0 0 3 4 4
result:
ok 6 numbers
Test #2:
score: -100
Memory Limit Exceeded
input:
500 500 19 458 1 480 7 485 50 461 12 476 15 461 48 466 40 453 46 467 9 458 27 478 26 472 46 459 29 490 6 500 17 487 48 484 28 472 28 459 25 480 4 491 29 481 36 460 2 491 44 499 22 473 20 458 4 483 27 471 2 496 11 461 43 450 2 478 37 466 15 459 42 482 7 451 19 455 2 453 47 475 48 450 1 474 46 471 9 4...
output:
411 79401 9145270 673005095 180581065 984223118 586589234 293043270 404363796 865361724 665487988 118838806 926189944 226338288 521479857 808644951 786041288 340769021 177100 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...