Submission #41835

# Submission time Handle Problem Language Result Execution time Memory
41835 2018-02-21T11:22:14 Z IvanC Boat (APIO16_boat) C++14
58 / 100
2000 ms 6508 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 501;
const ll MOD = 1e9 + 7;
ll dp[MAXN][MAXN],dp2[MAXN][2*MAXN],somatorio1[MAXN];
ll precalc[MAXN],A[MAXN],B[MAXN],N,M;
vector<ll> intervalos;
ll binary_expo(ll val,ll pot){
	if(pot == 0) return 1LL;
	if(pot % 2 == 0){
		ll davez = binary_expo(val,pot/2);
		return (davez*davez) % MOD;
	} 
	return (val*binary_expo(val,pot-1)) % MOD;
}
int main(){
	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> A[i] >> B[i];
		B[i]++;
		intervalos.push_back(A[i]);
		intervalos.push_back(B[i]); 
	}
	sort(intervalos.begin(),intervalos.end());
	intervalos.erase(unique(intervalos.begin(),intervalos.end()),intervalos.end());
	M = intervalos.size() - 2;
	ll tot = 0;
	for(int v = M;v>=0;v--){
		memset(dp,0,sizeof(dp));
		ll tam = intervalos[v+1] - intervalos[v];
		ll vaiate = min(tam,N);
		for(ll i = 2;i<=vaiate;i++){
			precalc[i] = (tam - i + 1)*binary_expo(i,MOD-2);
			precalc[i] %= MOD;
		}
		for(ll i = N;i>=1;i--){
			if(!(A[i] <= intervalos[v] && intervalos[v+1] <= B[i] )) continue;
			dp[i][1] = 1;
			for(ll j = i+1;j<=N;j++){
				dp[i][1] += somatorio1[j];
			}
			dp[i][1] %= MOD;
			dp[i][1] = (dp[i][1] * tam) % MOD;
			for(ll j = i + 1;j<=N;j++){
				for(ll k = 2;k<=vaiate;k++){
					dp[i][k] += dp[j][k-1];
				}
			}
			dp2[i][v] = dp[i][1];
			for(ll k = 2;k<=vaiate;k++){
				dp[i][k] %= MOD;
				dp[i][k] *= precalc[k];
				dp[i][k] %= MOD;
				dp2[i][v] += dp[i][k];
			}
			dp2[i][v] %= MOD;
			tot += dp2[i][v];
			tot %= MOD;
		}
		for(int i = 1;i<=N;i++){
			somatorio1[i] += dp2[i][v];
			somatorio1[i] %= MOD;
		}
	}
	cout << tot << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 211 ms 4216 KB Output is correct
