답안 #285742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285742 2020-08-29T14:18:03 Z TadijaSebez Long Distance Coach (JOI17_coach) C++11
100 / 100
261 ms 17144 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll lim=1e12;
const ll inf=1e18;
struct Line{
	ll k,n;
	Line(){}
	Line(ll a,ll b):k(a),n(b){}
	__int128 Get(ll x){return __int128(x)*__int128(k)+__int128(n);}
};
const int N=200050;
int ls[N],rs[N],tsz,root;
Line line[N];
void AddLine(int&c,ll ss,ll se,Line k){
	if(!c){c=++tsz;line[c]=k;return;}
	__int128 A=line[c].Get(ss),B=k.Get(ss),C=line[c].Get(se),D=k.Get(se);
	if(A<=B&&C<=D)return;
	if(A>=B&&C>=D){line[c]=k;return;}
	ll mid=ss+se>>1;
	if(A>B)swap(line[c],k);
	if(line[c].Get(mid)<=k.Get(mid))AddLine(rs[c],mid+1,se,k);
	else swap(k,line[c]),AddLine(ls[c],ss,mid,k);
}
__int128 Get(int c,ll ss,ll se,ll qi){
	if(!c)return __int128(inf);
	__int128 ans=line[c].Get(qi);
	if(ss==se)return ans;
	ll mid=ss+se>>1;
	if(qi<=mid)return min(ans,Get(ls[c],ss,mid,qi));
	else return min(ans,Get(rs[c],mid+1,se,qi));
}
ll s[N],mn[N],dp[N],pre[N];
pair<ll,ll> a[N];
int main(){
	int n,m;ll x,t,w;
	scanf("%lld %i %i %lld %lld",&x,&n,&m,&w,&t);
	for(int i=1;i<=n;i++)scanf("%lld",&s[i]);s[++n]=x;
	for(int i=1;i<=m;i++)scanf("%lld %lld",&a[i].first,&a[i].second),mn[i]=inf;
	sort(a+1,a+1+m);
	for(int i=1;i<=m;i++)pre[i]=pre[i-1]+a[i].second;
	for(int i=1;i<=n;i++){
		int j=upper_bound(a+1,a+1+m,(pair<ll,ll>){s[i]%t,inf})-a-1;
		mn[j]=min(mn[j],s[i]/t);
	}
	dp[0]=(x/t+1)*w;
	AddLine(root,0,lim,Line(0,dp[0]));
	for(int i=1;i<=m;i++){
		dp[i]=dp[i-1]+((x-a[i].first)/t+1)*w;
		if(mn[i]!=inf)dp[i]=min(dp[i],(ll)Get(root,0,lim,mn[i])+mn[i]*i*w+pre[i]);
		AddLine(root,0,lim,Line(-i*w,dp[i]-pre[i]));
	}
	printf("%lld\n",dp[m]);
	return 0;
}

Compilation message

coach.cpp: In function 'void AddLine(int&, long long int, long long int, Line)':
coach.cpp:20:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |  ll mid=ss+se>>1;
      |         ~~^~~
coach.cpp: In function '__int128 Get(int, long long int, long long int, long long int)':
coach.cpp:29:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |  ll mid=ss+se>>1;
      |         ~~^~~
coach.cpp: In function 'int main()':
coach.cpp:38:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   38 |  for(int i=1;i<=n;i++)scanf("%lld",&s[i]);s[++n]=x;
      |  ^~~
coach.cpp:38:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   38 |  for(int i=1;i<=n;i++)scanf("%lld",&s[i]);s[++n]=x;
      |                                           ^
coach.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%lld %i %i %lld %lld",&x,&n,&m,&w,&t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coach.cpp:38:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |  for(int i=1;i<=n;i++)scanf("%lld",&s[i]);s[++n]=x;
      |                       ~~~~~^~~~~~~~~~~~~~
coach.cpp:39:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |  for(int i=1;i<=m;i++)scanf("%lld %lld",&a[i].first,&a[i].second),mn[i]=inf;
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 372 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 416 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 372 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 416 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 372 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 416 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 512 KB Output is correct
52 Correct 221 ms 15480 KB Output is correct
53 Correct 180 ms 15480 KB Output is correct
54 Correct 261 ms 14588 KB Output is correct
55 Correct 241 ms 14844 KB Output is correct
56 Correct 215 ms 15096 KB Output is correct
57 Correct 241 ms 14968 KB Output is correct
58 Correct 199 ms 15352 KB Output is correct
59 Correct 223 ms 14840 KB Output is correct
60 Correct 233 ms 14712 KB Output is correct
61 Correct 225 ms 14840 KB Output is correct
62 Correct 224 ms 14840 KB Output is correct
63 Correct 227 ms 17144 KB Output is correct
64 Correct 208 ms 15608 KB Output is correct
65 Correct 165 ms 15608 KB Output is correct
66 Correct 141 ms 15480 KB Output is correct
67 Correct 188 ms 15480 KB Output is correct
68 Correct 180 ms 15528 KB Output is correct
69 Correct 213 ms 15224 KB Output is correct
70 Correct 217 ms 15348 KB Output is correct
71 Correct 208 ms 15356 KB Output is correct
72 Correct 216 ms 15224 KB Output is correct
73 Correct 220 ms 15224 KB Output is correct
74 Correct 198 ms 15224 KB Output is correct
75 Correct 187 ms 15480 KB Output is correct
76 Correct 183 ms 15356 KB Output is correct
77 Correct 246 ms 15096 KB Output is correct
78 Correct 236 ms 15480 KB Output is correct
79 Correct 215 ms 14840 KB Output is correct
80 Correct 212 ms 14840 KB Output is correct