Submission #127921

# Submission time Handle Problem Language Result Execution time Memory
127921 2019-07-10T08:29:11 Z 조승현(#3114) Long Distance Coach (JOI17_coach) C++14
100 / 100
491 ms 35320 KB
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<functional>
#include<set>
#define N_ 201000
using namespace std;
#define pii pair<int,int>

long long X[N_], D[N_];
int n, m;
long long cost, T;

struct point {
	long long x, c;
	bool operator <(const point &p)const {
		return x < p.x;
	}
}w[N_];

long long First[N_], Z[N_], INF = 4e18, D1[N_], D2[N_], SS[N_];

struct Seg {
	long long A, B;
};

vector<Seg>V;

void Put(long long A, long long B) {
	V.push_back({ A,B });
}
long long Get(long long x) {
	long long res = INF;
	for (auto &t : V) {
		res = min(res, t.A*x + t.B);
	}
	return res;
}



using line_t = long double;
const line_t is_query = -5e18;
struct Line {
	line_t m, b;
	mutable function<const Line*()> succ;
	bool operator<(const Line& rhs) const {
		if (rhs.b != is_query) return m < rhs.m;
		const Line* s = succ();
		if (!s) return 0;
		line_t x = rhs.m;
		return b - s->b < (s->m - m) * x;
	}
};
struct HullDynamic : public multiset<Line> { // will maintain upper hull for maximum
	bool bad(iterator y) {
		auto z = next(y);
		if (y == begin()) {
			if (z == end()) return 0;
			return y->m == z->m && y->b <= z->b;
		}
		auto x = prev(y);
		if (z == end()) return y->m == x->m && y->b <= x->b;
		return (x->b - y->b)*(z->m - y->m) >= (y->b - z->b)*(y->m - x->m);
	}
	void insert_line(line_t m, line_t b) {
		auto y = insert({ m, b });
		y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
		if (bad(y)) { erase(y); return; }
		while (next(y) != end() && bad(next(y))) erase(next(y));
		while (y != begin() && bad(prev(y))) erase(prev(y));
	}
	line_t query(line_t x) {
		Line p = { x,is_query };
		auto l = *lower_bound(p);
		return l.m * x + l.b;
	}
}H;

int main() {
	int i, j;
	scanf("%lld%d%d%lld%lld", &X[0], &m, &n, &cost, &T);
	for (i = 1; i <= m; i++) {
		scanf("%lld", &X[i]);
	}
	X[m + 1] = 0;
	sort(X, X + m + 2);
	m++;
	for (i = 1; i <= n; i++) {
		scanf("%lld%lld", &w[i].x, &w[i].c);
	}
	sort(w + 1, w + n + 1);
	for (i = 1; i <= n; i++) {
		Z[i] = w[i].x;
		SS[i] = SS[i - 1] + w[i].c;
	}
	D1[n + 1] = 0;
	D2[n + 1] = 0;
	for (i = 0; i <= n; i++) {
		D1[i] = INF;
		D2[i] = INF;
	}
	for (i = 0; i <= n; i++)First[i] = INF;
	for (i = 1; i <= m; i++) {
		int pv = lower_bound(Z, Z + n + 1, X[i] % T) - Z;
		First[pv % (n + 1)] = min(First[pv % (n + 1)], X[i]);
	}

	int ck = 0;
	for (i = n + 1; i >= 1; i--) {
		long long s = 0;
		D1[i - 1] = D2[i] + ((X[m] - w[i - 1].x) / T + 1)*cost;
		if (First[i % (n + 1)] < INF) {
			long long f = First[i % (n + 1)] / T * cost;
			//Put(-f, D2[i] + f * i + SS[i - 1]);
			H.insert_line(-(-f), -(D2[i] + f * i + SS[i - 1]));
			ck = 1;
		}
		if (i != 1) {
			D2[i - 1] = D1[i - 1];
			if (ck)D2[i - 1] = min(D2[i - 1], -(long long)H.query(i - 1) - SS[i - 2]);
		}
		//if (i != 1)D2[i - 1] = min(D1[i - 1], Get(i - 1) - SS[i - 2]);
	}
	printf("%lld\n", D1[0]);
}

Compilation message

coach.cpp: In function 'int main()':
coach.cpp:112:13: warning: unused variable 's' [-Wunused-variable]
   long long s = 0;
             ^
coach.cpp:82:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
coach.cpp:83:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%d%d%lld%lld", &X[0], &m, &n, &cost, &T);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &X[i]);
   ~~~~~^~~~~~~~~~~~~~~
coach.cpp:91:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &w[i].x, &w[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 352 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 352 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 4 ms 508 KB Output is correct
39 Correct 4 ms 504 KB Output is correct
40 Correct 4 ms 588 KB Output is correct
41 Correct 4 ms 504 KB Output is correct
42 Correct 4 ms 504 KB Output is correct
43 Correct 4 ms 504 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 4 ms 760 KB Output is correct
47 Correct 4 ms 508 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 4 ms 504 KB Output is correct
50 Correct 4 ms 504 KB Output is correct
51 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 292 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 352 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 404 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 352 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 380 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 4 ms 508 KB Output is correct
39 Correct 4 ms 504 KB Output is correct
40 Correct 4 ms 588 KB Output is correct
41 Correct 4 ms 504 KB Output is correct
42 Correct 4 ms 504 KB Output is correct
43 Correct 4 ms 504 KB Output is correct
44 Correct 4 ms 504 KB Output is correct
45 Correct 4 ms 504 KB Output is correct
46 Correct 4 ms 760 KB Output is correct
47 Correct 4 ms 508 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 4 ms 504 KB Output is correct
50 Correct 4 ms 504 KB Output is correct
51 Correct 4 ms 504 KB Output is correct
52 Correct 232 ms 13296 KB Output is correct
53 Correct 229 ms 13432 KB Output is correct
54 Correct 209 ms 13560 KB Output is correct
55 Correct 213 ms 13432 KB Output is correct
56 Correct 214 ms 13524 KB Output is correct
57 Correct 195 ms 13304 KB Output is correct
58 Correct 210 ms 13532 KB Output is correct
59 Correct 214 ms 13408 KB Output is correct
60 Correct 209 ms 13432 KB Output is correct
61 Correct 212 ms 13684 KB Output is correct
62 Correct 211 ms 13528 KB Output is correct
63 Correct 491 ms 35320 KB Output is correct
64 Correct 143 ms 13564 KB Output is correct
65 Correct 250 ms 13652 KB Output is correct
66 Correct 248 ms 13432 KB Output is correct
67 Correct 244 ms 13412 KB Output is correct
68 Correct 228 ms 13560 KB Output is correct
69 Correct 227 ms 13432 KB Output is correct
70 Correct 225 ms 13432 KB Output is correct
71 Correct 226 ms 13560 KB Output is correct
72 Correct 231 ms 13348 KB Output is correct
73 Correct 238 ms 13556 KB Output is correct
74 Correct 243 ms 13532 KB Output is correct
75 Correct 251 ms 13540 KB Output is correct
76 Correct 243 ms 13432 KB Output is correct
77 Correct 174 ms 13428 KB Output is correct
78 Correct 181 ms 13580 KB Output is correct
79 Correct 223 ms 13412 KB Output is correct
80 Correct 222 ms 13432 KB Output is correct