답안 #981168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
981168 2024-05-13T01:02:21 Z hmm789 Boat (APIO16_boat) C++14
9 / 100
380 ms 8360 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define MOD 1000000007

int pwr(int x, int n) {
	if(n == 0) return 1;
	if(n == 1) return x;
	int h = pwr(x, n/2);
	if(n%2 == 0) return h*h%MOD;
	else return h*h%MOD*x%MOD;
}

int inv2(int x) {
	return pwr(x, MOD-2);
}


int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	// regions [l, r)
	vector<pair<int, int>> v;
	vector<int> len;
	int a[n+1], b[n+1], inv[n+1], ans = 0;
	for(int i = 1; i <= n; i++) inv[i] = inv2(i);
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		v.push_back({a[i], i});
		v.push_back({b[i]+1, i+n});
	}
	v.push_back({0, 0});
	sort(v.begin(), v.end());
	int cnt = 0;
	for(int i = 0; i < v.size(); i++) {
		if(v[i].second <= n) a[v[i].second] = cnt;
		else b[v[i].second-n] = cnt-1;
		if(i != v.size()-1 && v[i].first != v[i+1].first) {
			len.push_back(v[i+1].first-v[i].first);
			cnt++;
		}
	}
	int dp[n+1][v.size()], pref[n+1][v.size()];
	memset(dp, 0, sizeof(dp));
	memset(pref, 0, sizeof(pref));
	dp[0][0] = 1;
	for(int i = 0; i < v.size(); i++) pref[0][i] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j < v.size(); j++) {
			if(j >= a[i] && j <= b[i]) {
				int c = 1;
				for(int k = i-1; k >= 0; k--) {
					c = c*(len[j]+i-k-1)%MOD * inv[i-k]%MOD;
					dp[i][j] += pref[k][j-1] * c % MOD;
					dp[i][j] %= MOD;
				}
			}
			pref[i][j] = pref[i][j-1]+dp[i][j];
			ans = (ans+dp[i][j]) % MOD;
		}
	}
	cout << ans;
}

Compilation message

boat.cpp: In function 'int32_t main()':
boat.cpp:37:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i = 0; i < v.size(); i++) {
      |                 ~~^~~~~~~~~~
boat.cpp:40:8: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   if(i != v.size()-1 && v[i].first != v[i+1].first) {
      |      ~~^~~~~~~~~~~~~
boat.cpp:49:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i = 0; i < v.size(); i++) pref[0][i] = 1;
      |                 ~~^~~~~~~~~~
boat.cpp:51:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j = 1; j < v.size(); j++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8284 KB Output is correct
2 Correct 9 ms 8284 KB Output is correct
3 Correct 8 ms 8284 KB Output is correct
4 Correct 8 ms 8284 KB Output is correct
5 Correct 8 ms 8284 KB Output is correct
6 Correct 8 ms 8284 KB Output is correct
7 Correct 8 ms 8284 KB Output is correct
8 Correct 8 ms 8284 KB Output is correct
9 Correct 10 ms 8352 KB Output is correct
10 Correct 8 ms 8284 KB Output is correct
11 Correct 8 ms 8360 KB Output is correct
12 Correct 7 ms 8284 KB Output is correct
13 Correct 7 ms 8176 KB Output is correct
14 Correct 8 ms 8284 KB Output is correct
15 Correct 8 ms 8284 KB Output is correct
16 Correct 8 ms 8340 KB Output is correct
17 Correct 8 ms 8284 KB Output is correct
18 Correct 8 ms 8284 KB Output is correct
19 Correct 8 ms 8324 KB Output is correct
20 Correct 8 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8284 KB Output is correct
2 Correct 9 ms 8284 KB Output is correct
3 Correct 8 ms 8284 KB Output is correct
4 Correct 8 ms 8284 KB Output is correct
5 Correct 8 ms 8284 KB Output is correct
6 Correct 8 ms 8284 KB Output is correct
7 Correct 8 ms 8284 KB Output is correct
8 Correct 8 ms 8284 KB Output is correct
9 Correct 10 ms 8352 KB Output is correct
10 Correct 8 ms 8284 KB Output is correct
11 Correct 8 ms 8360 KB Output is correct
12 Correct 7 ms 8284 KB Output is correct
13 Correct 7 ms 8176 KB Output is correct
14 Correct 8 ms 8284 KB Output is correct
15 Correct 8 ms 8284 KB Output is correct
16 Correct 8 ms 8340 KB Output is correct
17 Correct 8 ms 8284 KB Output is correct
18 Correct 8 ms 8284 KB Output is correct
19 Correct 8 ms 8324 KB Output is correct
20 Correct 8 ms 8284 KB Output is correct
21 Incorrect 380 ms 8348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8284 KB Output is correct
2 Correct 9 ms 8284 KB Output is correct
3 Correct 8 ms 8284 KB Output is correct
4 Correct 8 ms 8284 KB Output is correct
5 Correct 8 ms 8284 KB Output is correct
6 Correct 8 ms 8284 KB Output is correct
7 Correct 8 ms 8284 KB Output is correct
8 Correct 8 ms 8284 KB Output is correct
9 Correct 10 ms 8352 KB Output is correct
10 Correct 8 ms 8284 KB Output is correct
11 Correct 8 ms 8360 KB Output is correct
12 Correct 7 ms 8284 KB Output is correct
13 Correct 7 ms 8176 KB Output is correct
14 Correct 8 ms 8284 KB Output is correct
15 Correct 8 ms 8284 KB Output is correct
16 Correct 8 ms 8340 KB Output is correct
17 Correct 8 ms 8284 KB Output is correct
18 Correct 8 ms 8284 KB Output is correct
19 Correct 8 ms 8324 KB Output is correct
20 Correct 8 ms 8284 KB Output is correct
21 Incorrect 380 ms 8348 KB Output isn't correct
22 Halted 0 ms 0 KB -