Submission #673407

# Submission time Handle Problem Language Result Execution time Memory
673407 2022-12-20T14:02:29 Z S2speed Boat (APIO16_boat) C++17
100 / 100
504 ms 16252 KB
#include<bits/stdc++.h>

using namespace std;

#pragma GCC optimize ("Ofast")

#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
typedef long long ll;

const ll maxn = 1e3 + 17 , md = 1e9 + 7;

ll tav(ll n , ll k){
	ll res = 1;
	while(k > 0){
		if(k & 1){
			res *= n; res %= md;
		}
		n *= n; n %= md;
		k >>= 1;
	}
	return res;
}

ll l[maxn] , r[maxn] , w[maxn] , f[maxn][maxn] , dp[maxn][maxn];
vector<ll> v;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	ll n;
	cin>>n;
	for(ll i = 0 ; i < n ; i++){
		cin>>l[i]>>r[i]; l[i]--;
		v.push_back(l[i]); v.push_back(r[i]);
	}
	sort(all(v));
	v.resize(distance(v.begin() , unique(all(v))));
	ll vs = sze(v);
	for(ll i = 0 ; i < vs - 1 ; i++){
		w[i] = v[i + 1] - v[i];
		ll lm = min(w[i] , n);
		for(ll j = 1 ; j <= lm ; j++){
			f[i][j] = (w[i] - j + 1) * tav(j , md - 2) % md;
		}
	}
	for(ll i = 0 ; i < n ; i++){
		l[i] = lower_bound(all(v) , l[i]) - v.begin();
		r[i] = lower_bound(all(v) , r[i]) - v.begin();
	}
	for(ll i = 0 ; i < vs - 1 ; i++) dp[i][0] = 1;
	for(ll i = 0 ; i < n ; i++){
		for(ll j = r[i] - 1 ; j >= l[i] ; j--){
			ll h = 0 , lm = min(i + 1 , w[j]);
			for(ll k = lm ; k ; k--){
				ll o = dp[j][k - 1] * f[j][k] % md;
				dp[j][k] += o; dp[j][k] -= (dp[j][k] >= md) * md;
				h += o;
			}
			for(ll k = j + 1 ; k < vs ; k++){
				dp[k][0] += h; dp[k][0] %= md;
			}
		}
	}
	ll ans = dp[vs - 1][0];
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 10188 KB Output is correct
2 Correct 37 ms 10324 KB Output is correct
3 Correct 38 ms 10288 KB Output is correct
4 Correct 38 ms 10224 KB Output is correct
5 Correct 38 ms 10272 KB Output is correct
6 Correct 36 ms 10224 KB Output is correct
7 Correct 37 ms 10260 KB Output is correct
8 Correct 36 ms 10224 KB Output is correct
9 Correct 36 ms 10232 KB Output is correct
10 Correct 36 ms 10220 KB Output is correct
11 Correct 39 ms 10216 KB Output is correct
12 Correct 37 ms 10264 KB Output is correct
13 Correct 37 ms 10304 KB Output is correct
14 Correct 39 ms 10216 KB Output is correct
15 Correct 37 ms 10244 KB Output is correct
16 Correct 7 ms 2004 KB Output is correct
17 Correct 7 ms 2132 KB Output is correct
18 Correct 7 ms 2132 KB Output is correct
19 Correct 7 ms 2132 KB Output is correct
20 Correct 7 ms 2092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 10188 KB Output is correct
2 Correct 37 ms 10324 KB Output is correct
3 Correct 38 ms 10288 KB Output is correct
4 Correct 38 ms 10224 KB Output is correct
5 Correct 38 ms 10272 KB Output is correct
6 Correct 36 ms 10224 KB Output is correct
7 Correct 37 ms 10260 KB Output is correct
8 Correct 36 ms 10224 KB Output is correct
9 Correct 36 ms 10232 KB Output is correct
10 Correct 36 ms 10220 KB Output is correct
11 Correct 39 ms 10216 KB Output is correct
12 Correct 37 ms 10264 KB Output is correct
13 Correct 37 ms 10304 KB Output is correct
14 Correct 39 ms 10216 KB Output is correct
15 Correct 37 ms 10244 KB Output is correct
16 Correct 7 ms 2004 KB Output is correct
17 Correct 7 ms 2132 KB Output is correct
18 Correct 7 ms 2132 KB Output is correct
19 Correct 7 ms 2132 KB Output is correct
20 Correct 7 ms 2092 KB Output is correct
21 Correct 142 ms 7720 KB Output is correct
22 Correct 148 ms 7764 KB Output is correct
23 Correct 150 ms 7708 KB Output is correct
24 Correct 142 ms 7644 KB Output is correct
25 Correct 141 ms 7636 KB Output is correct
26 Correct 194 ms 7552 KB Output is correct
27 Correct 193 ms 7508 KB Output is correct
28 Correct 184 ms 7464 KB Output is correct
29 Correct 183 ms 7380 KB Output is correct
30 Correct 36 ms 11016 KB Output is correct
31 Correct 36 ms 11000 KB Output is correct
32 Correct 36 ms 11084 KB Output is correct
33 Correct 38 ms 11080 KB Output is correct
34 Correct 37 ms 11092 KB Output is correct
35 Correct 35 ms 10956 KB Output is correct
36 Correct 35 ms 10944 KB Output is correct
37 Correct 37 ms 11084 KB Output is correct
38 Correct 36 ms 10952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2268 KB Output is correct
2 Correct 6 ms 2248 KB Output is correct
3 Correct 6 ms 2244 KB Output is correct
4 Correct 7 ms 2260 KB Output is correct
5 Correct 6 ms 2260 KB Output is correct
6 Correct 7 ms 2260 KB Output is correct
7 Correct 7 ms 2260 KB Output is correct
8 Correct 7 ms 2260 KB Output is correct
9 Correct 8 ms 2252 KB Output is correct
10 Correct 8 ms 2208 KB Output is correct
11 Correct 6 ms 2260 KB Output is correct
12 Correct 6 ms 2260 KB Output is correct
13 Correct 6 ms 2132 KB Output is correct
14 Correct 6 ms 2260 KB Output is correct
15 Correct 6 ms 2256 KB Output is correct
16 Correct 3 ms 1364 KB Output is correct
17 Correct 3 ms 1352 KB Output is correct
18 Correct 4 ms 1364 KB Output is correct
19 Correct 3 ms 1352 KB Output is correct
20 Correct 3 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 10188 KB Output is correct
2 Correct 37 ms 10324 KB Output is correct
3 Correct 38 ms 10288 KB Output is correct
4 Correct 38 ms 10224 KB Output is correct
5 Correct 38 ms 10272 KB Output is correct
6 Correct 36 ms 10224 KB Output is correct
7 Correct 37 ms 10260 KB Output is correct
8 Correct 36 ms 10224 KB Output is correct
9 Correct 36 ms 10232 KB Output is correct
10 Correct 36 ms 10220 KB Output is correct
11 Correct 39 ms 10216 KB Output is correct
12 Correct 37 ms 10264 KB Output is correct
13 Correct 37 ms 10304 KB Output is correct
14 Correct 39 ms 10216 KB Output is correct
15 Correct 37 ms 10244 KB Output is correct
16 Correct 7 ms 2004 KB Output is correct
17 Correct 7 ms 2132 KB Output is correct
18 Correct 7 ms 2132 KB Output is correct
19 Correct 7 ms 2132 KB Output is correct
20 Correct 7 ms 2092 KB Output is correct
21 Correct 142 ms 7720 KB Output is correct
22 Correct 148 ms 7764 KB Output is correct
23 Correct 150 ms 7708 KB Output is correct
24 Correct 142 ms 7644 KB Output is correct
25 Correct 141 ms 7636 KB Output is correct
26 Correct 194 ms 7552 KB Output is correct
27 Correct 193 ms 7508 KB Output is correct
28 Correct 184 ms 7464 KB Output is correct
29 Correct 183 ms 7380 KB Output is correct
30 Correct 36 ms 11016 KB Output is correct
31 Correct 36 ms 11000 KB Output is correct
32 Correct 36 ms 11084 KB Output is correct
33 Correct 38 ms 11080 KB Output is correct
34 Correct 37 ms 11092 KB Output is correct
35 Correct 35 ms 10956 KB Output is correct
36 Correct 35 ms 10944 KB Output is correct
37 Correct 37 ms 11084 KB Output is correct
38 Correct 36 ms 10952 KB Output is correct
39 Correct 6 ms 2268 KB Output is correct
40 Correct 6 ms 2248 KB Output is correct
41 Correct 6 ms 2244 KB Output is correct
42 Correct 7 ms 2260 KB Output is correct
43 Correct 6 ms 2260 KB Output is correct
44 Correct 7 ms 2260 KB Output is correct
45 Correct 7 ms 2260 KB Output is correct
46 Correct 7 ms 2260 KB Output is correct
47 Correct 8 ms 2252 KB Output is correct
48 Correct 8 ms 2208 KB Output is correct
49 Correct 6 ms 2260 KB Output is correct
50 Correct 6 ms 2260 KB Output is correct
51 Correct 6 ms 2132 KB Output is correct
52 Correct 6 ms 2260 KB Output is correct
53 Correct 6 ms 2256 KB Output is correct
54 Correct 3 ms 1364 KB Output is correct
55 Correct 3 ms 1352 KB Output is correct
56 Correct 4 ms 1364 KB Output is correct
57 Correct 3 ms 1352 KB Output is correct
58 Correct 3 ms 1236 KB Output is correct
59 Correct 378 ms 16252 KB Output is correct
60 Correct 358 ms 16132 KB Output is correct
61 Correct 377 ms 16108 KB Output is correct
62 Correct 384 ms 16124 KB Output is correct
63 Correct 361 ms 16144 KB Output is correct
64 Correct 488 ms 15780 KB Output is correct
65 Correct 495 ms 15608 KB Output is correct
66 Correct 496 ms 15872 KB Output is correct
67 Correct 487 ms 15720 KB Output is correct
68 Correct 504 ms 15884 KB Output is correct
69 Correct 322 ms 15432 KB Output is correct
70 Correct 319 ms 15688 KB Output is correct
71 Correct 327 ms 15392 KB Output is correct
72 Correct 323 ms 15572 KB Output is correct
73 Correct 324 ms 15532 KB Output is correct
74 Correct 25 ms 2508 KB Output is correct
75 Correct 23 ms 2516 KB Output is correct
76 Correct 25 ms 2544 KB Output is correct
77 Correct 25 ms 2516 KB Output is correct
78 Correct 25 ms 2660 KB Output is correct