답안 #826443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826443 2023-08-15T15:01:34 Z MohamedAhmed04 Long Distance Coach (JOI17_coach) C++14
100 / 100
267 ms 19356 KB
#include <bits/stdc++.h>

using namespace std ;

struct Point
{
	long long x , y ;
};

__int128_t f(Point a , __int128_t x)
{
	return (x * a.x + a.y) ;
}

const long long inf = 3e18 ;
const int MAX = 2e5 + 10 ;
const int MAX2 = 1e7 + 10 ;

long long arr[MAX] ;
int n , m ;
long long x , t , w ;

vector< pair<long long , long long> >vp ;

long long val[MAX] , pref[MAX] ;
long long dp[MAX] ;

int L[MAX2] , R[MAX2] ;
Point Line[MAX2] ;
int id = 1 ;

void init()
{
	for(int i = 1 ; i < MAX2 ; ++i)
		Line[i].x = 0 , Line[i].y = inf ;
}

int Left(int node)
{
	if(!L[node])
		L[node] = ++id ;
	return L[node] ;
}

int Right(int node)
{
	if(!R[node])
		R[node] = ++id ;
	return R[node] ;
}

void Add_Line(Point p , int node = 1 , long long l = 0 , long long r = 1e12 + 100)
{
	long long m = l + (r-l) / 2ll ;
	bool lef = f(p , l) < f(Line[node] , l) ;
	bool mid = f(p , m) < f(Line[node] , m) ;
	if(mid)
		swap(Line[node] , p) ;
	if(r-l == 1)
		return ;
	if(lef != mid)
		Add_Line(p , Left(node) , l , m) ;
	else
		Add_Line(p , Right(node) , m , r) ;
}

__int128_t query(long long x , int node = 1 , long long l = 0 , long long r = 1e12 + 100)
{
	long long m = l + (r-l) / 2ll ;
	__int128_t now = f(Line[node] , x) ;
	if(r-l == 1)
		return now ;
	else if(x < m)
		return min(now , query(x , Left(node) , l , m)) ;
	else
		return min(now , query(x , Right(node) , m , r)) ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>x>>n>>m>>w>>t ;
	for(int i = 1 ; i <= n ; ++i)
		cin>>arr[i] ;
	for(int i = 1 ; i <= m ; ++i)
	{
		long long a , b ;
		cin>>a>>b ;
		vp.emplace_back(a , b) ;
	}
	vp.emplace_back(0 , 0) ;
	sort(arr+1 , arr+n+1) ;
	sort(vp.begin() , vp.end()) ;
	for(int i = 1 ; i <= m ; ++i)
		val[i] = inf , pref[i] = pref[i-1] + vp[i].second ;
	arr[n+1] = x ;
	for(int i = 1 ; i <= n+1 ; ++i)
	{
		int l = 1 , r = m ;
		int idx = -1 ;
		while(l <= r)
		{
			int mid = (l + r) >> 1 ;
			if(arr[i] % t >= vp[mid].first)
				idx = mid , l = mid+1 ;
			else
				r = mid-1 ;
		}
		if(idx != -1)
			val[idx] = min(val[idx] , arr[i] / t) ;
	}
	Point p ;
	p.x = 0 , p.y = 0 ;
	Add_Line(p) ;
	for(int i = 1 ; i <= m ; ++i)
	{
		dp[i] = dp[i-1] + x/t * w ;
		if(x%t > vp[i].first)
			dp[i] += w ;
		if(val[i] != inf)
		{
			//dp[j] + pref[i] - pref[j] + (i-j) * val[i] * w
			long long a = query(val[i]) ;
			dp[i] = min(dp[i] , pref[i] + i * val[i] * w + a) ;
		}
		p.x = -i * w , p.y = dp[i] - pref[i] ;
		Add_Line(p) ;
	}
	dp[m] += (x / t + 1) * w ;
	return cout<<dp[m]<<"\n" , 0 ;
}		
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 0 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 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 0 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 1 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 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 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 0 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 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 0 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 1 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 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 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 0 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 1 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 596 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 2 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 724 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 596 KB Output is correct
48 Correct 2 ms 596 KB Output is correct
49 Correct 3 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 0 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 1 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 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 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 0 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 1 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 596 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 2 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 724 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 596 KB Output is correct
48 Correct 2 ms 596 KB Output is correct
49 Correct 3 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 205 ms 13092 KB Output is correct
53 Correct 267 ms 18088 KB Output is correct
54 Correct 145 ms 12472 KB Output is correct
55 Correct 149 ms 12704 KB Output is correct
56 Correct 149 ms 12216 KB Output is correct
57 Correct 150 ms 14688 KB Output is correct
58 Correct 149 ms 12656 KB Output is correct
59 Correct 155 ms 12648 KB Output is correct
60 Correct 145 ms 12532 KB Output is correct
61 Correct 145 ms 12580 KB Output is correct
62 Correct 148 ms 12944 KB Output is correct
63 Correct 167 ms 19356 KB Output is correct
64 Correct 123 ms 9784 KB Output is correct
65 Correct 212 ms 15892 KB Output is correct
66 Correct 205 ms 15368 KB Output is correct
67 Correct 210 ms 16624 KB Output is correct
68 Correct 229 ms 16152 KB Output is correct
69 Correct 181 ms 12984 KB Output is correct
70 Correct 185 ms 13036 KB Output is correct
71 Correct 182 ms 13084 KB Output is correct
72 Correct 181 ms 13100 KB Output is correct
73 Correct 180 ms 12896 KB Output is correct
74 Correct 180 ms 12560 KB Output is correct
75 Correct 178 ms 12468 KB Output is correct
76 Correct 179 ms 12448 KB Output is correct
77 Correct 149 ms 9928 KB Output is correct
78 Correct 146 ms 9912 KB Output is correct
79 Correct 179 ms 13164 KB Output is correct
80 Correct 181 ms 13164 KB Output is correct