QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334567#8049. Equal Sumsucup-team1055ML 1ms3676kbC++173.3kb2024-02-22 05:12:032024-02-22 05:12:04

Judging History

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

  • [2024-02-22 05:12:04]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:3676kb
  • [2024-02-22 05:12:03]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <typename T> bool chmin(T &a, const T &b) {
    if (a <= b) return false;
    a = b;
    return true;
}
template <typename T> bool chmax(T &a, const T &b) {
    if (a >= b) return false;
    a = b;
    return true;
}

using namespace std;

template <ll m> struct modint {
    using mint = modint;
    ll a;

    modint(ll x = 0) : a((x % m + m) % m) {}
    static constexpr ll mod() {
        return m;
    }
    ll val() const {
        return a;
    }
    ll& val() {
        return a;
    }
    mint pow(ll n) const {
        mint res = 1;
        mint x = a;
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    mint inv() const {
        return pow(m - 2);
    }
    mint& operator+=(const mint rhs) {
        a += rhs.a;
        if (a >= m) a -= m;
        return *this;
    }
    mint& operator-=(const mint rhs) {
        if (a < rhs.a) a += m;
        a -= rhs.a;
        return *this;
    }
    mint& operator*=(const mint rhs) {
        a = a * rhs.a % m;
        return *this;
    }
    mint& operator/=(mint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const modint &lhs, const modint &rhs) {
        return lhs.a == rhs.a;
    }
    friend bool operator!=(const modint &lhs, const modint &rhs) {
        return !(lhs == rhs);
    }
    mint operator+() const {
        return *this;
    }
    mint operator-() const {
        return mint() - *this;
    }
};

using modint998244353 = modint<998244353>;
using modint1000000007 = modint<1'000'000'007>;

typedef modint998244353 mint;

const int mx = 500;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m; cin >> n >> m;
	
	vector<int> lx(n), rx(n);
	rep(i,0,n){
		cin >> lx[i] >> rx[i];
	}

	vector<int> ly(m), ry(m);
	rep(i,0,m){
		cin >> ly[i] >> ry[i];
	}

	vector dp(n+1, vector(m+1, vector<mint>(2*mx+1)));
	dp[0][0][mx] = 1;

	rep(i,0,n + 1){
		rep(j,0,m + 1){
			if (i > 0){
				vector<mint> rui(2*mx+2);
				rep(x,0,2*mx+1){
					rui[x+1] = rui[x] + dp[i-1][j][x];
				}
				rep(x,mx,2*mx+1){
					dp[i][j][x] = rui[x-lx[i-1]+1] - rui[x-rx[i-1]];
				}
			}
			if (j > 0){
				vector<mint> rui(2*mx+2);
				rep(x,0,2*mx+1){
					rui[x+1] = rui[x] + dp[i][j-1][x];
				}
				rep(x,0,mx){
					dp[i][j][x] = rui[x+ry[j-1]+1] - rui[x+ly[j-1]];
				}
			}
			if (i > 0){
				if (j > 0){
					cout << dp[i][j][mx].val();
					if (j == m) cout << '\n';
					else cout << ' ';
				}
			}
		}
	}
}

詳細信息

Test #1:

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

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: