QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764859#8049. Equal SumspurplevineML 1ms4184kbC++202.7kb2024-11-20 10:57:372024-11-20 10:57:41

Judging History

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

  • [2024-11-20 10:57:41]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:4184kb
  • [2024-11-20 10:57:37]
  • 提交

answer

#include <bits/stdc++.h>

const int mod = 998244353;
struct modint {
  int x;
  modint(int o = 0) {x = o;}
  modint &operator = (int o) {return x = o, *this;}
  modint &operator += (modint o) {return x = x+o.x >= mod ? x+o.x-mod : x+o.x, *this;}
  modint &operator -= (modint o) {return x = x-o.x < 0 ? x-o.x+mod : x-o.x, *this;}
  modint &operator *= (modint o) {return x = 1ll*x*o.x%mod, *this;}
  modint &operator ^= (int b) {
    modint a = *this, c = 1;
    for (; b; b >>= 1, a *= a) if(b & 1) c *= a;
    return x=c.x, *this;
  }
  modint &operator /= (modint o) {return *this *= o ^= mod-2;}
  friend modint operator + (modint a, modint b) {return a += b;}
  friend modint operator - (modint a, modint b) {return a -= b;}
  friend modint operator * (modint a, modint b) {return a *= b;}
  friend modint operator / (modint a, modint b) {return a /= b;}
  friend modint operator ^(modint a,int b) {return a ^= b;}
  friend bool operator == (modint a, int b) {return a.x == b;}
  friend bool operator != (modint a, int b) {return a.x != b;}
  bool operator ! () {return !x;}
  modint operator - () {return x ? mod-x : 0;}
  bool operator < (const modint &b) const {return x < b.x;}
};
inline modint qpow(modint x, int y) {return x ^ y;}

std::vector<modint> fac, ifac, iv;
inline void initC(int n) {
  if(iv.empty()) fac = ifac = iv = std::vector<modint>(2,1);
  int m = iv.size(); ++n;
  if(m >= n) return;
  iv.resize(n + 1), fac.resize(n + 1), ifac.resize(n + 1);
  for (int i = m; i <= n; i++) {
    iv[i] = iv[mod%i] * (mod - mod/i);
    fac[i] = fac[i-1] * i, ifac[i] = ifac[i-1] * iv[i];
  }
}
inline modint C(int n, int m) {
  if(m<0 || n<m) return 0;
  return initC(n), fac[n] * ifac[m] * ifac[n-m];
}

using v1 = std::vector<modint>;
using v2 = std::vector<v1>;
using v3 = std::vector<v2>;

int main() {
  int n, m; scanf("%d %d", &n, &m);
  int v = 502;
  std::vector<int> la(n + 1), ra(n + 1), lb(m + 1), rb(m + 1);
  for (int i = 1; i <= n; i++) scanf("%d %d", &la[i], &ra[i]);
  for (int i = 1; i <= m; i++) scanf("%d %d", &lb[i], &rb[i]);
  v3 f(n + 1, v2(m + 1, v1(2 * v + 1))), s(f);
  f[0][0][v] = 1;
  for (int i = v; i <= v + v; i++) s[0][0][i] = 1;
  modint ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (j) for (int k = 1; k < v; k++) f[i][j][k] = s[i][j - 1][k + rb[j]] - s[i][j - 1][k + lb[j] - 1];
      if (i) for (int k = v; k < v + v; k++) f[i][j][k] = s[i - 1][j][k - la[i]] - s[i - 1][j][k - ra[i] - 1];
      if (i && j) printf("%d ", f[i][j][v]);  
      s[i][j][0] = f[i][j][0];
      if (i || j) for (int k = 1; k <= v + v; k++) s[i][j][k] = s[i][j][k - 1] + f[i][j][k];
    } 
    if (i) printf("\n");
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: