Submission #597507

# Submission time Handle Problem Language Result Execution time Memory
597507 2022-07-16T07:44:51 Z GusterGoose27 Long Distance Coach (JOI17_coach) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<ll, ll> pii;
typedef long long ll;

const ll MAXN = 2e5+1;
long long n, m, t, wll, wcost;
ll dp[MAXN];
pii ppl[MAXN]; // time, drop_cost
ll refill[MAXN];
ll stat_with[MAXN];
ll pre[MAXN];
const ll inf = 4e18;

class Frac {
public:
	ll num, denom;
	Frac() {
		num = inf;
		denom = 1;
	}
	Frac(ll x, ll y) {
		num = x;
		denom = y;
		reduce();
	}
	void reduce() {
		if (denom < 0) {
			denom *= -1;
			num *= -1;
		}
		ll g = gcd(abs(num), denom);
		num /= g;
		denom /= g;
	}
	ll gcd(ll a, ll b) {
		if (a > b) return gcd(b, a);
		if (a == 0) return b;
		return gcd(b%a, a);
	}
};

bool operator<(Frac a, Frac b) {
	return ((__ll128)a.num*b.denom) < ((__ll128)b.num*a.denom);
}

class Line {
public:
	ll ller;
	ll slope;
	Frac rbound;
	Line(ll in, ll s) {
		ller = in;
		slope = s;
	}
};

Frac llersect(Line a, Line b) {
	return Frac(a.ller-b.ller, b.slope-a.slope);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> t >> m >> n >> wcost >> wll;
	m++;
	for (ll i = 0; i < m-1; i++) {
		long long r; cin >> r;
		refill[i] = r;
	}
	refill[m-1] = t;
	sort(refill, refill+m);
	n++;
	ppl[0] = pii(0, 0);
	for (ll i = 1; i < n; i++) {
		ll x, y; cin >> x >> y;
		ppl[i] = pii(x, y);
	}
	sort(ppl, ppl+n);
	fill(stat_with, stat_with+n, -1);
	ll cur = 0;
	for (ll i = 0; i < n; i++) {
		cur += ppl[i].second;
		pre[i] = cur;
	}
	for (ll i = 0; i < m; i++) {
		ll comp = refill[i]/wll;
		ll mn = 0;
		ll mx = n;
		while (mx > mn+1) {
			ll cur = (mn+mx)/2;
			if ((refill[i]-ppl[cur].first)/wll == comp) mn = cur;
			else mx = cur;
		}
		if (stat_with[mn] == -1) stat_with[mn] = i;
	}
	dp[0] = wcost*((t+wll)/wll);
	vector<Line> hull;
	hull.push_back(Line(dp[0]-pre[0], 0));
	for (ll i = 1; i < n; i++) {
		dp[i] = wcost*((t-ppl[i].first)/wll+1)+dp[i-1];
		if (stat_with[i] >= 0) {
			ll stat = stat_with[i];
			ll sl = wcost*((refill[stat]-ppl[i].first)/wll);
			ll mn = -1;
			ll mx = hull.size()-1;
			Frac f(sl, 1);
			while (mx > mn+1) {
				ll cur = (mn+mx)/2;
				if (hull[cur].rbound < f) mn = cur;
				else mx = cur;
			}
			ll cval = pre[i]+hull[mx].ller+hull[mx].slope*sl+i*sl;
			dp[i] = min(dp[i], cval);
		}
		Line cur_l(dp[i]-pre[i], -i);
		Frac ller = llersect(cur_l, hull.back());
		while (hull.size() > 1 && ller < hull[hull.size()-2].rbound) {
			hull.pop_back();
			ller = llersect(cur_l, hull.back());
		}
		hull.back().rbound = ller;
		hull.push_back(cur_l);
	}
	cout << dp[n-1] << "\n";
}

Compilation message

coach.cpp:5:14: error: 'll' was not declared in this scope
    5 | typedef pair<ll, ll> pii;
      |              ^~
coach.cpp:5:18: error: 'll' was not declared in this scope
    5 | typedef pair<ll, ll> pii;
      |                  ^~
coach.cpp:5:20: error: template argument 1 is invalid
    5 | typedef pair<ll, ll> pii;
      |                    ^
coach.cpp:5:20: error: template argument 2 is invalid
coach.cpp: In function 'bool operator<(Frac, Frac)':
coach.cpp:46:11: error: '__ll128' was not declared in this scope
   46 |  return ((__ll128)a.num*b.denom) < ((__ll128)b.num*a.denom);
      |           ^~~~~~~
coach.cpp:46:19: error: expected ')' before 'a'
   46 |  return ((__ll128)a.num*b.denom) < ((__ll128)b.num*a.denom);
      |         ~         ^
      |                   )
coach.cpp: In function 'int main()':
coach.cpp:75:19: error: expression list treated as compound expression in functional cast [-fpermissive]
   75 |  ppl[0] = pii(0, 0);
      |                   ^
coach.cpp:75:15: warning: left operand of comma operator has no effect [-Wunused-value]
   75 |  ppl[0] = pii(0, 0);
      |               ^
coach.cpp:78:20: error: expression list treated as compound expression in functional cast [-fpermissive]
   78 |   ppl[i] = pii(x, y);
      |                    ^
coach.cpp:78:16: warning: left operand of comma operator has no effect [-Wunused-value]
   78 |   ppl[i] = pii(x, y);
      |                ^
coach.cpp:84:17: error: request for member 'second' in 'ppl[i]', which is of non-class type 'pii' {aka 'int'}
   84 |   cur += ppl[i].second;
      |                 ^~~~~~
coach.cpp:93:28: error: request for member 'first' in 'ppl[cur]', which is of non-class type 'pii' {aka 'int'}
   93 |    if ((refill[i]-ppl[cur].first)/wll == comp) mn = cur;
      |                            ^~~~~
coach.cpp:102:28: error: request for member 'first' in 'ppl[i]', which is of non-class type 'pii' {aka 'int'}
  102 |   dp[i] = wcost*((t-ppl[i].first)/wll+1)+dp[i-1];
      |                            ^~~~~
coach.cpp:105:40: error: request for member 'first' in 'ppl[i]', which is of non-class type 'pii' {aka 'int'}
  105 |    ll sl = wcost*((refill[stat]-ppl[i].first)/wll);
      |                                        ^~~~~