Submission #71564

# Submission time Handle Problem Language Result Execution time Memory
71564 2018-08-25T07:10:38 Z gnoor Shortcut (IOI16_shortcut) C++17
0 / 100
3 ms 484 KB
#include "shortcut.h"

#include <vector>
#include <algorithm>

using namespace std;

struct rect {
	long long lft,top,rgt,bot;

	rect():lft(-1e18),top(1e18),rgt(1e18),bot(-1e18) {}
	rect(long long _lft,long long _top,long long _rgt,long long _bot):lft(_lft),top(_top),rgt(_rgt),bot(_bot) {}
};

rect comb(const rect &a, const rect &b) {
	return rect(max(a.lft,b.lft),min(a.top,b.top),min(a.rgt,b.rgt),max(a.bot,b.bot));
}

struct inter {
	long long a,b,c;

	rect eval(long long k) const {
		long long z=k-c;
		return rect(a-b-z,a+b+z,a-b+z,a+b-z);
	}
};

bool work(long long k,const vector<inter> inters,long long cost) {
	rect cur;
	for (auto &i:inters) {
		if (i.c-cost+i.b-i.a<=k) continue;
		cur=comb(cur,i.eval(k));
	}
	return cur.lft<=cur.rgt&&cur.bot<=cur.top;
}

long long find_shortcut(int n, vector<int> l, vector<int> d, int c)
{
	vector<long long> qs(n,0);
	for (int i=1;i<n;i++) {
		qs[i]=l[i];
		qs[i]+=qs[i-1];
	}
	vector<inter> inters;
	inters.reserve(n*(n-1)/2);
	for (int i=0;i<n;i++) {
		for (int j=i+1;j<n;j++) {
			inters.push_back(inter{qs[i],qs[j],d[i]+d[j]+c});
		}
	}
	long long lo=0;
	long long hi=1e15;
	long long mid;
	while (lo<hi) {
		mid=(lo+hi)>>1;
		if (work(mid,inters,c)) {
			hi=mid;
		} else {
			lo=mid+1;
		}
	}
	return lo;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB n = 4, 80 is a correct answer
2 Correct 2 ms 484 KB n = 9, 110 is a correct answer
3 Correct 3 ms 484 KB n = 4, 21 is a correct answer
4 Incorrect 2 ms 484 KB n = 3, incorrect answer: jury 4 vs contestant 3