QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#767091#8049. Equal SumsK8HeML 1ms8024kbC++141.9kb2024-11-20 19:48:482024-11-20 19:48:57

Judging History

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

  • [2024-11-20 19:48:57]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:8024kb
  • [2024-11-20 19:48:48]
  • 提交

answer

#include <bits/stdc++.h>
#define _for(i, a, b) for (int i = a; i <= b; ++i)
#define for_(i, a, b) for (int i = a; i >= b; --i)
#define far(i, vec) for (auto i : vec)
#define bdmd int mid = (l + r) >> 1
typedef long double ldb;
typedef long long ll;
typedef double db;
typedef std::pair <int, int> pii;
typedef std::pair <ll, ll> pll;
const int N = 510, V = 500, P = 998244353;
namespace IO {
	int rnt () {
		int x = 0, w = 1; char c = getchar ();
		while (!isdigit (c)) { if (c == '-') w = -1; c = getchar (); }
		while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
		return x * w;
	}
}
namespace SOLVE {
	using namespace IO;
	int n, m, lx[N], rx[N], ly[N], ry[N];
	int F[N][N][N * 2], sum[N][N][N * 2];
	void In () {
		n = rnt (), m = rnt ();
		_for (i, 1, n) lx[i] = rnt (), rx[i] = rnt ();
		_for (i, 1, m) ly[i] = rnt (), ry[i] = rnt ();
		return;
	}
	void Solve () {
		F[0][0][N] = 1;
		_for (x, -V, -1) sum[0][0][x + N] = 0;
		_for (x, 0, V) sum[0][0][x + N] = 1;
		_for (S, 1, n + m) {
			_for (i, std::max (0, S - m), std::min (S, n)) {
				int j = S - i;
				_for (x, -V, V) {
					if (i) {
						int R = std::min (0, x - lx[i]) + N;
						int L = std::max (-V, x - rx[i]) + N - 1;
						if (L <= R)
							F[i][j][x + N] = (sum[i - 1][j][R] - sum[i - 1][j][L] + P) % P;
					}
					if (j) {
						int R = std::min (V, x + ry[j]) + N;
						int L = std::max (1, x + ly[j]) + N - 1;
						if (L <= R)
							F[i][j][x + N] = (F[i][j][x + N] + (sum[i][j - 1][R] - sum[i][j - 1][L] + P) % P) % P;
					}
					sum[i][j][x + N] = (sum[i][j][x - 1 + N] + F[i][j][x + N]) % P;
				}
			}
		}
		return;
	}
	void Out () {
		_for (i, 1, n) {
			_for (j, 1, m)
				printf ("%d ", F[i][j][N]);
			puts ("");
		}
		return;
	}
}
int main () {
	SOLVE::In ();
	SOLVE::Solve ();
	SOLVE::Out ();
	return 0;
} /*

*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 8024kb

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

result: