Submission #40847

# Submission time Handle Problem Language Result Execution time Memory
40847 2018-02-09T12:22:20 Z IvanC Boat (APIO16_boat) C++14
31 / 100
1523 ms 16412 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 501;
const ll MOD = (ll)1e9 + 7;
ll A[MAXN],B[MAXN],N;
vector<ll> dp[MAXN],sum[MAXN];
inline ll get_sum(int idx,int i,int j){
	i -= A[idx];
	j -= A[idx];
	i = max(i,0);
	if(i > j) return 0;
	if(i == 0) return sum[idx][j];
	else return sum[idx][j] - sum[idx][i-1];
}
int main(){
	cin >> N;
	for(int i = 1;i<=N;i++){
		cin >> A[i] >> B[i];
		dp[i].assign(B[i] - A[i] + 1,0);
		sum[i].assign(B[i] - A[i] + 1,0);
	}
	for(int j = A[N];j<=B[N];j++){
		dp[N][j - A[N]] = 1;
		sum[N][j - A[N]] = dp[N][j - A[N]];
		if(j - A[N] != 0) sum[N][j - A[N]] += sum[N][j - A[N] - 1]; 
	}
	for(int i = N-1;i>=1;i--){
		for(int j = A[i];j<=B[i];j++){
			dp[i][j - A[i]] = 1;
			for(ll k = i+1;k<=N;k++){
				dp[i][j - A[i]] = (dp[i][j - A[i]] + get_sum(k,j+1,B[k]));
			}
			dp[i][j - A[i]] %= MOD;
		}
		for(int j = A[i];j<=B[i];j++){
			sum[i][j - A[i]] = dp[i][j - A[i]];
			if(j - A[i] != 0) sum[i][j - A[i]] += sum[i][j - A[i] - 1];
			sum[i][j - A[i]] %= MOD;
		}
	}
	ll tot = 0;
	for(int i = 1;i<=N;i++) tot = (tot + sum[i].back()) % MOD;
	if(tot < 0) tot += MOD;
	cout << tot << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 372 KB Output is correct
2 Correct 3 ms 372 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 3 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 3 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 372 KB Output is correct
2 Correct 3 ms 372 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 3 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 3 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 1154 ms 14332 KB Output is correct
22 Correct 1180 ms 14332 KB Output is correct
23 Correct 1074 ms 14332 KB Output is correct
24 Correct 1304 ms 14836 KB Output is correct
25 Correct 1429 ms 14932 KB Output is correct
26 Correct 1329 ms 15748 KB Output is correct
27 Correct 1395 ms 15956 KB Output is correct
28 Correct 1427 ms 15956 KB Output is correct
29 Correct 1523 ms 16100 KB Output is correct
30 Correct 603 ms 16308 KB Output is correct
31 Correct 570 ms 16308 KB Output is correct
32 Correct 621 ms 16412 KB Output is correct
33 Correct 601 ms 16412 KB Output is correct
34 Correct 588 ms 16412 KB Output is correct
35 Correct 764 ms 16412 KB Output is correct
36 Correct 669 ms 16412 KB Output is correct
37 Correct 714 ms 16412 KB Output is correct
38 Correct 690 ms 16412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 16412 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 3 ms 372 KB Output is correct
2 Correct 3 ms 372 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 2 ms 448 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 3 ms 576 KB Output is correct
8 Correct 2 ms 576 KB Output is correct
9 Correct 2 ms 576 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 3 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 1154 ms 14332 KB Output is correct
22 Correct 1180 ms 14332 KB Output is correct
23 Correct 1074 ms 14332 KB Output is correct
24 Correct 1304 ms 14836 KB Output is correct
25 Correct 1429 ms 14932 KB Output is correct
26 Correct 1329 ms 15748 KB Output is correct
27 Correct 1395 ms 15956 KB Output is correct
28 Correct 1427 ms 15956 KB Output is correct
29 Correct 1523 ms 16100 KB Output is correct
30 Correct 603 ms 16308 KB Output is correct
31 Correct 570 ms 16308 KB Output is correct
32 Correct 621 ms 16412 KB Output is correct
33 Correct 601 ms 16412 KB Output is correct
34 Correct 588 ms 16412 KB Output is correct
35 Correct 764 ms 16412 KB Output is correct
36 Correct 669 ms 16412 KB Output is correct
37 Correct 714 ms 16412 KB Output is correct
38 Correct 690 ms 16412 KB Output is correct
39 Runtime error 4 ms 16412 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -