Submission #105521

# Submission time Handle Problem Language Result Execution time Memory
105521 2019-04-13T08:23:10 Z polyfish Shortcut (IOI16_shortcut) C++14
0 / 100
2000 ms 512 KB
//Pantyhose(black) + glasses = infinity

#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

const int64_t INF = 1e18;

int n;
int64_t c;
vector<int64_t> d, v, q;
map<int64_t, int> idx;

struct fenwick_tree {

	int n;
	vector<int64_t> bit;

	fenwick_tree(int n): n(n) {
		bit.resize(n+1, -INF);
	}

	void upd(int idx, int64_t val) {
		for (; idx<=n; idx += idx & -idx)
			bit[idx] = max(bit[idx], val);
	}

	int64_t get(int idx) {
		int64_t res = -INF;

		for (; idx>0; idx -= idx & -idx)
			res = max(res, bit[idx]);

		return res;
	}

};

void init(int64_t x) {
	for (int i=0; i<n; ++i)
		q.push_back(d[i]);
	sort(q.begin(), q.end());

	vector<int64_t> b;
	for (int i=0; i<n; ++i) {
		b.push_back(-d[i]-v[i]);
		b.push_back(v[i]-d[i]-x-1);
	}

	sort(b.begin(), b.end());
	b.resize(unique(b.begin(), b.end()) - b.begin());

	idx.clear();

	for (int i=0; i<b.size(); ++i)
		idx[b[i]] = i;
}

bool check(int64_t x) {
	int64_t l1, r1, l2, r2;
	l1 = l2 = -INF;
	r1 = r2 = INF;

	fenwick_tree bit1(2*n), bit2(2*n);

	init(x);

	for (int i=n-1; i>=0; --i) {

		int tmp2 = idx[v[i]-d[i]-x-1];

		l1 = max(l1, bit1.get(tmp2)+d[i]-x+c+v[i]);
		r1 = min(r1, -bit2.get(tmp2)+d[i]+x-c-v[i]);
		l2 = max(l2, bit2.get(tmp2)+d[i]-x+c+v[i]);
		r2 = min(r2, -bit1.get(tmp2)+d[i]+x-c-v[i]);

		// if (i==0)
		// 	debug(bit1.get(tmp2));

		int tmp1 = idx[-d[i]-v[i]];
		bit1.upd(tmp1, d[i]+v[i]);
		bit2.upd(tmp1, -d[i]+v[i]);
		// debug(-d[i]+v[i]);
	}
	// debug(v[3]);
	// cerr << l1 << ' ' << r1 << ' ' << l2 << ' ' << r2 << '\n';

	for (int i=0; i<n; ++i) {
		int64_t L = max(l1-d[i], d[i]-r2);
		int64_t R = min(r1-d[i], d[i]-l2);

		auto it = lower_bound(q.begin(), q.end(), L);

		if (it!=q.end() && *it<=R)
			return true;
	}

	return false;
}

int64_t find_shortcut(int _n, vector<int> _l, vector<int> _d, int _c) {
	c = _c;
	n = _n;

	for (auto x : _d)
		v.push_back(x);

	for (auto x : _l)
		d.push_back(x);

	d.insert(d.begin(), 0);
	for (int i=1; i<d.size(); ++i)
		d[i] += d[i-1];

	// PR0(v, n);

	// debug(check(62));

	int64_t l = 1, r = INF;
	for (int64_t mid=(l+r)/2; mid!=l && r!=mid; mid=(l+r)/2) {
		if (check(mid))
			r = mid;
		else
			l = mid;
	}

	for (int64_t i=l; i<=r; ++i) {
		if (check(i))
			return i;
	}

	return 0;
}

Compilation message

shortcut.cpp: In function 'void init(int64_t)':
shortcut.cpp:60:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<b.size(); ++i)
                ~^~~~~~~~~
shortcut.cpp: In function 'int64_t find_shortcut(int, std::vector<int>, std::vector<int>, int)':
shortcut.cpp:117:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=1; i<d.size(); ++i)
                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB n = 4, 80 is a correct answer
2 Correct 3 ms 384 KB n = 9, 110 is a correct answer
3 Correct 3 ms 512 KB n = 4, 21 is a correct answer
4 Correct 3 ms 384 KB n = 3, 4 is a correct answer
5 Correct 2 ms 256 KB n = 2, 62 is a correct answer
6 Correct 2 ms 256 KB n = 2, 3 is a correct answer
7 Correct 2 ms 384 KB n = 3, 29 is a correct answer
8 Correct 2 ms 384 KB n = 2, 3 is a correct answer
9 Correct 2 ms 384 KB n = 2, 3 is a correct answer
10 Execution timed out 2003 ms 384 KB Time limit exceeded
11 Halted 0 ms 0 KB -