Submission #40882

# Submission time Handle Problem Language Result Execution time Memory
40882 2018-02-09T16:14:17 Z gabrielsimoes Boat (APIO16_boat) C++14
31 / 100
1939 ms 8516 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1000000007;
const int MAXN = 510;

int n;
int va[MAXN], vb[MAXN];
vector<ll> dp[MAXN];

int main() {
	va[0] = vb[0] = 0;
	dp[0].push_back(1);

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &va[i], &vb[i]);
		dp[i].resize(vb[i] - va[i] + 1);
	}

	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < dp[i].size(); j++) {
			if (j > 0) {
				dp[i][j] += dp[i][j-1];
			}

			if (i > 0) {
				ans += dp[i][j];
				ans %= MOD;
			}

			ll cur = va[i] + j;

			for (int k = i+1; k <= n; k++) {
				if (cur < vb[k]) {
					int pos = max(cur - va[k] + 1, 0LL);
					dp[k][pos] += dp[i][j];
					dp[k][pos] %= MOD;
				}
			}
		}
	}

	printf("%lld\n", ans);
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:24:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < dp[i].size(); j++) {
                     ^
boat.cpp:16:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
boat.cpp:18:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &va[i], &vb[i]);
                                 ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 476 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 708 KB Output is correct
13 Correct 2 ms 708 KB Output is correct
14 Correct 3 ms 708 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 2 ms 708 KB Output is correct
17 Correct 2 ms 708 KB Output is correct
18 Correct 2 ms 708 KB Output is correct
19 Correct 2 ms 708 KB Output is correct
20 Correct 2 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 476 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 708 KB Output is correct
13 Correct 2 ms 708 KB Output is correct
14 Correct 3 ms 708 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 2 ms 708 KB Output is correct
17 Correct 2 ms 708 KB Output is correct
18 Correct 2 ms 708 KB Output is correct
19 Correct 2 ms 708 KB Output is correct
20 Correct 2 ms 708 KB Output is correct
21 Correct 1401 ms 7476 KB Output is correct
22 Correct 1382 ms 7476 KB Output is correct
23 Correct 1092 ms 7476 KB Output is correct
24 Correct 1355 ms 7804 KB Output is correct
25 Correct 1418 ms 7804 KB Output is correct
26 Correct 1488 ms 8228 KB Output is correct
27 Correct 1515 ms 8312 KB Output is correct
28 Correct 1762 ms 8312 KB Output is correct
29 Correct 1939 ms 8384 KB Output is correct
30 Correct 809 ms 8492 KB Output is correct
31 Correct 840 ms 8492 KB Output is correct
32 Correct 833 ms 8516 KB Output is correct
33 Correct 828 ms 8516 KB Output is correct
34 Correct 863 ms 8516 KB Output is correct
35 Correct 629 ms 8516 KB Output is correct
36 Correct 529 ms 8516 KB Output is correct
37 Correct 559 ms 8516 KB Output is correct
38 Correct 641 ms 8516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 8516 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 2 ms 476 KB Output is correct
6 Correct 2 ms 476 KB Output is correct
7 Correct 2 ms 532 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 3 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 708 KB Output is correct
13 Correct 2 ms 708 KB Output is correct
14 Correct 3 ms 708 KB Output is correct
15 Correct 2 ms 708 KB Output is correct
16 Correct 2 ms 708 KB Output is correct
17 Correct 2 ms 708 KB Output is correct
18 Correct 2 ms 708 KB Output is correct
19 Correct 2 ms 708 KB Output is correct
20 Correct 2 ms 708 KB Output is correct
21 Correct 1401 ms 7476 KB Output is correct
22 Correct 1382 ms 7476 KB Output is correct
23 Correct 1092 ms 7476 KB Output is correct
24 Correct 1355 ms 7804 KB Output is correct
25 Correct 1418 ms 7804 KB Output is correct
26 Correct 1488 ms 8228 KB Output is correct
27 Correct 1515 ms 8312 KB Output is correct
28 Correct 1762 ms 8312 KB Output is correct
29 Correct 1939 ms 8384 KB Output is correct
30 Correct 809 ms 8492 KB Output is correct
31 Correct 840 ms 8492 KB Output is correct
32 Correct 833 ms 8516 KB Output is correct
33 Correct 828 ms 8516 KB Output is correct
34 Correct 863 ms 8516 KB Output is correct
35 Correct 629 ms 8516 KB Output is correct
36 Correct 529 ms 8516 KB Output is correct
37 Correct 559 ms 8516 KB Output is correct
38 Correct 641 ms 8516 KB Output is correct
39 Runtime error 4 ms 8516 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -