Submission #44377

# Submission time Handle Problem Language Result Execution time Memory
44377 2018-04-01T10:18:45 Z szawinis Aliens (IOI16_aliens) C++17
0 / 100
2 ms 536 KB
#include "aliens.h"
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

inline ll square(ll x) { return x*x; }

void tidy_up(int &n, vector<int> &l, vector<int> &r) {
	for(int i = 0; i < n; i++) if(l[i] > r[i]) swap(l[i], r[i]);
	vector<int> id(n);
	iota(id.begin(), id.end(), 0);
	sort(id.begin(), id.end(), [l, r] (int i, int j) {
		return make_pair(r[i], -l[i]) < make_pair(r[j], -l[j]);
	});
	vector<int> tmp;
	tmp.push_back(-1);
	tmp.push_back(id[0]);
	for(int i = 1; i < n; i++) {
		while(tmp.size() > 1 && l[tmp.back()] >= l[id[i]]) tmp.pop_back();
		tmp.push_back(id[i]);
	}
	n = tmp.size() - 1;
	id = tmp;
	for(int i = 1; i <= n; i++) tmp[i] = r[id[i]];
	r = tmp;
	for(int i = 1; i <= n; i++) tmp[i] = l[id[i]];
	l = tmp;
}

struct cht {
	struct line {
		ll m, c;
		line(ll m, ll c): m(m), c(c) {};
		ll getVal(ll x) { return m*x + c; }
	};
	vector<line> f;
	bool bad(line l1, line l2, line l3) { // m1 > m2 > m3
		return (double) (l1.c-l3.c)*(l2.m-l1.m) <= (double) (l1.c-l2.c)*(l3.m-l1.m);
	}
	void insert(ll m, ll c) {
		line l = line(m, c);
		while(f.size() >= 2 && bad(f[f.size()-2], f[f.size()-1], l)) f.pop_back();
		f.push_back(l);
	}
	ll query(ll x) {
		static int idx = 0;
		while(idx+1 < f.size() && f[idx+1].getVal(x) < f[idx].getVal(x)) ++idx;
		return f[idx].getVal(x);
	}
	void clear() { f.clear(); }
} hull;

vector<vector<ll> > dp;

ll take_photos(int n, int m, int k, vector<int> l, vector<int> r) {
	tidy_up(n, l, r);
	dp = vector<vector<ll> >(k+1, vector<ll>(n+1, -1));
	hull.insert(-2*(l[1]-1), square(l[1]-1));
	for(int j = 1; j <= k; j++) {
		dp[j][0] = 0;
		for(int i = 1; i <= n; i++) {
			dp[j][i] = hull.query(r[i]) + square(r[i]);
		}
		hull.clear();
		for(int i = 0; i < n; i++) {
			hull.insert(-2*(l[i+1]-1), square(l[i+1]-1) + dp[j][i] - square(max(0, r[i] - l[i+1] + 1)));
		}
	}
	return dp[k][n];
}

Compilation message

aliens.cpp: In member function 'll cht::query(ll)':
aliens.cpp:47:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(idx+1 < f.size() && f[idx+1].getVal(x) < f[idx].getVal(x)) ++idx;
         ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Correct answer: answer = 4
2 Correct 2 ms 356 KB Correct answer: answer = 4
3 Correct 2 ms 432 KB Correct answer: answer = 4
4 Correct 2 ms 508 KB Correct answer: answer = 12
5 Correct 2 ms 532 KB Correct answer: answer = 52
6 Incorrect 2 ms 532 KB Wrong answer: output = 212, expected = 210
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 532 KB Correct answer: answer = 1
2 Correct 2 ms 536 KB Correct answer: answer = 4
3 Correct 2 ms 536 KB Correct answer: answer = 1
4 Correct 2 ms 536 KB Correct answer: answer = 5
5 Correct 2 ms 536 KB Correct answer: answer = 41
6 Incorrect 2 ms 536 KB Wrong answer: output = 151683, expected = 71923
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Correct answer: answer = 4
2 Correct 2 ms 356 KB Correct answer: answer = 4
3 Correct 2 ms 432 KB Correct answer: answer = 4
4 Correct 2 ms 508 KB Correct answer: answer = 12
5 Correct 2 ms 532 KB Correct answer: answer = 52
6 Incorrect 2 ms 532 KB Wrong answer: output = 212, expected = 210
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Correct answer: answer = 4
2 Correct 2 ms 356 KB Correct answer: answer = 4
3 Correct 2 ms 432 KB Correct answer: answer = 4
4 Correct 2 ms 508 KB Correct answer: answer = 12
5 Correct 2 ms 532 KB Correct answer: answer = 52
6 Incorrect 2 ms 532 KB Wrong answer: output = 212, expected = 210
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Correct answer: answer = 4
2 Correct 2 ms 356 KB Correct answer: answer = 4
3 Correct 2 ms 432 KB Correct answer: answer = 4
4 Correct 2 ms 508 KB Correct answer: answer = 12
5 Correct 2 ms 532 KB Correct answer: answer = 52
6 Incorrect 2 ms 532 KB Wrong answer: output = 212, expected = 210
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Correct answer: answer = 4
2 Correct 2 ms 356 KB Correct answer: answer = 4
3 Correct 2 ms 432 KB Correct answer: answer = 4
4 Correct 2 ms 508 KB Correct answer: answer = 12
5 Correct 2 ms 532 KB Correct answer: answer = 52
6 Incorrect 2 ms 532 KB Wrong answer: output = 212, expected = 210
7 Halted 0 ms 0 KB -