QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340821 | #8049. Equal Sums | supepapupu | ML | 0ms | 3796kb | C++20 | 1.8kb | 2024-02-29 12:53:17 | 2024-02-29 12:53:17 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << el
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;
void inc(ll &a, ll b) {
a += b;
if (a >= mod) a -= mod;
}
void dec(ll &a, ll b) {
a -= b;
if (a < 0) a += mod;
}
ll add(ll a, ll b) {
a += b;
return a >= mod ? a - mod : a;
}
ll del(ll a, ll b) {
a -= b;
return a < 0 ? a + mod : a;
}
ll qmi(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
ll inv(ll a) {
return qmi(a, mod - 2);
}
ll f[510][510][1010];
int lx[510], rx[510], ly[510], ry[510];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> lx[i] >> rx[i];
for (int i = 1; i <= m; ++i) cin >> ly[i] >> ry[i];
f[0][0][500] = 1, f[0][0][501] = -1;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m; ++j) {
for (int k = 1; k <= 1000; ++k) inc(f[i][j][k], f[i][j][k - 1]);
for (int k = 0; k <= 1000; ++k) {
if (k <= 500) {
inc(f[i + 1][j][k + lx[i + 1]], f[i][j][k]);
dec(f[i + 1][j][k + rx[i + 1] + 1], f[i][j][k]);
} else {
inc(f[i][j + 1][k - ry[j + 1]], f[i][j][k]);
dec(f[i][j + 1][k - ly[j + 1] + 1], f[i][j][k]);
}
}
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
cout << f[i][j][500] << " \n"[j == m];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
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 ...