Submission #733051

# Submission time Handle Problem Language Result Execution time Memory
733051 2023-04-30T03:51:05 Z minhcool Boat (APIO16_boat) C++17
100 / 100
827 ms 30300 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,sse,sse2,sse3,sse4")
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 3005;
 
const int oo = 1e18 + 7, mod = 1e9 + 7;
 
int n, a[N], b[N];
int dp[N][N];
 
vector<int> vc;
 
int le[N], ri[N];
 
int prep[N][N];
int inv[N];
 
int binpw(int base, int pw){
	int ans = 1;
	while(pw){
		if(pw & 1) ans = (ans * base) % mod;
		base = (base * base) % mod;
		pw >>= 1;
	}
	return ans;
}
 
void pre(int x, int ind){
	if(!inv[0]){
		inv[0] = 1;
		for(int i = 1; i <= n; i++){
			inv[i] = binpw(i, mod - 2) % mod;
		}
	}
	int ans = 1;
	prep[ind][0] = 1;
	for(int i = 1; i <= min(x, n); i++){
		ans = (ans * (x - i + 1)) % mod;
		ans = (ans * inv[i]) % mod;
		prep[ind][i] = ans;
	}
}
 
int c[N][N];
 
int pref[N][N];
 
int precal[N][N];
 
void pr(){
	c[0][0] = 1;
	for(int i = 1; i <= n; i++){
		c[i][0] = 1;
		for(int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
	}
	for(int j = 1; j < vc.size(); j++){
		for(int cnt = 2; cnt <= n; cnt++){
			for(int temp = 2; temp <= cnt; temp++){
				precal[j][cnt] = (precal[j][cnt] + c[cnt - 2][temp - 2] * prep[j][temp]) % mod;
			}
		}
	}
}
 
void process(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
		a[i]--;
		vc.pb(a[i]), vc.pb(b[i]);
	}
	sort(vc.begin(), vc.end());
	vc.resize(unique(vc.begin(), vc.end()) - vc.begin());
	for(int i = 1; i < vc.size(); i++) pre(vc[i] - vc[i - 1], i);
	pr();
	for(int i = 1; i <= n; i++){
		le[i] = lower_bound(vc.begin(), vc.end(), a[i]) - vc.begin();
		le[i]++;
		ri[i] = lower_bound(vc.begin(), vc.end(), b[i]) - vc.begin();
		//cout << i << " " << le[i] << " " << ri[i] << "\n";
	}
	dp[0][0] = pref[0][0] = 1;
	for(int j = 1; j < vc.size(); j++) dp[0][j] = pref[0][j] = 1;
	for(int i = 1; i <= n; i++){
		dp[i][0] = pref[i][0] = 1;
		for(int j = 1; j < vc.size(); j++){
			if(le[i] > j || ri[i] < j){
				//pref[i][j] = pref[i - 1][j];
				continue;
			}
			dp[i][j] = (pref[i - 1][j - 1] * prep[j][1]) % mod;
			//dp[i][j] = dp[i - 1][j];
			int sum = 0, cnt = 1;
			for(int k = i - 1; k >= 1; k--){
				//if(le[k] > j || ri[k] < j) break;
				if(le[k] <= j && ri[k] >= j){
					cnt++;
					//sum = (sum + pref[j][cnt]) % mod;
					int sum2 = 0;
					/*
					for(int temp = 2; temp <= cnt; temp++){
						sum2 = (sum2 + c[cnt - 2][temp - 2] * prep[j][temp]) % mod;
					}
					dp[i][j] = (dp[i][j] + pref[k - 1][j - 1] * sum2) % mod;*/
					dp[i][j] = (dp[i][j] + pref[k - 1][j - 1] * precal[j][cnt]) % mod;
					//dp[i][j] = (dp[i][j] + (pref[k - 1][j - 1] * sum)) % mod;
					//dp[i][j] += dp[i - 1][j - 1] * prep;
				}
			}
			//pref[i][j] += pref[i - 1][j];
		}
		for(int j = 1; j < vc.size(); j++){
			pref[i][j] = (pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + dp[i][j] + 3 * mod) % mod;
		}
	}
	for(int i = 0; i <= n; i++){
		//for(int j = 0; j < vc.size(); j++) cout << i << " " << j << " " << pref[i][j] << "\n";
	}
	cout << (pref[n][vc.size() - 1] + mod - 1) % mod << "\n";
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}
 

Compilation message

boat.cpp: In function 'void pr()':
boat.cpp:69:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for(int j = 1; j < vc.size(); j++){
      |                 ~~^~~~~~~~~~~
boat.cpp: In function 'void process()':
boat.cpp:87:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i = 1; i < vc.size(); i++) pre(vc[i] - vc[i - 1], i);
      |                 ~~^~~~~~~~~~~
