Submission #673405

# Submission time Handle Problem Language Result Execution time Memory
673405 2022-12-20T13:58:52 Z S2speed Boat (APIO16_boat) C++17
9 / 100
117 ms 8320 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] , pd[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();
	}
	fill(pd , pd + vs - 1 , 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 > 1 ; 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;
			}
			ll o = pd[j] * f[j][1] % md;
			dp[j][1] += o; dp[j][1] -= (dp[j][1] >= md) * md;
			h += o;
			for(ll k = j + 1 ; k < vs ; k++){
				pd[k] += h; pd[k] %= md;
			}
		}
	}
	ll ans = pd[vs - 1];
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 8268 KB Output is correct
2 Correct 35 ms 8216 KB Output is correct
3 Correct 37 ms 8204 KB Output is correct
4 Correct 37 ms 8248 KB Output is correct
5 Correct 38 ms 8320 KB Output is correct
6 Correct 37 ms 8276 KB Output is correct
7 Correct 36 ms 8264 KB Output is correct
8 Correct 36 ms 8212 KB Output is correct
9 Correct 36 ms 8296 KB Output is correct
10 Correct 37 ms 8208 KB Output is correct
11 Correct 37 ms 8304 KB Output is correct
12 Correct 37 ms 8268 KB Output is correct
13 Correct 37 ms 8204 KB Output is correct
14 Correct 37 ms 8220 KB Output is correct
15 Correct 36 ms 8268 KB Output is correct
16 Correct 7 ms 1724 KB Output is correct
17 Correct 8 ms 1876 KB Output is correct
18 Correct 7 ms 1748 KB Output is correct
19 Correct 8 ms 1876 KB Output is correct
20 Correct 7 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 8268 KB Output is correct
2 Correct 35 ms 8216 KB Output is correct
3 Correct 37 ms 8204 KB Output is correct
4 Correct 37 ms 8248 KB Output is correct
5 Correct 38 ms 8320 KB Output is correct
6 Correct 37 ms 8276 KB Output is correct
7 Correct 36 ms 8264 KB Output is correct
8 Correct 36 ms 8212 KB Output is correct
9 Correct 36 ms 8296 KB Output is correct
10 Correct 37 ms 8208 KB Output is correct
11 Correct 37 ms 8304 KB Output is correct
12 Correct 37 ms 8268 KB Output is correct
13 Correct 37 ms 8204 KB Output is correct
14 Correct 37 ms 8220 KB Output is correct
15 Correct 36 ms 8268 KB Output is correct
16 Correct 7 ms 1724 KB Output is correct
17 Correct 8 ms 1876 KB Output is correct
18 Correct 7 ms 1748 KB Output is correct
19 Correct 8 ms 1876 KB Output is correct
20 Correct 7 ms 1748 KB Output is correct
21 Incorrect 117 ms 7848 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 2260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 8268 KB Output is correct
2 Correct 35 ms 8216 KB Output is correct
3 Correct 37 ms 8204 KB Output is correct
4 Correct 37 ms 8248 KB Output is correct
5 Correct 38 ms 8320 KB Output is correct
6 Correct 37 ms 8276 KB Output is correct
7 Correct 36 ms 8264 KB Output is correct
8 Correct 36 ms 8212 KB Output is correct
9 Correct 36 ms 8296 KB Output is correct
10 Correct 37 ms 8208 KB Output is correct
11 Correct 37 ms 8304 KB Output is correct
12 Correct 37 ms 8268 KB Output is correct
13 Correct 37 ms 8204 KB Output is correct
14 Correct 37 ms 8220 KB Output is correct
15 Correct 36 ms 8268 KB Output is correct
16 Correct 7 ms 1724 KB Output is correct
17 Correct 8 ms 1876 KB Output is correct
18 Correct 7 ms 1748 KB Output is correct
19 Correct 8 ms 1876 KB Output is correct
20 Correct 7 ms 1748 KB Output is correct
21 Incorrect 117 ms 7848 KB Output isn't correct
22 Halted 0 ms 0 KB -