Submission #30792

# Submission time Handle Problem Language Result Execution time Memory
30792 2017-07-26T14:04:28 Z cdemirer Boat (APIO16_boat) C++14
0 / 100
2000 ms 350004 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llp;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define MOD ((ll)1e9+7)
#define safeadd(x, y) ( ( ((ll)x % MOD) + ((ll)y % MOD) ) % MOD )

int N;
map<int, ll> dp[500];
int A[500], B[500];

ll func(int x, int s) {
	s = max(s, A[x]-1);
	//cerr << "called: " << x << " " << s << endl;
	if (dp[x][s] != -1) return dp[x][s];
	ll sum = 0;
	if (x < N-1) sum = safeadd(sum, func(x+1, 0));
	else sum = safeadd(sum, 1);
	for (int i = s+1; i <= B[x]; i++) {
		if (x < N-1) sum = safeadd(sum, func(x+1, i));
		else sum = safeadd(sum, 1);
	}
	dp[x][s] = sum;
	//cerr << "returned: " << sum << endl;
	return dp[x][s];
}

int main(int argc, char **argv) {

	//freopen("input", "r", stdin);
	//freopen("output", "w", stdout);

	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &(A[i]), &(B[i]));
	}
	for (int i = 0; i < N; i++) {
		dp[i][0] = -1;
		for (int j = A[i]-1; j <= B[i]; j++) {
			dp[i][j] = -1;
		}
	}
	printf("%lld\n", safeadd(func(0, 0), -1));
	

	return 0;
}

Compilation message

boat.cpp: In function 'int main(int, char**)':
boat.cpp:40:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
boat.cpp:42:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &(A[i]), &(B[i]));
                                  ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2000 ms 350004 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2184 KB Output isn't correct
2 Halted 0 ms 0 KB -