QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#765284#8049. Equal SumsThe_cosmosML 1ms5776kbC++142.2kb2024-11-20 13:35:392024-11-20 13:35:39

Judging History

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

  • [2024-11-20 13:35:39]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:5776kb
  • [2024-11-20 13:35:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using db = double;
using lb = long double;
using ull = unsigned long long;
using uint = unsigned int;
using ll = long long;
//using i128 = __int128;
//using ui128 = unsigned __int128;
#define REP(i, first, last) for(int i = (first); i <= (last); ++ i)
#define DOW(i, first, last) for(int i = (first); i >= (last); -- i)
#define int long long
#define pb emplace_back
#define ob pop_back
#define pii pair<int, int>
#define MmodR make_pair
#define fi first
#define se second
#define tpl tuple<int, int, int>
#define MTmod make_tuple
#define poly vector<int>
#define polyp vector<pii>
#define polyt vector<tpl>
#define all(x) x.begin(), x.end()
#define CVR(a, q) memset(a, q, sizeof a)
#define CLR(a) memset(a, 0, sizeof a)
#define CmodY(a, q) memcpy(a, q, sizeof a)
#define modCT __builtin_popcount
const int N = 500 + 5, M = 1e6 + 5;
const int mod1 = 1e9 + 7, mod2 = 998244353, mod = mod2;
const long long inf = 1e18;
const int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n, m, f[N][N][N << 1], s[N << 1];
int a[N][2], b[N][2];

void Add(int& x, int y) {
	return (x += y) >= mod ? x -= mod : x, void();
}

void Solve() {
	cin >> n >> m;
	REP(i, 1, n) cin >> a[i][0] >> a[i][1];
	REP(i, 1, m) cin >> b[i][0] >> b[i][1];
	f[0][0][N] = 1;
	REP(i, 0, n) REP(j, 0, m) {
		if (i > 0) { 
			REP(k, -500, 500) s[k + N] = f[i - 1][j][k + N], Add(s[k + N], s[k + N - 1]);
			REP(k, 0, 500) Add(f[i][j][k + N], s[k + N - a[i][0]]), Add(f[i][j][k + N], mod - s[k + N - a[i][1] - 1]);
		}
		if (j > 0) {
			DOW(k, 500, -500) s[k + N] = f[i][j - 1][k + N], Add(s[k + N], s[k + N + 1]);
			REP(k, -500, -1) Add(f[i][j][k + N], s[k + N + b[j][0]]), Add(f[i][j][k + N], mod - s[k + N + b[j][1] + 1]);
		}
	}
	REP(i, 1, n) REP(j, 1, m)
		cout << f[i][j][N] << " \n"[j == m];
}
signed main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int T = 1;
//	cin >> T;
	while (T --) {
		Solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: