답안 #981165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
981165 2024-05-13T00:56:28 Z hmm789 Boat (APIO16_boat) C++17
9 / 100
2000 ms 8536 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 inv(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], ans = 0;
	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 = 0; k < i; 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:35: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]
   35 |  for(int i = 0; i < v.size(); i++) {
      |                 ~~^~~~~~~~~~
boat.cpp:38: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]
   38 |   if(i != v.size()-1 && v[i].first != v[i+1].first) {
      |      ~~^~~~~~~~~~~~~
boat.cpp:47: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]
   47 |  for(int i = 0; i < v.size(); i++) pref[0][i] = 1;
      |                 ~~^~~~~~~~~~
boat.cpp:49: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]
   49 |   for(int j = 1; j < v.size(); j++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 8280 KB Output is correct
2 Correct 30 ms 8360 KB Output is correct
3 Correct 31 ms 8284 KB Output is correct
4 Correct 32 ms 8532 KB Output is correct
5 Correct 31 ms 8340 KB Output is correct
6 Correct 30 ms 8280 KB Output is correct
7 Correct 30 ms 8284 KB Output is correct
8 Correct 30 ms 8280 KB Output is correct
9 Correct 31 ms 8280 KB Output is correct
10 Correct 30 ms 8284 KB Output is correct
11 Correct 30 ms 8280 KB Output is correct
12 Correct 30 ms 8284 KB Output is correct
13 Correct 31 ms 8280 KB Output is correct
14 Correct 30 ms 8284 KB Output is correct
15 Correct 30 ms 8284 KB Output is correct
16 Correct 30 ms 8332 KB Output is correct
17 Correct 31 ms 8280 KB Output is correct
18 Correct 30 ms 8280 KB Output is correct
19 Correct 30 ms 8536 KB Output is correct
20 Correct 31 ms 8360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 8280 KB Output is correct
2 Correct 30 ms 8360 KB Output is correct
3 Correct 31 ms 8284 KB Output is correct
4 Correct 32 ms 8532 KB Output is correct
5 Correct 31 ms 8340 KB Output is correct
6 Correct 30 ms 8280 KB Output is correct
7 Correct 30 ms 8284 KB Output is correct
8 Correct 30 ms 8280 KB Output is correct
9 Correct 31 ms 8280 KB Output is correct
10 Correct 30 ms 8284 KB Output is correct
11 Correct 30 ms 8280 KB Output is correct
12 Correct 30 ms 8284 KB Output is correct
13 Correct 31 ms 8280 KB Output is correct
14 Correct 30 ms 8284 KB Output is correct
15 Correct 30 ms 8284 KB Output is correct
16 Correct 30 ms 8332 KB Output is correct
17 Correct 31 ms 8280 KB Output is correct
18 Correct 30 ms 8280 KB Output is correct
19 Correct 30 ms 8536 KB Output is correct
20 Correct 31 ms 8360 KB Output is correct
21 Execution timed out 2074 ms 8284 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 8280 KB Output is correct
2 Correct 30 ms 8360 KB Output is correct
3 Correct 31 ms 8284 KB Output is correct
4 Correct 32 ms 8532 KB Output is correct
5 Correct 31 ms 8340 KB Output is correct
6 Correct 30 ms 8280 KB Output is correct
7 Correct 30 ms 8284 KB Output is correct
8 Correct 30 ms 8280 KB Output is correct
9 Correct 31 ms 8280 KB Output is correct
10 Correct 30 ms 8284 KB Output is correct
11 Correct 30 ms 8280 KB Output is correct
12 Correct 30 ms 8284 KB Output is correct
13 Correct 31 ms 8280 KB Output is correct
14 Correct 30 ms 8284 KB Output is correct
15 Correct 30 ms 8284 KB Output is correct
16 Correct 30 ms 8332 KB Output is correct
17 Correct 31 ms 8280 KB Output is correct
18 Correct 30 ms 8280 KB Output is correct
19 Correct 30 ms 8536 KB Output is correct
20 Correct 31 ms 8360 KB Output is correct
21 Execution timed out 2074 ms 8284 KB Time limit exceeded
22 Halted 0 ms 0 KB -