Submission #954820

# Submission time Handle Problem Language Result Execution time Memory
954820 2024-03-28T15:51:44 Z Itamar Boat (APIO16_boat) C++14
100 / 100
915 ms 2860 KB
#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define x first
#define y second
#define pd pair<double,double>

const int siz = 502;
ll a[siz], b[siz];

ll ch[siz][siz];
ll invfac[siz];
ll inv[siz];
const int mod = 1e9 + 7;

ll powi(ll a, ll b) {
	if (b == 0)return 1;
	ll ans = powi(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2)ans = (ans * a) % mod;
	return ans;
}
int main()
{
	int n; cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];

	vll v; for (int i = 0; i < n; i++) { v.push_back(a[i]); v.push_back(b[i]); v.push_back(b[i] + 1); }
	sort(v.begin(), v.end());

	for (int i = 0; i < siz; i++)inv[i] = powi(i, mod - 2);
	invfac[0] = 1;
	for (int i = 1; i < siz; i++)invfac[i] = (inv[i] * invfac[i - 1])%mod;

	for (int i = 0; i < siz; i++) {
		for (int j = 0; j <= i; j++) {
			ch[i][j] = (invfac[j] * invfac[i - j]) % mod;
			ch[i][j] = (ch[i][j] * powi(invfac[i], mod - 2)) % mod;
		}
	}

	vll dp(n);
	for (int i = 0; i < v.size()-1; i++) {
		ll N = v[i+1]-v[i];
		if (N <= 0)continue;
		vll nc(siz);
		nc[0] = 1;
		for (int j = 1; j < siz; j++) {
			nc[j] = ((N - j + 1) * nc[j - 1]) % mod;
			nc[j] = (nc[j] * inv[j]) % mod;
		}
		vll form(siz);
		for (int j = 0; j+2 < siz; j++) {
			for (int f = 0; f <= j; f++) {
				form[j] += nc[f + 2] * ch[j][f];
				form[j] %= mod;
			}
		}
		vll dpt=dp;
		ll sum = 0;
		for (int j = 0; j < n; j++) {
			if (a[j] <= v[i] && b[j] >= v[i + 1] - 1) {
				int bet = 0;
				dpt[j] += (sum + 1) * N;
				dpt[j] %= mod;
				for (int f = j + 1; f < n; f++) {
					if (a[f] <= v[i] && b[f] >= v[i + 1] - 1) {
						dpt[f] += (sum + 1) * form[bet];
						dpt[f] %= mod;
						bet++;
					}
				}
			}
			sum += dp[j];
			sum %= mod;
		}
		dp = dpt;
	}
	ll ans = 0; for (int i = 0; i < n; i++)ans += dp[i];
	ans %= mod;
	cout << ans;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for (int i = 0; i < v.size()-1; i++) {
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 501 ms 2436 KB Output is correct
2 Correct 502 ms 2444 KB Output is correct
3 Correct 501 ms 2444 KB Output is correct
4 Correct 500 ms 2444 KB Output is correct
5 Correct 500 ms 2384 KB Output is correct
6 Correct 501 ms 2448 KB Output is correct
7 Correct 503 ms 2440 KB Output is correct
8 Correct 500 ms 2444 KB Output is correct
9 Correct 504 ms 2396 KB Output is correct
10 Correct 503 ms 2644 KB Output is correct
11 Correct 501 ms 2640 KB Output is correct
12 Correct 501 ms 2444 KB Output is correct
13 Correct 504 ms 2444 KB Output is correct
14 Correct 503 ms 2388 KB Output is correct
15 Correct 503 ms 2640 KB Output is correct
16 Correct 108 ms 2356 KB Output is correct
17 Correct 115 ms 2440 KB Output is correct
18 Correct 114 ms 2860 KB Output is correct
19 Correct 114 ms 2384 KB Output is correct
20 Correct 112 ms 2444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 501 ms 2436 KB Output is correct
2 Correct 502 ms 2444 KB Output is correct
3 Correct 501 ms 2444 KB Output is correct
4 Correct 500 ms 2444 KB Output is correct
5 Correct 500 ms 2384 KB Output is correct
6 Correct 501 ms 2448 KB Output is correct
7 Correct 503 ms 2440 KB Output is correct
8 Correct 500 ms 2444 KB Output is correct
9 Correct 504 ms 2396 KB Output is correct
10 Correct 503 ms 2644 KB Output is correct
11 Correct 501 ms 2640 KB Output is correct
12 Correct 501 ms 2444 KB Output is correct
13 Correct 504 ms 2444 KB Output is correct
14 Correct 503 ms 2388 KB Output is correct
15 Correct 503 ms 2640 KB Output is correct
16 Correct 108 ms 2356 KB Output is correct
17 Correct 115 ms 2440 KB Output is correct
18 Correct 114 ms 2860 KB Output is correct
19 Correct 114 ms 2384 KB Output is correct
20 Correct 112 ms 2444 KB Output is correct
21 Correct 738 ms 2436 KB Output is correct
22 Correct 744 ms 2444 KB Output is correct
23 Correct 720 ms 2548 KB Output is correct
24 Correct 731 ms 2440 KB Output is correct
25 Correct 735 ms 2444 KB Output is correct
26 Correct 726 ms 2640 KB Output is correct
27 Correct 750 ms 2380 KB Output is correct
28 Correct 735 ms 2444 KB Output is correct
29 Correct 742 ms 2436 KB Output is correct
30 Correct 715 ms 2448 KB Output is correct
31 Correct 714 ms 2440 KB Output is correct
32 Correct 715 ms 2444 KB Output is correct
33 Correct 717 ms 2644 KB Output is correct
34 Correct 710 ms 2440 KB Output is correct
35 Correct 503 ms 2396 KB Output is correct
36 Correct 502 ms 2444 KB Output is correct
37 Correct 500 ms 2412 KB Output is correct
38 Correct 499 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 2360 KB Output is correct
2 Correct 168 ms 2548 KB Output is correct
3 Correct 168 ms 2412 KB Output is correct
4 Correct 166 ms 2392 KB Output is correct
5 Correct 169 ms 2416 KB Output is correct
6 Correct 167 ms 2420 KB Output is correct
7 Correct 167 ms 2384 KB Output is correct
8 Correct 168 ms 2640 KB Output is correct
9 Correct 167 ms 2636 KB Output is correct
10 Correct 167 ms 2388 KB Output is correct
11 Correct 167 ms 2412 KB Output is correct
12 Correct 167 ms 2384 KB Output is correct
13 Correct 168 ms 2200 KB Output is correct
14 Correct 167 ms 2396 KB Output is correct
15 Correct 168 ms 2416 KB Output is correct
16 Correct 94 ms 2412 KB Output is correct
17 Correct 91 ms 2252 KB Output is correct
18 Correct 91 ms 2396 KB Output is correct
19 Correct 91 ms 2412 KB Output is correct
20 Correct 96 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 501 ms 2436 KB Output is correct
2 Correct 502 ms 2444 KB Output is correct
3 Correct 501 ms 2444 KB Output is correct
4 Correct 500 ms 2444 KB Output is correct
5 Correct 500 ms 2384 KB Output is correct
6 Correct 501 ms 2448 KB Output is correct
7 Correct 503 ms 2440 KB Output is correct
8 Correct 500 ms 2444 KB Output is correct
9 Correct 504 ms 2396 KB Output is correct
10 Correct 503 ms 2644 KB Output is correct
11 Correct 501 ms 2640 KB Output is correct
12 Correct 501 ms 2444 KB Output is correct
13 Correct 504 ms 2444 KB Output is correct
14 Correct 503 ms 2388 KB Output is correct
15 Correct 503 ms 2640 KB Output is correct
16 Correct 108 ms 2356 KB Output is correct
17 Correct 115 ms 2440 KB Output is correct
18 Correct 114 ms 2860 KB Output is correct
19 Correct 114 ms 2384 KB Output is correct
20 Correct 112 ms 2444 KB Output is correct
21 Correct 738 ms 2436 KB Output is correct
22 Correct 744 ms 2444 KB Output is correct
23 Correct 720 ms 2548 KB Output is correct
24 Correct 731 ms 2440 KB Output is correct
25 Correct 735 ms 2444 KB Output is correct
26 Correct 726 ms 2640 KB Output is correct
27 Correct 750 ms 2380 KB Output is correct
28 Correct 735 ms 2444 KB Output is correct
29 Correct 742 ms 2436 KB Output is correct
30 Correct 715 ms 2448 KB Output is correct
31 Correct 714 ms 2440 KB Output is correct
32 Correct 715 ms 2444 KB Output is correct
33 Correct 717 ms 2644 KB Output is correct
34 Correct 710 ms 2440 KB Output is correct
35 Correct 503 ms 2396 KB Output is correct
36 Correct 502 ms 2444 KB Output is correct
37 Correct 500 ms 2412 KB Output is correct
38 Correct 499 ms 2384 KB Output is correct
39 Correct 168 ms 2360 KB Output is correct
40 Correct 168 ms 2548 KB Output is correct
41 Correct 168 ms 2412 KB Output is correct
42 Correct 166 ms 2392 KB Output is correct
43 Correct 169 ms 2416 KB Output is correct
44 Correct 167 ms 2420 KB Output is correct
45 Correct 167 ms 2384 KB Output is correct
46 Correct 168 ms 2640 KB Output is correct
47 Correct 167 ms 2636 KB Output is correct
48 Correct 167 ms 2388 KB Output is correct
49 Correct 167 ms 2412 KB Output is correct
50 Correct 167 ms 2384 KB Output is correct
51 Correct 168 ms 2200 KB Output is correct
52 Correct 167 ms 2396 KB Output is correct
53 Correct 168 ms 2416 KB Output is correct
54 Correct 94 ms 2412 KB Output is correct
55 Correct 91 ms 2252 KB Output is correct
56 Correct 91 ms 2396 KB Output is correct
57 Correct 91 ms 2412 KB Output is correct
58 Correct 96 ms 2396 KB Output is correct
59 Correct 846 ms 2640 KB Output is correct
60 Correct 839 ms 2384 KB Output is correct
61 Correct 841 ms 2640 KB Output is correct
62 Correct 856 ms 2452 KB Output is correct
63 Correct 847 ms 2444 KB Output is correct
64 Correct 892 ms 2444 KB Output is correct
65 Correct 892 ms 2444 KB Output is correct
66 Correct 903 ms 2440 KB Output is correct
67 Correct 895 ms 2640 KB Output is correct
68 Correct 915 ms 2448 KB Output is correct
69 Correct 838 ms 2568 KB Output is correct
70 Correct 838 ms 2640 KB Output is correct
71 Correct 848 ms 2644 KB Output is correct
72 Correct 848 ms 2644 KB Output is correct
73 Correct 838 ms 2440 KB Output is correct
74 Correct 133 ms 2440 KB Output is correct
75 Correct 131 ms 2440 KB Output is correct
76 Correct 130 ms 2396 KB Output is correct
77 Correct 131 ms 2388 KB Output is correct
78 Correct 130 ms 2440 KB Output is correct