Submission #883085

# Submission time Handle Problem Language Result Execution time Memory
883085 2023-12-04T13:34:07 Z KN200711 Boat (APIO16_boat) C++14
9 / 100
69 ms 1080 KB
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;

const ll MOD = 1e9 + 7;

vector<int> seg[1100];
int l[1100], r[1100], len[1100];
bool V[501];
int num;

ll pref[1100], ad[1100], inv[1100];

ll fast(ll a, int b) {
	if(b == 0) return 1ll;
	if(b == 1) return a;
	ll K = fast(a, b / 2);
	K *= K;
	K %= MOD;
	if(b&1) {
		K *= a;
		K %= MOD;
	}
	return K;
}

void build() {
	inv[0] = 1;
	for(int i=1;i<1100;i++) {
		inv[i] = fast(i, MOD - 2);
	}
}

void fx(ll &a, ll c, ll d) {
	a *= c;
	a %= MOD;
	a *= inv[d];
	a %= MOD;
}

int main() {
	build();
	
	int N;
	scanf("%d", &N);
	
	vector< pair<int, int> > arr;
	arr.clear();
	for(int i=1;i<=N;i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		arr.push_back(make_pair(a, i));
		arr.push_back(make_pair(b + 1, -i));
	}
	sort(arr.begin(), arr.end());
	int lst;
	for(int i=0;i<arr.size();i++) {
		if(i > 0 && arr[i].fi != arr[i - 1].fi) {
			l[num] = lst;
			r[num] = arr[i].fi - 1;
			len[num] = r[num] - l[num] + 1;
			for(int k=1;k<=N;k++) {
				if(V[k]) seg[num].push_back(k);
			}
			num++;
		}
		if(arr[i].se < 0) V[-arr[i].se] = 0;
		else V[arr[i].se] = 1;
		lst = arr[i].fi;
	}
	
	for(int i=0;i<=N;i++) pref[i] = 1ll;
	for(int i=0;i<num;i++) {
	//	cout<<l[i]<<" "<<r[i]<<endl;
		for(int k=1;k<=N;k++) ad[k] = 0ll;
		for(int k=1;k<=seg[i].size();k++) {
			ll as = 0ll;
			if(k == 1) {
				as = len[i];
			} else if(len[i] >= 2) {
				ll v = 1ll;
				fx(v, len[i], 1ll);
				fx(v, len[i] - 1, 2ll);
				for(int c=0;;c++) {
					as += v;
					as %= MOD;
					if(len[i] < c + 2) break;
					if(k < c + 2) break;
					fx(v, len[i] - c - 2ll, c + 3ll);
					fx(v, k - c - 2ll, 1ll);
				}
			}
		//	cout<<"as : "<<i<<" "<<k<<" "<<as<<endl;
			for(int c=0;c+k-1<seg[i].size();c++) {
				ll D = as * pref[seg[i][c] - 1];
				D %= MOD;
				ad[seg[i][c + k - 1]] += D;
				ad[seg[i][c + k - 1]] %= MOD;
			}
		}
		ll kp = 0ll;
		for(int k = 1;k<=N;k++) {
		//	cout<<i<<" "<<k<<" "<<ad[k]<<endl;
			kp += ad[k];
			kp %= MOD;
			pref[k] += kp;
			pref[k] %= MOD;
		}
	}
	pref[N]--;
	if(pref[N] < 0) pref[N] += MOD;
	printf("%lld\n", pref[N]);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i=0;i<arr.size();i++) {
      |              ~^~~~~~~~~~~
boat.cpp:78:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for(int k=1;k<=seg[i].size();k++) {
      |               ~^~~~~~~~~~~~~~~
boat.cpp:96:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |    for(int c=0;c+k-1<seg[i].size();c++) {
      |                ~~~~~^~~~~~~~~~~~~~
boat.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
boat.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 388 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 484 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 388 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 484 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 524 KB Output is correct
21 Incorrect 69 ms 1080 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 3 ms 388 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 3 ms 484 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 524 KB Output is correct
21 Incorrect 69 ms 1080 KB Output isn't correct
22 Halted 0 ms 0 KB -