답안 #41836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41836 2018-02-21T11:24:06 Z IvanC Boat (APIO16_boat) C++14
9 / 100
216 ms 5612 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];
			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 213 ms 4316 KB Output is correct
2 Correct 208 ms 4316 KB Output is correct
3 Correct 204 ms 4316 KB Output is correct
4 Correct 197 ms 4316 KB Output is correct
5 Correct 201 ms 4368 KB Output is correct
6 Correct 204 ms 4368 KB Output is correct
7 Correct 205 ms 4572 KB Output is correct
8 Correct 199 ms 4728 KB Output is correct
9 Correct 216 ms 4728 KB Output is correct
10 Correct 195 ms 4728 KB Output is correct
11 Correct 211 ms 4728 KB Output is correct
12 Correct 203 ms 4728 KB Output is correct
13 Correct 201 ms 4728 KB Output is correct
14 Correct 195 ms 4728 KB Output is correct
15 Correct 204 ms 4728 KB Output is correct
16 Correct 41 ms 4728 KB Output is correct
17 Correct 42 ms 4728 KB Output is correct
18 Correct 42 ms 4728 KB Output is correct
19 Correct 41 ms 4728 KB Output is correct
20 Correct 41 ms 4728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 4316 KB Output is correct
2 Correct 208 ms 4316 KB Output is correct
3 Correct 204 ms 4316 KB Output is correct
4 Correct 197 ms 4316 KB Output is correct
5 Correct 201 ms 4368 KB Output is correct
6 Correct 204 ms 4368 KB Output is correct
7 Correct 205 ms 4572 KB Output is correct
8 Correct 199 ms 4728 KB Output is correct
9 Correct 216 ms 4728 KB Output is correct
10 Correct 195 ms 4728 KB Output is correct
11 Correct 211 ms 4728 KB Output is correct
12 Correct 203 ms 4728 KB Output is correct
13 Correct 201 ms 4728 KB Output is correct
14 Correct 195 ms 4728 KB Output is correct
15 Correct 204 ms 4728 KB Output is correct
16 Correct 41 ms 4728 KB Output is correct
17 Correct 42 ms 4728 KB Output is correct
18 Correct 42 ms 4728 KB Output is correct
19 Correct 41 ms 4728 KB Output is correct
20 Correct 41 ms 4728 KB Output is correct
21 Incorrect 137 ms 5612 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 5612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 4316 KB Output is correct
2 Correct 208 ms 4316 KB Output is correct
3 Correct 204 ms 4316 KB Output is correct
4 Correct 197 ms 4316 KB Output is correct
5 Correct 201 ms 4368 KB Output is correct
6 Correct 204 ms 4368 KB Output is correct
7 Correct 205 ms 4572 KB Output is correct
8 Correct 199 ms 4728 KB Output is correct
9 Correct 216 ms 4728 KB Output is correct
10 Correct 195 ms 4728 KB Output is correct
11 Correct 211 ms 4728 KB Output is correct
12 Correct 203 ms 4728 KB Output is correct
13 Correct 201 ms 4728 KB Output is correct
14 Correct 195 ms 4728 KB Output is correct
15 Correct 204 ms 4728 KB Output is correct
16 Correct 41 ms 4728 KB Output is correct
17 Correct 42 ms 4728 KB Output is correct
18 Correct 42 ms 4728 KB Output is correct
19 Correct 41 ms 4728 KB Output is correct
20 Correct 41 ms 4728 KB Output is correct
21 Incorrect 137 ms 5612 KB Output isn't correct
22 Halted 0 ms 0 KB -