Submission #389438

# Submission time Handle Problem Language Result Execution time Memory
389438 2021-04-14T05:41:36 Z talant117408 Boat (APIO16_boat) C++17
100 / 100
922 ms 4428 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 = 1e9+7;
 
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 Correct 10 ms 4220 KB Output is correct
2 Correct 11 ms 4300 KB Output is correct
3 Correct 11 ms 4300 KB Output is correct
4 Correct 11 ms 4284 KB Output is correct
5 Correct 11 ms 4300 KB Output is correct
6 Correct 11 ms 4300 KB Output is correct
7 Correct 11 ms 4232 KB Output is correct
8 Correct 10 ms 4260 KB Output is correct
9 Correct 11 ms 4308 KB Output is correct
10 Correct 11 ms 4228 KB Output is correct
11 Correct 11 ms 4300 KB Output is correct
12 Correct 11 ms 4308 KB Output is correct
13 Correct 10 ms 4300 KB Output is correct
14 Correct 11 ms 4300 KB Output is correct
15 Correct 10 ms 4300 KB Output is correct
16 Correct 5 ms 3020 KB Output is correct
17 Correct 5 ms 3020 KB Output is correct
18 Correct 5 ms 3020 KB Output is correct
19 Correct 5 ms 3020 KB Output is correct
20 Correct 5 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4220 KB Output is correct
2 Correct 11 ms 4300 KB Output is correct
3 Correct 11 ms 4300 KB Output is correct
4 Correct 11 ms 4284 KB Output is correct
5 Correct 11 ms 4300 KB Output is correct
6 Correct 11 ms 4300 KB Output is correct
7 Correct 11 ms 4232 KB Output is correct
8 Correct 10 ms 4260 KB Output is correct
9 Correct 11 ms 4308 KB Output is correct
10 Correct 11 ms 4228 KB Output is correct
11 Correct 11 ms 4300 KB Output is correct
12 Correct 11 ms 4308 KB Output is correct
13 Correct 10 ms 4300 KB Output is correct
14 Correct 11 ms 4300 KB Output is correct
15 Correct 10 ms 4300 KB Output is correct
16 Correct 5 ms 3020 KB Output is correct
17 Correct 5 ms 3020 KB Output is correct
18 Correct 5 ms 3020 KB Output is correct
19 Correct 5 ms 3020 KB Output is correct
20 Correct 5 ms 3020 KB Output is correct
21 Correct 502 ms 4320 KB Output is correct
22 Correct 478 ms 4272 KB Output is correct
23 Correct 445 ms 4308 KB Output is correct
24 Correct 478 ms 4304 KB Output is correct
25 Correct 473 ms 4292 KB Output is correct
26 Correct 798 ms 4420 KB Output is correct
27 Correct 825 ms 4292 KB Output is correct
28 Correct 812 ms 4412 KB Output is correct
29 Correct 783 ms 4356 KB Output is correct
30 Correct 13 ms 4200 KB Output is correct
31 Correct 14 ms 4220 KB Output is correct
32 Correct 13 ms 4304 KB Output is correct
33 Correct 13 ms 4212 KB Output is correct
34 Correct 13 ms 4304 KB Output is correct
35 Correct 13 ms 4264 KB Output is correct
36 Correct 13 ms 4300 KB Output is correct
37 Correct 13 ms 4236 KB Output is correct
38 Correct 13 ms 4300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 824 KB Output is correct
2 Correct 5 ms 844 KB Output is correct
3 Correct 5 ms 844 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 6 ms 892 KB Output is correct
6 Correct 8 ms 864 KB Output is correct
7 Correct 8 ms 844 KB Output is correct
8 Correct 8 ms 844 KB Output is correct
9 Correct 8 ms 832 KB Output is correct
10 Correct 8 ms 800 KB Output is correct
11 Correct 5 ms 848 KB Output is correct
12 Correct 4 ms 844 KB Output is correct
13 Correct 5 ms 844 KB Output is correct
14 Correct 5 ms 844 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 4 ms 764 KB Output is correct
17 Correct 4 ms 844 KB Output is correct
18 Correct 4 ms 844 KB Output is correct
19 Correct 4 ms 844 KB Output is correct
20 Correct 4 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4220 KB Output is correct
2 Correct 11 ms 4300 KB Output is correct
3 Correct 11 ms 4300 KB Output is correct
4 Correct 11 ms 4284 KB Output is correct
5 Correct 11 ms 4300 KB Output is correct
6 Correct 11 ms 4300 KB Output is correct
7 Correct 11 ms 4232 KB Output is correct
8 Correct 10 ms 4260 KB Output is correct
9 Correct 11 ms 4308 KB Output is correct
10 Correct 11 ms 4228 KB Output is correct
11 Correct 11 ms 4300 KB Output is correct
12 Correct 11 ms 4308 KB Output is correct
13 Correct 10 ms 4300 KB Output is correct
14 Correct 11 ms 4300 KB Output is correct
15 Correct 10 ms 4300 KB Output is correct
16 Correct 5 ms 3020 KB Output is correct
17 Correct 5 ms 3020 KB Output is correct
18 Correct 5 ms 3020 KB Output is correct
19 Correct 5 ms 3020 KB Output is correct
20 Correct 5 ms 3020 KB Output is correct
21 Correct 502 ms 4320 KB Output is correct
22 Correct 478 ms 4272 KB Output is correct
23 Correct 445 ms 4308 KB Output is correct
24 Correct 478 ms 4304 KB Output is correct
25 Correct 473 ms 4292 KB Output is correct
26 Correct 798 ms 4420 KB Output is correct
27 Correct 825 ms 4292 KB Output is correct
28 Correct 812 ms 4412 KB Output is correct
29 Correct 783 ms 4356 KB Output is correct
30 Correct 13 ms 4200 KB Output is correct
31 Correct 14 ms 4220 KB Output is correct
32 Correct 13 ms 4304 KB Output is correct
33 Correct 13 ms 4212 KB Output is correct
34 Correct 13 ms 4304 KB Output is correct
35 Correct 13 ms 4264 KB Output is correct
36 Correct 13 ms 4300 KB Output is correct
37 Correct 13 ms 4236 KB Output is correct
38 Correct 13 ms 4300 KB Output is correct
39 Correct 5 ms 824 KB Output is correct
40 Correct 5 ms 844 KB Output is correct
41 Correct 5 ms 844 KB Output is correct
42 Correct 5 ms 844 KB Output is correct
43 Correct 6 ms 892 KB Output is correct
44 Correct 8 ms 864 KB Output is correct
45 Correct 8 ms 844 KB Output is correct
46 Correct 8 ms 844 KB Output is correct
47 Correct 8 ms 832 KB Output is correct
48 Correct 8 ms 800 KB Output is correct
49 Correct 5 ms 848 KB Output is correct
50 Correct 4 ms 844 KB Output is correct
51 Correct 5 ms 844 KB Output is correct
52 Correct 5 ms 844 KB Output is correct
53 Correct 5 ms 844 KB Output is correct
54 Correct 4 ms 764 KB Output is correct
55 Correct 4 ms 844 KB Output is correct
56 Correct 4 ms 844 KB Output is correct
57 Correct 4 ms 844 KB Output is correct
58 Correct 4 ms 844 KB Output is correct
59 Correct 537 ms 4312 KB Output is correct
60 Correct 505 ms 4292 KB Output is correct
61 Correct 481 ms 4304 KB Output is correct
62 Correct 535 ms 4300 KB Output is correct
63 Correct 530 ms 4352 KB Output is correct
64 Correct 912 ms 4324 KB Output is correct
65 Correct 918 ms 4380 KB Output is correct
66 Correct 911 ms 4380 KB Output is correct
67 Correct 909 ms 4224 KB Output is correct
68 Correct 922 ms 4240 KB Output is correct
69 Correct 423 ms 4296 KB Output is correct
70 Correct 417 ms 4284 KB Output is correct
71 Correct 422 ms 4320 KB Output is correct
72 Correct 434 ms 4292 KB Output is correct
73 Correct 445 ms 4428 KB Output is correct
74 Correct 108 ms 3012 KB Output is correct
75 Correct 103 ms 3044 KB Output is correct
76 Correct 107 ms 3036 KB Output is correct
77 Correct 107 ms 3016 KB Output is correct
78 Correct 121 ms 3048 KB Output is correct