QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764874 | #8049. Equal Sums | Sktn0089 | WA | 1309ms | 28308kb | C++14 | 1.8kb | 2024-11-20 11:00:06 | 2024-11-20 11:00:06 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define mkp make_pair
#define pir pair <ll, ll>
#define pb emplace_back
#define i128 __int128
using namespace std;
template <class T>
void rd(T &x) {
char ch; ll f = 0;
while(!isdigit(ch = getchar()))
if(ch == '-') f = 1;
x = ch - '0';
while(isdigit(ch = getchar()))
x = (x << 1) + (x << 3) + ch - '0';
if(f) x = -x;
}
const ll maxn = 510, mod = 998244353;
template <class T>
void add(T &x, const T y) { x = x + y >= mod? x + y - mod : x + y; }
ll n, m, lx[maxn], rx[maxn], ly[maxn], ry[maxn];
ll _[2][maxn][maxn << 1], *dp[2][maxn];
ll __[2][maxn][maxn << 2], *sum[2][maxn];
int main() {
rd(n), rd(m);
for(ll i = 1; i <= n; i++) rd(lx[i]), rd(rx[i]);
for(ll i = 1; i <= m; i++) rd(ly[i]), rd(ry[i]);
for(ll i = 0; i < 2; i++)
for(ll j = 0; j <= m; j++)
dp[i][j] = _[i][j] + 505, sum[i][j] = __[i][j] + 505;
for(ll i = 0; i <= n; i++) {
ll cur = i & 1; memset(_[cur], 0, sizeof _[cur]);
memset(__[cur], 0, sizeof __[cur]);
if(i == 0) dp[0][0][0] = 1;
for(ll j = 0; j <= m; j++) {
for(ll k = -500; k <= 499; k++) {
ll l, r;
if(i) {
l = lx[i], r = rx[i];
l = max(l, k + 1), r = min(r, k + 500);
if(l <= r)
add(dp[cur][j][k], sum[cur ^ 1][j][k - l]),
add(dp[cur][j][k], mod - sum[cur ^ 1][j][k - r - 1]);
}
if(j) {
l = ly[j], r = ry[j];
l = max(l, -k), r = min(r, 500 - k);
if(l <= r)
add(dp[cur][j][k], sum[cur][j - 1][k + r]),
add(dp[cur][j][k], mod - sum[cur][j - 1][k + l - 1]);
}
sum[cur][j][k] = dp[cur][j][k];
add(sum[cur][j][k], sum[cur][j][k - 1]);
// printf("\ndp[%lld, %lld, %lld] = %lld\n", i, j, k, dp[cur][j][k]);
}
if(i && j) printf("%lld ", dp[cur][j][0]);
} if(i) puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 28308kb
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
Wrong Answer
time: 1309ms
memory: 28200kb
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 998238263 866607750 957037284 654614352 302964837 424364841 889490093 423037116 4509272 752408905 47324307 389457595 287495579 462979313 642732646 504524692 312611100 777766825 566580209 242801353 356675876 123658100 616741098 707938305 411759067 194770987 824138728 787448670 535715400 917907332...
result:
wrong answer 2nd numbers differ - expected: '79401', found: '998238263'