2 Correct 207 ms 4448 KB Output is correct
3 Correct 204 ms 4448 KB Output is correct
4 Correct 204 ms 4448 KB Output is correct
5 Correct 210 ms 4448 KB Output is correct
6 Correct 208 ms 4448 KB Output is correct
7 Correct 203 ms 4448 KB Output is correct
8 Correct 210 ms 4572 KB Output is correct
9 Correct 210 ms 4572 KB Output is correct
10 Correct 206 ms 4572 KB Output is correct
11 Correct 206 ms 4572 KB Output is correct
12 Correct 209 ms 4572 KB Output is correct
13 Correct 207 ms 4644 KB Output is correct
14 Correct 202 ms 4644 KB Output is correct
15 Correct 203 ms 4644 KB Output is correct
16 Correct 41 ms 4644 KB Output is correct
17 Correct 43 ms 4644 KB Output is correct
18 Correct 43 ms 4644 KB Output is correct
19 Correct 44 ms 4644 KB Output is correct
20 Correct 44 ms 4644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 4216 KB Output is correct
2 Correct 207 ms 4448 KB Output is correct
3 Correct 204 ms 4448 KB Output is correct
4 Correct 204 ms 4448 KB Output is correct
5 Correct 210 ms 4448 KB Output is correct
6 Correct 208 ms 4448 KB Output is correct
7 Correct 203 ms 4448 KB Output is correct
8 Correct 210 ms 4572 KB Output is correct
9 Correct 210 ms 4572 KB Output is correct
10 Correct 206 ms 4572 KB Output is correct
11 Correct 206 ms 4572 KB Output is correct
12 Correct 209 ms 4572 KB Output is correct
13 Correct 207 ms 4644 KB Output is correct
14 Correct 202 ms 4644 KB Output is correct
15 Correct 203 ms 4644 KB Output is correct
16 Correct 41 ms 4644 KB Output is correct
17 Correct 43 ms 4644 KB Output is correct
18 Correct 43 ms 4644 KB Output is correct
19 Correct 44 ms 4644 KB Output is correct
20 Correct 44 ms 4644 KB Output is correct
21 Correct 360 ms 5624 KB Output is correct
22 Correct 382 ms 5624 KB Output is correct
23 Correct 363 ms 5624 KB Output is correct
24 Correct 397 ms 5748 KB Output is correct
25 Correct 384 ms 5932 KB Output is correct
26 Correct 399 ms 6388 KB Output is correct
27 Correct 389 ms 6404 KB Output is correct
28 Correct 396 ms 6508 KB Output is correct
29 Correct 400 ms 6508 KB Output is correct
30 Correct 246 ms 6508 KB Output is correct
31 Correct 240 ms 6508 KB Output is correct
32 Correct 241 ms 6508 KB Output is correct
33 Correct 242 ms 6508 KB Output is correct
34 Correct 242 ms 6508 KB Output is correct
35 Correct 231 ms 6508 KB Output is correct
36 Correct 237 ms 6508 KB Output is correct
37 Correct 246 ms 6508 KB Output is correct
38 Correct 236 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 6508 KB Output is correct
2 Correct 59 ms 6508 KB Output is correct
3 Correct 68 ms 6508 KB Output is correct
4 Correct 70 ms 6508 KB Output is correct
5 Correct 65 ms 6508 KB Output is correct
6 Correct 80 ms 6508 KB Output is correct
7 Correct 83 ms 6508 KB Output is correct
8 Correct 77 ms 6508 KB Output is correct
9 Correct 77 ms 6508 KB Output is correct
10 Correct 79 ms 6508 KB Output is correct
11 Correct 77 ms 6508 KB Output is correct
12 Correct 79 ms 6508 KB Output is correct
13 Correct 86 ms 6508 KB Output is correct
14 Correct 71 ms 6508 KB Output is correct
15 Correct 65 ms 6508 KB Output is correct
16 Correct 40 ms 6508 KB Output is correct
17 Correct 33 ms 6508 KB Output is correct
18 Correct 30 ms 6508 KB Output is correct
19 Correct 32 ms 6508 KB Output is correct
20 Correct 33 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 4216 KB Output is correct
2 Correct 207 ms 4448 KB Output is correct
3 Correct 204 ms 4448 KB Output is correct
4 Correct 204 ms 4448 KB Output is correct
5 Correct 210 ms 4448 KB Output is correct
6 Correct 208 ms 4448 KB Output is correct
7 Correct 203 ms 4448 KB Output is correct
8 Correct 210 ms 4572 KB Output is correct
9 Correct 210 ms 4572 KB Output is correct
10 Correct 206 ms 4572 KB Output is correct
11 Correct 206 ms 4572 KB Output is correct
12 Correct 209 ms 4572 KB Output is correct
13 Correct 207 ms 4644 KB Output is correct
14 Correct 202 ms 4644 KB Output is correct
15 Correct 203 ms 4644 KB Output is correct
16 Correct 41 ms 4644 KB Output is correct
17 Correct 43 ms 4644 KB Output is correct
18 Correct 43 ms 4644 KB Output is correct
19 Correct 44 ms 4644 KB Output is correct
20 Correct 44 ms 4644 KB Output is correct
21 Correct 360 ms 5624 KB Output is correct
22 Correct 382 ms 5624 KB Output is correct
23 Correct 363 ms 5624 KB Output is correct
24 Correct 397 ms 5748 KB Output is correct
25 Correct 384 ms 5932 KB Output is correct
26 Correct 399 ms 6388 KB Output is correct
27 Correct 389 ms 6404 KB Output is correct
28 Correct 396 ms 6508 KB Output is correct
29 Correct 400 ms 6508 KB Output is correct
30 Correct 246 ms 6508 KB Output is correct
31 Correct 240 ms 6508 KB Output is correct
32 Correct 241 ms 6508 KB Output is correct
33 Correct 242 ms 6508 KB Output is correct
34 Correct 242 ms 6508 KB Output is correct
35 Correct 231 ms 6508 KB Output is correct
36 Correct 237 ms 6508 KB Output is correct
37 Correct 246 ms 6508 KB Output is correct
38 Correct 236 ms 6508 KB Output is correct
39 Correct 67 ms 6508 KB Output is correct
40 Correct 59 ms 6508 KB Output is correct
41 Correct 68 ms 6508 KB Output is correct
42 Correct 70 ms 6508 KB Output is correct
43 Correct 65 ms 6508 KB Output is correct
44 Correct 80 ms 6508 KB Output is correct
45 Correct 83 ms 6508 KB Output is correct
46 Correct 77 ms 6508 KB Output is correct
47 Correct 77 ms 6508 KB Output is correct
48 Correct 79 ms 6508 KB Output is correct
49 Correct 77 ms 6508 KB Output is correct
50 Correct 79 ms 6508 KB Output is correct
51 Correct 86 ms 6508 KB Output is correct
52 Correct 71 ms 6508 KB Output is correct
53 Correct 65 ms 6508 KB Output is correct
54 Correct 40 ms 6508 KB Output is correct
55 Correct 33 ms 6508 KB Output is correct
56 Correct 30 ms 6508 KB Output is correct
57 Correct 32 ms 6508 KB Output is correct
58 Correct 33 ms 6508 KB Output is correct
59 Execution timed out 2020 ms 6508 KB Time limit exceeded
60 Halted 0 ms 0 KB -