Submission #821661

# Submission time Handle Problem Language Result Execution time Memory
821661 2023-08-11T12:42:53 Z AdamGS Long Distance Coach (JOI17_coach) C++17
100 / 100
210 ms 29388 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t ll2;
typedef struct item * pitem;
#define rep(a, b) for(ll a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll2 INF=2e18+7;
const int LIM=2e5+7;
struct item {
	pitem l=nullptr, r=nullptr;
	ll2 a=0, b=INF;
};
ll2 dp[LIM], pref[LIM];
ll T[LIM], kiedy[LIM], x, n, m, w, t, N=1;
pair<ll,ll>P[LIM];
void upd(pitem &v, ll2 l, ll2 r, ll2 a, ll2 b) {
	ll2 mid=(l+r-1)/2;
	if(v->a*mid+v->b>a*mid+b) {
		swap(v->a, a);
		swap(v->b, b);
	}
	if(a==0 && b==INF || l==r) return;
	if(a<v->a) {
		if(!v->r) v->r=new item();
		upd(v->r, mid+1, r, a, b);
	} else {
		if(!v->l) v->l=new item();
		upd(v->l, l, mid, a, b);
	}
}
ll2 cnt(pitem &v, ll2 l, ll2 r, ll2 x) {
	if(!v) return INF;
	ll2 ans=v->a*x+v->b, mid=(l+r-1)/2;
	if(l==r) return ans;
	if(x<=mid) ans=min(ans, cnt(v->l, l, mid, x));
	else ans=min(ans, cnt(v->r, mid+1, r, x));
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> x >> n >> m >> w >> t;
	rep(i, 40) N*=2;
	pitem root=new item();
	rep(i, n) cin >> T[i];
	T[n]=x; ++n;
	rep(i, m) cin >> P[i].st >> P[i].nd;
	sort(T, T+n);
	sort(P, P+m);
	rep(i, m) {
		kiedy[i]=INF;
		pref[i]=P[i].nd;
		if(i) pref[i]+=pref[i-1];
	}
	rep(i, n) {
		ll po=0, ko=m-1;
		while(po<ko) {
			ll sr=(po+ko+1)/2;
			if(P[sr].st>T[i]%t) ko=sr-1; else po=sr;
		}
		if(P[po].st>T[i]%t) continue;
		kiedy[po]=min(kiedy[po], T[i]/t);
	}
	rep(i, m) {
		ll ile=w*(x/t);
		if(x%t>P[i].st) ile+=w;
		dp[i]=ile;
		if(i) dp[i]+=dp[i-1];
		if(kiedy[i]!=INF) {
			dp[i]=min(dp[i], pref[i]+i*kiedy[i]*w+cnt(root, -N+1, 0, -kiedy[i]));
			dp[i]=min(dp[i], pref[i]+(i+1)*kiedy[i]*w);
		}
		upd(root, -N+1, 0, i*w, dp[i]-pref[i]);
	}
	cout << (ll)(dp[m-1])+w*(x/t+1) << '\n';
}

Compilation message

coach.cpp: In function 'void upd(item*&, ll2, ll2, ll2, ll2)':
coach.cpp:26:10: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   26 |  if(a==0 && b==INF || l==r) return;
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 2 ms 596 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 197 ms 12892 KB Output is correct
53 Correct 210 ms 12948 KB Output is correct
54 Correct 162 ms 13004 KB Output is correct
55 Correct 166 ms 18124 KB Output is correct
56 Correct 166 ms 18240 KB Output is correct
57 Correct 171 ms 18356 KB Output is correct
58 Correct 169 ms 18508 KB Output is correct
59 Correct 165 ms 18064 KB Output is correct
60 Correct 171 ms 17976 KB Output is correct
61 Correct 164 ms 18040 KB Output is correct
62 Correct 166 ms 17980 KB Output is correct
63 Correct 168 ms 29388 KB Output is correct
64 Correct 130 ms 18652 KB Output is correct
65 Correct 194 ms 18704 KB Output is correct
66 Correct 182 ms 18544 KB Output is correct
67 Correct 199 ms 18756 KB Output is correct
68 Correct 202 ms 18676 KB Output is correct
69 Correct 205 ms 18500 KB Output is correct
70 Correct 199 ms 18444 KB Output is correct
71 Correct 194 ms 18420 KB Output is correct
72 Correct 197 ms 18464 KB Output is correct
73 Correct 197 ms 18420 KB Output is correct
74 Correct 197 ms 18516 KB Output is correct
75 Correct 196 ms 18476 KB Output is correct
76 Correct 183 ms 18504 KB Output is correct
77 Correct 185 ms 18252 KB Output is correct
78 Correct 175 ms 18776 KB Output is correct
79 Correct 201 ms 18048 KB Output is correct
80 Correct 194 ms 18064 KB Output is correct