Submission #59889

#TimeUsernameProblemLanguageResultExecution timeMemory
59889KieranHorganShortcut (IOI16_shortcut)C++17
31 / 100
2040 ms1248 KiB
#include "shortcut.h"
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 
ll prefix[3005];
ll bestB[3005];
ll bestA[3005];
 
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
	vector<int> L = {0,0};
	for(auto i: l) L.push_back(i);
	l=L;
	vector<ll> D = {0};
	for(auto i: d) D.push_back(i);
	d.clear();
	for(auto i: D) d.push_back(i);
 
	for(int i = 1; i <= n; i++)
		prefix[i] = prefix[i-1] + l[i];
 
	ll diam = 1ll<<50;
 
	vector<ll> Db = D;
	for(int i = 2; i <= n; i++)
		Db[i] = max(Db[i], Db[i-1]+(ll)l[i]);
	vector<ll> Da = D;
	for(int i = n-1; i >= 1; i--)
		Da[i] = max(Da[i], Da[i+1]+(ll)l[i+1]);
 
	// cerr << "  ";
	// for(int i = 2; i <= n; i++)
		// cerr << l[i] << "  ";
	// cerr << endl;
	// for(int i = 1; i <= n; i++) {
		// cerr << d[i] << "  ";
		// if(d[i]==0)
			// cerr << " ";
	// }
	// cerr << endl;
	// cerr << endl;
// 
	// for(int i = 1; i <= n; i++)
		// cerr << Db[i] << "  ";
	// cerr << endl;
	// cerr << endl;
	// for(int i = 1; i <= n; i++)
		// cerr << Da[i] << "  ";
	// cerr << endl;
	// cerr << endl;
 
	for(int i = 1; i <= n; i++)
		for(int j = i+1; j <= n; j++)
			bestB[j] = max(bestB[j], prefix[j]-prefix[i] + (ll)d[i] + (ll)d[j]),
			bestA[i] = max(bestA[i], prefix[j]-prefix[i] + (ll)d[i] + (ll)d[j]);
	for(int i = 2; i <= n; i++)
		bestB[i] = max(bestB[i], bestB[i-1]);
	for(int i = n-1; i >= 1; i--)
		bestA[i] = max(bestA[i], bestA[i+1]);
 
	// for(int i = 1; i <= n; i++)
		// cerr << bestB[i] << "  ";
	// cerr << endl;
	// for(int i = 1; i <= n; i++)
		// cerr << bestA[i] << "  ";
	// cerr << endl;
	// cerr << endl;
 
	for(ll ci = 1; ci <= n; ci++) {
		for(ll cj = ci+1; cj <= n; cj++) {
			D[ci] = Db[ci];
			D[cj] = Da[cj];
 
			ll currDiam = max(bestB[ci], bestA[cj]);
			ll j = 0;
			vector<ll> opt(cj+1, 0);
			for(ll i = ci; i <= cj; i++) {
				for(j = max(opt[i-1], i+1); j <= cj; j++) {
					if(min(prefix[j]-prefix[i] + D[i] + D[j], prefix[cj]-prefix[j] + c + prefix[i]-prefix[ci] + D[i] + D[j]) >= currDiam) {
						currDiam = min(prefix[j]-prefix[i] + D[i] + D[j], prefix[cj]-prefix[j] + c + prefix[i]-prefix[ci] + D[i] + D[j]);
						opt[i] = j;
					}
				}
			}
			diam = min(diam, currDiam);
 
			D[ci] = d[ci];
			D[cj] = d[cj];
		}
	}
 
    return diam;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...