Submission #362538

# Submission time Handle Problem Language Result Execution time Memory
362538 2021-02-03T15:09:47 Z flappybird Boat (APIO16_boat) C++14
31 / 100
857 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;
#define MAX 1010101
#define all(v) v.begin(), v.end()
#define ln '\n'
#define MOD 1000000007
#define INF 210000000000
#define pb push_back
#define abs(x) (((x)>0)?(x):(-(x)))
#define len(x) ((x).second-(x).first)
typedef long long ll;
ll A[MAX], B[MAX];
vector<ll> v, num;
ll dp[MAX];
ll find(ll x) {
	ll l, r;
	l = 0;
	r = num.size();
	ll mid;
	while (l < r) {
		mid = (l + r) / 2;
		if (num[mid] == x) break;
		if (num[mid] > x) r = mid;
		if (num[mid] < x) l = mid + 1;
	}
	if (num[mid] == x) return mid;
	if (num[l] == x) return l;
	return -1;
}
int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	ll i, j, k;
	ll a, b;
	ll sum;
	dp[0] = 1;
	ll it;
	for (i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		for (j = A[i]; j <= B[i]; j++) v.pb(j);
	}
	sort(all(v));
	v.push_back(MOD);
	num.pb(0);
	for (i = 0; i < v.size() - 1; i++) {
		if (v[i] != v[i + 1]) num.pb(v[i]);
	}
	ll sz = num.size();
	for (i = 1; i <= N; i++) {
		a = A[i];
		b = B[i];
		sum = 0;
		for (it = 0; it < sz; it++) {
			if (num[it] >= a) break;
			sum += dp[it];
			sum %= MOD;
		}
		it = find(a);
		for (j = it; j <= b - a + it; j++) {
			sum += dp[j];
			sum %= MOD;
			dp[j] = sum;
		}
	}
	sum = 0;
	for (it = 1; it < sz; it++) sum += dp[it], sum %= MOD;
	while (sum < 0) sum += MOD;
	cout << sum << ln;
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:47:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for (i = 0; i < v.size() - 1; i++) {
      |              ~~^~~~~~~~~~~~~~
boat.cpp:35:11: warning: unused variable 'k' [-Wunused-variable]
   35 |  ll i, j, k;
      |           ^
boat.cpp: In function 'll find(ll)':
boat.cpp:26:13: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |  if (num[mid] == x) return mid;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 52 ms 8672 KB Output is correct
22 Correct 53 ms 8672 KB Output is correct
23 Correct 50 ms 8800 KB Output is correct
24 Correct 54 ms 8672 KB Output is correct
25 Correct 54 ms 8692 KB Output is correct
26 Correct 64 ms 8672 KB Output is correct
27 Correct 55 ms 8672 KB Output is correct
28 Correct 60 ms 8672 KB Output is correct
29 Correct 55 ms 8672 KB Output is correct
30 Correct 816 ms 23896 KB Output is correct
31 Correct 826 ms 23492 KB Output is correct
32 Correct 823 ms 23876 KB Output is correct
33 Correct 824 ms 23288 KB Output is correct
34 Correct 842 ms 23620 KB Output is correct
35 Correct 817 ms 22340 KB Output is correct
36 Correct 806 ms 23108 KB Output is correct
37 Correct 857 ms 23364 KB Output is correct
38 Correct 838 ms 22724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 547 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 52 ms 8672 KB Output is correct
22 Correct 53 ms 8672 KB Output is correct
23 Correct 50 ms 8800 KB Output is correct
24 Correct 54 ms 8672 KB Output is correct
25 Correct 54 ms 8692 KB Output is correct
26 Correct 64 ms 8672 KB Output is correct
27 Correct 55 ms 8672 KB Output is correct
28 Correct 60 ms 8672 KB Output is correct
29 Correct 55 ms 8672 KB Output is correct
30 Correct 816 ms 23896 KB Output is correct
31 Correct 826 ms 23492 KB Output is correct
32 Correct 823 ms 23876 KB Output is correct
33 Correct 824 ms 23288 KB Output is correct
34 Correct 842 ms 23620 KB Output is correct
35 Correct 817 ms 22340 KB Output is correct
36 Correct 806 ms 23108 KB Output is correct
37 Correct 857 ms 23364 KB Output is correct
38 Correct 838 ms 22724 KB Output is correct
39 Runtime error 547 ms 524292 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -