답안 #41837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41837 2018-02-21T11:25:58 Z IvanC Boat (APIO16_boat) C++14
100 / 100
1332 ms 6924 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],somatorio2[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));
		memset(somatorio2,0,sizeof(somatorio2));
		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 k = 2;k<=vaiate;k++){
				dp[i][k] = somatorio2[k-1];
			}
			dp2[i][v] = dp[i][1];
			somatorio2[1] += dp[i][1];
			somatorio2[1] %= MOD;
			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];
				somatorio2[k] += dp[i][k];
				somatorio2[k] %= MOD;
			}
			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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 4216 KB Output is correct
2 Correct 199 ms 4320 KB Output is correct
3 Correct 206 ms 4444 KB Output is correct
4 Correct 202 ms 4444 KB Output is correct
5 Correct 201 ms 4444 KB Output is correct
6 Correct 210 ms 4600 KB Output is correct
7 Correct 194 ms 4600 KB Output is correct
8 Correct 208 ms 4700 KB Output is correct
9 Correct 194 ms 4700 KB Output is correct
10 Correct 204 ms 4744 KB Output is correct
11 Correct 201 ms 4744 KB Output is correct
12 Correct 202 ms 4744 KB Output is correct
13 Correct 198 ms 4744 KB Output is correct
14 Correct 201 ms 4744 KB Output is correct
15 Correct 202 ms 4744 KB Output is correct
16 Correct 41 ms 4744 KB Output is correct
17 Correct 42 ms 4744 KB Output is correct
18 Correct 41 ms 4744 KB Output is correct
19 Correct 43 ms 4744 KB Output is correct
20 Correct 44 ms 4744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 4216 KB Output is correct
2 Correct 199 ms 4320 KB Output is correct
3 Correct 206 ms 4444 KB Output is correct
4 Correct 202 ms 4444 KB Output is correct
5 Correct 201 ms 4444 KB Output is correct
6 Correct 210 ms 4600 KB Output is correct
7 Correct 194 ms 4600 KB Output is correct
8 Correct 208 ms 4700 KB Output is correct
9 Correct 194 ms 4700 KB Output is correct
10 Correct 204 ms 4744 KB Output is correct
11 Correct 201 ms 4744 KB Output is correct
12 Correct 202 ms 4744 KB Output is correct
13 Correct 198 ms 4744 KB Output is correct
14 Correct 201 ms 4744 KB Output is correct
15 Correct 202 ms 4744 KB Output is correct
16 Correct 41 ms 4744 KB Output is correct
17 Correct 42 ms 4744 KB Output is correct
18 Correct 41 ms 4744 KB Output is correct
19 Correct 43 ms 4744 KB Output is correct
20 Correct 44 ms 4744 KB Output is correct
21 Correct 144 ms 5640 KB Output is correct
22 Correct 146 ms 5740 KB Output is correct
23 Correct 147 ms 5740 KB Output is correct
24 Correct 135 ms 5740 KB Output is correct
25 Correct 143 ms 5740 KB Output is correct
26 Correct 148 ms 6252 KB Output is correct
27 Correct 153 ms 6252 KB Output is correct
28 Correct 151 ms 6272 KB Output is correct
29 Correct 152 ms 6272 KB Output is correct
30 Correct 204 ms 6272 KB Output is correct
31 Correct 195 ms 6272 KB Output is correct
32 Correct 186 ms 6272 KB Output is correct
33 Correct 199 ms 6272 KB Output is correct
34 Correct 196 ms 6272 KB Output is correct
35 Correct 197 ms 6272 KB Output is correct
36 Correct 196 ms 6272 KB Output is correct
37 Correct 192 ms 6272 KB Output is correct
38 Correct 199 ms 6272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 6272 KB Output is correct
2 Correct 36 ms 6272 KB Output is correct
3 Correct 37 ms 6272 KB Output is correct
4 Correct 36 ms 6272 KB Output is correct
5 Correct 38 ms 6272 KB Output is correct
6 Correct 37 ms 6272 KB Output is correct
7 Correct 41 ms 6272 KB Output is correct
8 Correct 37 ms 6272 KB Output is correct
9 Correct 38 ms 6272 KB Output is correct
10 Correct 40 ms 6272 KB Output is correct
11 Correct 43 ms 6272 KB Output is correct
12 Correct 35 ms 6272 KB Output is correct
13 Correct 36 ms 6272 KB Output is correct
14 Correct 37 ms 6272 KB Output is correct
15 Correct 37 ms 6272 KB Output is correct
16 Correct 22 ms 6272 KB Output is correct
17 Correct 24 ms 6272 KB Output is correct
18 Correct 20 ms 6272 KB Output is correct
19 Correct 19 ms 6272 KB Output is correct
20 Correct 19 ms 6272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 4216 KB Output is correct
2 Correct 199 ms 4320 KB Output is correct
3 Correct 206 ms 4444 KB Output is correct
4 Correct 202 ms 4444 KB Output is correct
5 Correct 201 ms 4444 KB Output is correct
6 Correct 210 ms 4600 KB Output is correct
7 Correct 194 ms 4600 KB Output is correct
8 Correct 208 ms 4700 KB Output is correct
9 Correct 194 ms 4700 KB Output is correct
10 Correct 204 ms 4744 KB Output is correct
11 Correct 201 ms 4744 KB Output is correct
12 Correct 202 ms 4744 KB Output is correct
13 Correct 198 ms 4744 KB Output is correct
14 Correct 201 ms 4744 KB Output is correct
15 Correct 202 ms 4744 KB Output is correct
16 Correct 41 ms 4744 KB Output is correct
17 Correct 42 ms 4744 KB Output is correct
18 Correct 41 ms 4744 KB Output is correct
19 Correct 43 ms 4744 KB Output is correct
20 Correct 44 ms 4744 KB Output is correct
21 Correct 144 ms 5640 KB Output is correct
22 Correct 146 ms 5740 KB Output is correct
23 Correct 147 ms 5740 KB Output is correct
24 Correct 135 ms 5740 KB Output is correct
25 Correct 143 ms 5740 KB Output is correct
26 Correct 148 ms 6252 KB Output is correct
27 Correct 153 ms 6252 KB Output is correct
28 Correct 151 ms 6272 KB Output is correct
29 Correct 152 ms 6272 KB Output is correct
30 Correct 204 ms 6272 KB Output is correct
31 Correct 195 ms 6272 KB Output is correct
32 Correct 186 ms 6272 KB Output is correct
33 Correct 199 ms 6272 KB Output is correct
34 Correct 196 ms 6272 KB Output is correct
35 Correct 197 ms 6272 KB Output is correct
36 Correct 196 ms 6272 KB Output is correct
37 Correct 192 ms 6272 KB Output is correct
38 Correct 199 ms 6272 KB Output is correct
39 Correct 36 ms 6272 KB Output is correct
40 Correct 36 ms 6272 KB Output is correct
41 Correct 37 ms 6272 KB Output is correct
42 Correct 36 ms 6272 KB Output is correct
43 Correct 38 ms 6272 KB Output is correct
44 Correct 37 ms 6272 KB Output is correct
45 Correct 41 ms 6272 KB Output is correct
46 Correct 37 ms 6272 KB Output is correct
47 Correct 38 ms 6272 KB Output is correct
48 Correct 40 ms 6272 KB Output is correct
49 Correct 43 ms 6272 KB Output is correct
50 Correct 35 ms 6272 KB Output is correct
51 Correct 36 ms 6272 KB Output is correct
52 Correct 37 ms 6272 KB Output is correct
53 Correct 37 ms 6272 KB Output is correct
54 Correct 22 ms 6272 KB Output is correct
55 Correct 24 ms 6272 KB Output is correct
56 Correct 20 ms 6272 KB Output is correct
57 Correct 19 ms 6272 KB Output is correct
58 Correct 19 ms 6272 KB Output is correct
59 Correct 991 ms 6272 KB Output is correct
60 Correct 940 ms 6272 KB Output is correct
61 Correct 898 ms 6272 KB Output is correct
62 Correct 957 ms 6272 KB Output is correct
63 Correct 951 ms 6272 KB Output is correct
64 Correct 1332 ms 6924 KB Output is correct
65 Correct 1273 ms 6924 KB Output is correct
66 Correct 1255 ms 6924 KB Output is correct
67 Correct 1278 ms 6924 KB Output is correct
68 Correct 1268 ms 6924 KB Output is correct
69 Correct 896 ms 6924 KB Output is correct
70 Correct 919 ms 6924 KB Output is correct
71 Correct 909 ms 6924 KB Output is correct
72 Correct 956 ms 6924 KB Output is correct
73 Correct 942 ms 6924 KB Output is correct
74 Correct 108 ms 6924 KB Output is correct
75 Correct 113 ms 6924 KB Output is correct
76 Correct 123 ms 6924 KB Output is correct
77 Correct 111 ms 6924 KB Output is correct
78 Correct 118 ms 6924 KB Output is correct