Submission #56636

# Submission time Handle Problem Language Result Execution time Memory
56636 2018-07-12T04:07:27 Z spencercompton Shortcut (IOI16_shortcut) C++17
0 / 100
3 ms 612 KB
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll c;
vector<ll> l;
vector<ll> d;
vector<ll> pos;
ll dist(int i, int j){
	return abs(pos[i]-pos[j]);
}
long long find_shortcut(int n, std::vector<int> x, std::vector<int> y, int z)
{
	for(int i = 0; i<n; i++){
		if(i<n){
			l.push_back(x[i]);
		}
		d.push_back(y[i]);
	}
	c = z;
	ll inf = 10000000000000000LL;
	pos.resize(n);
	pos[0] = 0LL;
	for(int i = 1; i<n; i++){
		pos[i] = pos[i-1] + (ll)l[i-1];
	}
	ll best[n];
	int f[n];
	for(int i = 0; i<n; i++){
		best[i] = inf;
		f[i] = -1;
	}
	//testing to see if f[i] is increasing, if so I can do N log^2 N with d&c
	for(int i = 0; i<n; i++){
		for(int j = i+1; j<n; j++){
			ll now = 0LL;
			for(int a = 0; a<n; a++){
				for(int b = a+1; b<n; b++){
					//a->b
					ll here = min(d[a]+d[b]+dist(a,b),d[a]+d[b]+dist(a,i)+c+dist(j,b));
					now = max(now,here);
				}
			}
			if(now<best[i]){
				best[i] = now;
				f[i] = j;
			}
		}
	}
	ll ans = best[0];
	for(int i = 0; i<n-1; i++){
		ans = min(ans,best[i]);
		assert(f[i]!=-1);
		if(i>0){
			assert(f[i-1]<=f[i]);
		}
	}
	// ll maxl[n];
	// ll maxr[n];
	// ll dl[n];
	// ll dr[n];
	// int bl[n];
	// int br[n];
	// dl[0] = 0LL;
	// dr[0] = 0LL;
	// bl[0] = 0;
	// br[0] = 0;
	// maxl[0] = d[0];
	// for(int i = 1; i<n; i++){
	// 	maxl[i] = max(maxl[i-1]+(ll)l[i-1],d[i]);
	// }
	// maxr[n-1] = d[n-1];
	// for(int i = n-2; i>=0; i--){
	// 	maxr[i] = max(maxr[i+1]+(ll)l[i],d[i]);
	// }
	// int f[n];
	// ll best[n];
	// for(int i = 0; i<n; i++){
	// 	f[i] = -1;
	// 	best[i] = inf;
	// }
	// for(int i = 0; i<n; i++){
	// 	for(int j = i; j<n; j++){
	// 		//A B C
	// 		//A -> 
	// 	}
	// }
    return ans;
}
/*
4 10
10 20 20
0 40 0 30


9 30
10 10 10 10 10 10 10 10
20 0 30 0 0 40 0 40 0

4 1
2 2 2
1 10 10 1

3 3
1 1
1 1 1

*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -