Submission #787580

#TimeUsernameProblemLanguageResultExecution timeMemory
787580NothingXDShortcut (IOI16_shortcut)C++17
23 / 100
2049 ms300 KiB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;

void debug_out(){cerr << endl;}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 300 + 10;
const ll inf = 1e18;

int n, l[maxn], d[maxn], st, en, c;
ll h[maxn];

void bfs(int v){
	memset(h, 63, sizeof h);
	h[v] = 0;
	queue<int> q;
	q.push(v);
	while(!q.empty()){
		int v = q.front();
		q.pop();
		if (v && h[v-1] > h[v] + l[v-1]){
			h[v-1] = h[v] + l[v-1];
			q.push(v-1);
		}
		if (v < n-1 && h[v+1] > h[v] + l[v]){
			h[v+1] = h[v] + l[v];
			q.push(v+1);
		}
		if (v == st && h[en] > h[st] + c){
			h[en] = h[st] + c;
			q.push(en);
		}
		if (v == en && h[st] > h[en] + c){
			h[st] = h[en] + c;
			q.push(st);
		}
	}
}


long long find_shortcut(int N, std::vector<int> L, std::vector<int> D, int C){

	n = N, c = C;
	for (int i = 0; i < n; i++){
		if (i != n-1) l[i] = L[i];
		d[i] = D[i];
	}

	ll ans = inf;

	for (int i = 0; i < n; i++){
		for (int j = i+1; j < n; j++){
			st = i;
			en = j;
			ll res = 0;
			for (int k = 0; k < n; k++){
				bfs(k);
				for (int l = k+1; l < n; l++){
					res = max(res, h[l] + d[l] + d[k]);
				}
			}
			ans = min(ans, res);
		}
	}

    return ans;
}
#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...