QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398869#8049. Equal SumslifanTL 2638ms19916kbC++141.3kb2024-04-25 19:21:022024-04-25 19:21:03

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 19:21:03]
  • 评测
  • 测评结果:TL
  • 用时:2638ms
  • 内存:19916kb
  • [2024-04-25 19:21:02]
  • 提交

answer

// 
#include <bits/stdc++.h>

typedef long long LL;

const int N = 500 + 5;
const LL MOD = 998244353;

int n, m;
int al[N], ar[N], bl[N], br[N];

template<typename T, int L, int R>
struct Array {
	T a[R - L + 1];
	T &operator[](int x) { return a[x - L]; }
	const T &operator[](int x) const { return a[x - L]; }
};
Array<LL, -N, N> f[2][N], g[2][N];

LL sum(int idx1, int idx2, int l, int r, int ll, int rr) {
	l = std::max(l, ll);
	r = std::min(r, rr);
	if(l > r) return 0;
	return (g[idx1][idx2][r] - g[idx1][idx2][l - 1] + MOD) % MOD;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) scanf("%d%d", &al[i], &ar[i]);
	for(int i = 1; i <= m; i++) scanf("%d%d", &bl[i], &br[i]);
	for(int i = 0; i <= n; i++) {
		memset(f[i & 1], 0, sizeof(f[i & 1])), memset(g[i & 1], 0, sizeof(g[i & 1]));
		for(int j = 0; j <= m; j++) for(int k = -500; k <= 500; k++) {
			if(i == 0 && j == 0 && k == 0) (f[i & 1][j][k] += 1) %= MOD;
			if(i) (f[i & 1][j][k] += sum(~i & 1, j, k - ar[i], k - al[i], -500, 0)) %= MOD;
			if(j) (f[i & 1][j][k] += sum(i & 1, j - 1, k + bl[j], k + br[j], 1, 500)) %= MOD;
			g[i & 1][j][k] = (g[i & 1][j][k - 1] + f[i & 1][j][k]) % MOD;
		}
		if(i) {
			for(int j = 1; j <= m; j++) printf("%lld ", f[i & 1][j][0]);
			puts("");
		}
	}
	return 0;
} /*
2 3
1 2
2 3
1 4sad
2 2
1 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 19792kb

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: 0
Accepted
time: 2475ms
memory: 19864kb

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 ...

result:

ok 250000 numbers

Test #3:

score: 0
Accepted
time: 2462ms
memory: 19916kb

input:

500 500
36 457
29 497
27 469
21 497
12 498
35 496
40 478
47 497
45 451
34 488
5 500
22 453
6 462
17 491
3 482
12 468
37 461
27 476
45 470
37 491
49 498
45 485
29 455
8 478
25 493
48 491
2 496
40 493
10 485
22 455
18 475
42 450
8 464
39 498
28 497
18 455
13 492
44 471
39 478
40 481
37 459
37 486
38 4...

output:

410 67896 5410240 335246275 482170226 913746165 370327287 785404079 322053982 763512109 721728384 612084387 267089167 247309721 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 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 ...

result:

ok 250000 numbers

Test #4:

score: 0
Accepted
time: 2638ms
memory: 19872kb

input:

500 500
14 454
10 476
22 452
18 488
4 463
12 495
31 472
19 464
20 476
10 467
44 485
6 496
31 474
39 461
45 483
1 496
25 471
47 462
23 463
42 494
2 481
5 465
41 468
4 496
49 498
24 472
18 500
7 497
2 493
15 491
10 463
31 466
7 469
50 483
46 478
19 458
2 481
20 455
22 485
20 455
45 486
16 469
21 495
5...

output:

441 96580 10039316 711563490 841935541 132520335 384371932 889484040 482637692 883143772 885148661 571513373 992796968 47082194 1307504 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 250000 numbers

Test #5:

score: -100
Time Limit Exceeded

input:

500 500
4 480
6 477
36 454
25 450
38 458
50 464
47 458
1 479
46 485
26 494
10 478
2 480
23 463
35 453
7 454
33 479
44 496
17 471
27 487
36 473
43 497
32 476
22 490
25 496
50 479
4 456
49 456
26 497
2 450
46 496
27 455
32 459
50 495
22 491
15 484
14 488
39 484
1 463
13 483
38 499
35 468
45 453
32 468...

output:

471 108433 16539764 292114332 355294571 926046361 659177551 39453824 529783563 221351807 826151817 498533391 891430723 97219089 48882128 5311735 1 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result: