Submission #389437

# Submission time Handle Problem Language Result Execution time Memory
389437 2021-04-14T05:40:56 Z talant117408 Boat (APIO16_boat) C++17
0 / 100
11 ms 4300 KB
/*
    Code written by Talant I.D.
*/
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
 
const int mod = 998244353;
 
ll mode(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    return a;
}
 
ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}
 
ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}
 
ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}
 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

ll divide(ll a, ll b) {
	return mult(a, binpow(b, mod-2));
}

const int N = 1010;
int a[N], b[N], rng[N];
ll dp[N][N];
ll inv[N];
int n;

int main() {
	do_not_disturb
	
	vector <int> compressed;
	inv[1] = 1;
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		b[i]++;
		compressed.pb(a[i]);
		compressed.pb(b[i]);
		if (i > 1) inv[i] = binpow(i, mod-2);
	}
	
	sort(all(compressed));
	compressed.resize(unique(all(compressed))-compressed.begin());
	
	auto m = sz(compressed);
	
	for (int j = 0; j < m-1; j++) {
		rng[j+1] = compressed[j+1]-compressed[j];
	}
	for (int i = 1; i <= n; i++) {
		a[i] = lb(all(compressed), a[i])-compressed.begin()+1;
		b[i] = lb(all(compressed), b[i])-compressed.begin()+1;
	}
	
	for (int j = 0; j < m; j++) {
		dp[0][j] = 1;
	}
	ll ans = 0;
	
	for (int i = 1; i <= n; i++) {
		for (int j = a[i]; j < b[i]; j++) {
			ll res = rng[j];
			ll x = rng[j], y = 1;
			for (int k = i-1; k >= 0; k--) {
				dp[i][j] = add(dp[i][j], res*dp[k][j-1]);
				if (a[k] <= j && j < b[k]) {
					x++; y++;
					res = mult(mult(res, x), inv[y]);
				}
			}
		}
		for (int j = 1; j < m; j++) {
			dp[i][j] = add(dp[i][j], dp[i][j-1]);
		}
		ans = add(ans, dp[i][m-1]);
	}
	
	cout << ans;
	
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 4300 KB Output isn't correct
2 Halted 0 ms 0 KB -