boat.cpp:96:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |  for(int j = 1; j < vc.size(); j++) dp[0][j] = pref[0][j] = 1;
      |                 ~~^~~~~~~~~~~
boat.cpp:99:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |   for(int j = 1; j < vc.size(); j++){
      |                  ~~^~~~~~~~~~~
boat.cpp:112:10: warning: unused variable 'sum2' [-Wunused-variable]
  112 |      int sum2 = 0;
      |          ^~~~
boat.cpp:106:8: warning: unused variable 'sum' [-Wunused-variable]
  106 |    int sum = 0, cnt = 1;
      |        ^~~
boat.cpp:125:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |   for(int j = 1; j < vc.size(); j++){
      |                  ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 526 ms 26756 KB Output is correct
2 Correct 528 ms 26808 KB Output is correct
3 Correct 518 ms 26896 KB Output is correct
4 Correct 540 ms 26748 KB Output is correct
5 Correct 552 ms 26812 KB Output is correct
6 Correct 531 ms 26860 KB Output is correct
7 Correct 563 ms 26760 KB Output is correct
8 Correct 527 ms 26736 KB Output is correct
9 Correct 509 ms 26696 KB Output is correct
10 Correct 515 ms 26864 KB Output is correct
11 Correct 523 ms 26656 KB Output is correct
12 Correct 527 ms 26840 KB Output is correct
13 Correct 516 ms 26832 KB Output is correct
14 Correct 512 ms 26780 KB Output is correct
15 Correct 507 ms 26880 KB Output is correct
16 Correct 97 ms 10796 KB Output is correct
17 Correct 104 ms 11020 KB Output is correct
18 Correct 95 ms 10920 KB Output is correct
19 Correct 101 ms 11036 KB Output is correct
20 Correct 97 ms 10896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 526 ms 26756 KB Output is correct
2 Correct 528 ms 26808 KB Output is correct
3 Correct 518 ms 26896 KB Output is correct
4 Correct 540 ms 26748 KB Output is correct
5 Correct 552 ms 26812 KB Output is correct
6 Correct 531 ms 26860 KB Output is correct
7 Correct 563 ms 26760 KB Output is correct
8 Correct 527 ms 26736 KB Output is correct
9 Correct 509 ms 26696 KB Output is correct
10 Correct 515 ms 26864 KB Output is correct
11 Correct 523 ms 26656 KB Output is correct
12 Correct 527 ms 26840 KB Output is correct
13 Correct 516 ms 26832 KB Output is correct
14 Correct 512 ms 26780 KB Output is correct
15 Correct 507 ms 26880 KB Output is correct
16 Correct 97 ms 10796 KB Output is correct
17 Correct 104 ms 11020 KB Output is correct
18 Correct 95 ms 10920 KB Output is correct
19 Correct 101 ms 11036 KB Output is correct
20 Correct 97 ms 10896 KB Output is correct
21 Correct 574 ms 24160 KB Output is correct
22 Correct 573 ms 24476 KB Output is correct
23 Correct 553 ms 24128 KB Output is correct
24 Correct 569 ms 24048 KB Output is correct
25 Correct 567 ms 24088 KB Output is correct
26 Correct 699 ms 23968 KB Output is correct
27 Correct 718 ms 24332 KB Output is correct
28 Correct 704 ms 24096 KB Output is correct
29 Correct 679 ms 23944 KB Output is correct
30 Correct 516 ms 26536 KB Output is correct
31 Correct 515 ms 26672 KB Output is correct
32 Correct 512 ms 26580 KB Output is correct
33 Correct 517 ms 26664 KB Output is correct
34 Correct 501 ms 26568 KB Output is correct
35 Correct 511 ms 26444 KB Output is correct
36 Correct 513 ms 26700 KB Output is correct
37 Correct 508 ms 26528 KB Output is correct
38 Correct 514 ms 26448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3788 KB Output is correct
2 Correct 7 ms 3796 KB Output is correct
3 Correct 8 ms 3708 KB Output is correct
4 Correct 7 ms 3800 KB Output is correct
5 Correct 7 ms 3788 KB Output is correct
6 Correct 8 ms 3796 KB Output is correct
7 Correct 8 ms 3812 KB Output is correct
8 Correct 8 ms 3796 KB Output is correct
9 Correct 8 ms 3752 KB Output is correct
10 Correct 8 ms 3796 KB Output is correct
11 Correct 8 ms 3796 KB Output is correct
12 Correct 7 ms 3796 KB Output is correct
13 Correct 7 ms 3796 KB Output is correct
14 Correct 7 ms 3792 KB Output is correct
15 Correct 7 ms 3796 KB Output is correct
16 Correct 5 ms 2772 KB Output is correct
17 Correct 4 ms 2772 KB Output is correct
18 Correct 4 ms 2772 KB Output is correct
19 Correct 5 ms 2772 KB Output is correct
20 Correct 4 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 526 ms 26756 KB Output is correct
2 Correct 528 ms 26808 KB Output is correct
3 Correct 518 ms 26896 KB Output is correct
4 Correct 540 ms 26748 KB Output is correct
5 Correct 552 ms 26812 KB Output is correct
6 Correct 531 ms 26860 KB Output is correct
7 Correct 563 ms 26760 KB Output is correct
8 Correct 527 ms 26736 KB Output is correct
9 Correct 509 ms 26696 KB Output is correct
10 Correct 515 ms 26864 KB Output is correct
11 Correct 523 ms 26656 KB Output is correct
12 Correct 527 ms 26840 KB Output is correct
13 Correct 516 ms 26832 KB Output is correct
14 Correct 512 ms 26780 KB Output is correct
15 Correct 507 ms 26880 KB Output is correct
16 Correct 97 ms 10796 KB Output is correct
17 Correct 104 ms 11020 KB Output is correct
18 Correct 95 ms 10920 KB Output is correct
19 Correct 101 ms 11036 KB Output is correct
20 Correct 97 ms 10896 KB Output is correct
21 Correct 574 ms 24160 KB Output is correct
22 Correct 573 ms 24476 KB Output is correct
23 Correct 553 ms 24128 KB Output is correct
24 Correct 569 ms 24048 KB Output is correct
25 Correct 567 ms 24088 KB Output is correct
26 Correct 699 ms 23968 KB Output is correct
27 Correct 718 ms 24332 KB Output is correct
28 Correct 704 ms 24096 KB Output is correct
29 Correct 679 ms 23944 KB Output is correct
30 Correct 516 ms 26536 KB Output is correct
31 Correct 515 ms 26672 KB Output is correct
32 Correct 512 ms 26580 KB Output is correct
33 Correct 517 ms 26664 KB Output is correct
34 Correct 501 ms 26568 KB Output is correct
35 Correct 511 ms 26444 KB Output is correct
36 Correct 513 ms 26700 KB Output is correct
37 Correct 508 ms 26528 KB Output is correct
38 Correct 514 ms 26448 KB Output is correct
39 Correct 7 ms 3788 KB Output is correct
40 Correct 7 ms 3796 KB Output is correct
41 Correct 8 ms 3708 KB Output is correct
42 Correct 7 ms 3800 KB Output is correct
43 Correct 7 ms 3788 KB Output is correct
44 Correct 8 ms 3796 KB Output is correct
45 Correct 8 ms 3812 KB Output is correct
46 Correct 8 ms 3796 KB Output is correct
47 Correct 8 ms 3752 KB Output is correct
48 Correct 8 ms 3796 KB Output is correct
49 Correct 8 ms 3796 KB Output is correct
50 Correct 7 ms 3796 KB Output is correct
51 Correct 7 ms 3796 KB Output is correct
52 Correct 7 ms 3792 KB Output is correct
53 Correct 7 ms 3796 KB Output is correct
54 Correct 5 ms 2772 KB Output is correct
55 Correct 4 ms 2772 KB Output is correct
56 Correct 4 ms 2772 KB Output is correct
57 Correct 5 ms 2772 KB Output is correct
58 Correct 4 ms 2772 KB Output is correct
59 Correct 631 ms 29712 KB Output is correct
60 Correct 618 ms 29780 KB Output is correct
61 Correct 606 ms 29584 KB Output is correct
62 Correct 649 ms 29632 KB Output is correct
63 Correct 656 ms 29528 KB Output is correct
64 Correct 812 ms 30300 KB Output is correct
65 Correct 798 ms 30268 KB Output is correct
66 Correct 799 ms 30172 KB Output is correct
67 Correct 827 ms 30100 KB Output is correct
68 Correct 807 ms 30208 KB Output is correct
69 Correct 612 ms 29640 KB Output is correct
70 Correct 606 ms 29644 KB Output is correct
71 Correct 608 ms 29628 KB Output is correct
72 Correct 626 ms 29568 KB Output is correct
73 Correct 626 ms 29636 KB Output is correct
74 Correct 130 ms 11084 KB Output is correct
75 Correct 120 ms 11244 KB Output is correct
76 Correct 120 ms 11212 KB Output is correct
77 Correct 141 ms 11212 KB Output is correct
78 Correct 132 ms 11080 KB Output is correct