Submission #24954

# Submission time Handle Problem Language Result Execution time Memory
24954 2017-06-18T03:35:11 Z Hiasat Shortcut (IOI16_shortcut) C++14
0 / 100
0 ms 72452 KB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 3000;
const ll INF = 1e18;
ll L[N], R[N], mxL[N], mxR[N], pre[N];
vector<int> d, l;
ll dp[N][N];
int n;

ll c;

bool check(ll mid) {
	for (int len = 1; len <= n ; ++len) {
		for (int i = n - len ; i >= 0 ; --i) {
			int j = i + len - 1;
			if (len == 1) {
				dp[i][j] = INF;
				continue;
			}
			if (pre[j] - pre[i] + d[i] + d[j] > mid)
				dp[i][j] = (pre[j] - pre[i]) - d[i] - d[j];
			else
				dp[i][j] = INF;
			dp[i][j] = min(dp[i][j], min(dp[i + 1][j], dp[i][j - 1]));
		}
	}
	for (int i = 0 ; i < n ; i++) {
		if (mxL[i] > mid)
			continue;
		ll fage3 = -INF;
		pair<ll, int> mn = make_pair(INF, -1);
		for (int j = i + 1 ; j < n ; j++) {
			mn = min(mn, make_pair(pre[j] - d[j], j));
			if (L[j] + d[j] > mid)
				fage3 = max(fage3, L[i] + c + d[j]);
			if (mxR[j] > mid)
				continue;
			if (L[i] + min(pre[j] - pre[i], c) + R[j] > mid)
				continue;
			if (dp[i][j] != INF && (pre[j] - pre[i] + c) - dp[i][j] > mid)
				continue;
			if (fage3 > mid)
				break;
			if (mn.second != -1 && R[j] + pre[j] - mn.first > mid) {
				
				if (pre[mn.second] - pre[i] + d[mn.second] + c + R[j] > mid)
					continue;
			}

			return 1;
		}
	}
	/*	for(int i = 0 ; i < n ; ++i){
			if(mxL[i] > mid)
				continue;
			ll fage3 = -INF;
			ll csum = 0;
			for (int j = i+1; j < n; ++j){
				csum += l[j-1];
				if(L[j]+d[j] > mid)
					fage3 = max(fage3,L[i]+c+d[j]);
				if(fage3 > mid)
					break;
				if(min(csum,c)+L[i]+R[j]<=mid && mxR[j]<=mid && (dp[i][j] ==INF || csum+c-dp[i][j]<=mid)){
					vis[i][j] = vsId;
				}
				if(j != n-1)
					fage3 += l[j];
			}
		}
		for(int i = n-1 ; i >= 0 ;--i){
			if(mxR[i] > mid)
				continue;
			ll fage3 = -INF;
			for (int j = i-1; j>= 0 ;j--){
				if(R[j]+d[j] > mid)
					fage3 = max(fage3,R[i]+c+d[j]);

				if(fage3 > mid)
					break;
				if(mxL[j]<=mid && vis[j][i] == vsId){
					return true;
				}
				if(j != 0)
					fage3 += l[j-1];
			}
		}*/
	return false;
}
ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
	if (n > 3000)
		return -1;
	::n = n;
	::d = d;
	::c = c;
	::l = l;
	for (int i = 0; i < n; ++i) {
		L[i] = d[i];
		if (i)
			pre[i] = l[i - 1] + pre[i - 1];
		if (i)
			L[i] = max(L[i - 1] + l[i - 1], L[i]);
		mxL[i] = max(i ? mxL[i - 1] : 0, d[i] + (i ? L[i - 1] + l[i - 1] : 0));
	}
	for (int i = n - 1 ; i >= 0 ; i--) {
		R[i] = d[i];
		if (i != n - 1)
			R[i] = max(R[i], R[i + 1] + l[i]);
		mxR[i] = max(i != n - 1 ? mxR[i + 1] : 0, d[i] + (i != n - 1 ? R[i + 1] + l[i] : 0));
	}
	ll lo = *max_element(d.begin(), d.end()) , hi = 1e9 * (N + 3), best = -1;
	while (lo <= hi) {
		ll mid = (lo + hi) / 2;
		if (check(mid)) {
			best = mid;
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
	}
	assert(best != -1);
	return best;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 72452 KB n = 4, 80 is a correct answer
2 Correct 0 ms 72452 KB n = 9, 110 is a correct answer
3 Correct 0 ms 72452 KB n = 4, 21 is a correct answer
4 Correct 0 ms 72452 KB n = 3, 4 is a correct answer
5 Correct 0 ms 72452 KB n = 2, 62 is a correct answer
6 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
7 Correct 0 ms 72452 KB n = 3, 29 is a correct answer
8 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
9 Correct 0 ms 72452 KB n = 2, 3 is a correct answer
10 Correct 0 ms 72452 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 72452 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
13 Correct 0 ms 72452 KB n = 3, 3000000000 is a correct answer
14 Correct 0 ms 72452 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 72452 KB n = 4, 4000000000 is a correct answer
16 Incorrect 0 ms 72452 KB n = 5, incorrect answer: jury 4000000000 vs contestant 3000000001
17 Halted 0 ms 0 KB -