답안 #363133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
363133 2021-02-05T06:40:31 Z alireza_kaviani Boat (APIO16_boat) C++11
27 / 100
41 ms 1260 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)						(x).begin(),(x).end()
#define X							first
#define Y							second
#define sep							' '
#define endl						'\n'
#define SZ(x)						ll(x.size())

const ll MAXN = 500 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; //998244353; //1e9 + 9;

ll n , L[MAXN] , R[MAXN] , dp[MAXN][MAXN] , ps[MAXN] , inv[MAXN];
vector<int> compress = {0};

ll poww(ll a , ll b){
	ll ans = 1;
	for( ; b ; b /= 2 , a = a * a % MOD)	if(b & 1)	ans = ans * a % MOD;
	return ans;
}

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

	for(int i = 1 ; i < MAXN ; i++)	inv[i] = poww(i , MOD - 2);
//	for(int i = 1 ; i <= 5 ; i++)	cout << i << sep << inv[i] << endl;
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> L[i] >> R[i]; R[i]++;
		compress.push_back(L[i]);
		compress.push_back(R[i]);
	}
	sort(all(compress));
	compress.resize(unique(all(compress)) - compress.begin());
	dp[0][0] = 1; fill(ps , ps + MAXN , 1);
	for(int i = 1 ; i <= n ; i++){
		L[i] = lower_bound(all(compress) , L[i]) - compress.begin();
		R[i] = lower_bound(all(compress) , R[i]) - compress.begin();
		for(int j = L[i] ; j < R[i] ; j++){
			int len = compress[j + 1] - compress[j];
			for(int k = MAXN - 1 ; k >= 2 ; k--){
				dp[j][k] = (dp[j][k] + dp[j][k - 1] * (len - k + 1) % MOD * inv[k]) % MOD;
			}
			dp[j][1] = (dp[j][1] + ps[j - 1] * len) % MOD;
		}
		ps[0] = dp[0][0];
		for(int j = 1 ; j < MAXN ; j++){
			ps[j] = ps[j - 1];
			for(int k = 0 ; k < MAXN ; k++){
				ps[j] = (ps[j] + dp[j][k]);
			}
			ps[j] %= MOD;
		}
	}
	cout << (ps[MAXN - 1] + MOD - 1) % MOD << endl;

    return 0;
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1132 KB Output is correct
2 Correct 28 ms 1132 KB Output is correct
3 Correct 32 ms 1132 KB Output is correct
4 Correct 32 ms 1132 KB Output is correct
5 Correct 32 ms 1132 KB Output is correct
6 Correct 39 ms 1132 KB Output is correct
7 Correct 41 ms 1132 KB Output is correct
8 Correct 38 ms 1152 KB Output is correct
9 Correct 39 ms 1132 KB Output is correct
10 Correct 39 ms 1132 KB Output is correct
11 Correct 38 ms 1132 KB Output is correct
12 Correct 33 ms 1132 KB Output is correct
13 Correct 30 ms 1132 KB Output is correct
14 Correct 31 ms 1260 KB Output is correct
15 Correct 33 ms 1132 KB Output is correct
16 Correct 26 ms 876 KB Output is correct
17 Correct 25 ms 748 KB Output is correct
18 Correct 31 ms 748 KB Output is correct
19 Correct 25 ms 876 KB Output is correct
20 Correct 25 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -