답안 #127977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
127977 2019-07-10T09:45:29 Z ainta Long Distance Coach (JOI17_coach) C++17
100 / 100
480 ms 38264 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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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
# 결과 실행 시간 메모리 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 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 376 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 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 376 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 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 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 504 KB Output is correct
39 Correct 4 ms 508 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 4 ms 632 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 532 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 504 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 3 ms 504 KB Output is correct
50 Correct 4 ms 504 KB Output is correct
51 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 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 376 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 380 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 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 376 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 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 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 504 KB Output is correct
39 Correct 4 ms 508 KB Output is correct
40 Correct 4 ms 504 KB Output is correct
41 Correct 4 ms 632 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 532 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 504 KB Output is correct
48 Correct 4 ms 504 KB Output is correct
49 Correct 3 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 230 ms 15808 KB Output is correct
53 Correct 241 ms 16168 KB Output is correct
54 Correct 212 ms 16364 KB Output is correct
55 Correct 215 ms 16376 KB Output is correct
56 Correct 217 ms 16376 KB Output is correct
57 Correct 196 ms 16244 KB Output is correct
58 Correct 210 ms 16220 KB Output is correct
59 Correct 216 ms 16376 KB Output is correct
60 Correct 212 ms 16376 KB Output is correct
61 Correct 217 ms 16384 KB Output is correct
62 Correct 212 ms 16396 KB Output is correct
63 Correct 480 ms 38264 KB Output is correct
64 Correct 147 ms 16248 KB Output is correct
65 Correct 243 ms 16284 KB Output is correct
66 Correct 250 ms 16256 KB Output is correct
67 Correct 228 ms 16220 KB Output is correct
68 Correct 234 ms 16532 KB Output is correct
69 Correct 227 ms 16232 KB Output is correct
70 Correct 228 ms 16376 KB Output is correct
71 Correct 229 ms 16348 KB Output is correct
72 Correct 233 ms 16312 KB Output is correct
73 Correct 247 ms 16240 KB Output is correct
74 Correct 245 ms 16508 KB Output is correct
75 Correct 257 ms 16248 KB Output is correct
76 Correct 247 ms 16332 KB Output is correct
77 Correct 176 ms 16396 KB Output is correct
78 Correct 183 ms 16288 KB Output is correct
79 Correct 225 ms 16248 KB Output is correct
80 Correct 225 ms 16248 KB Output is correct