답안 #826442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826442 2023-08-15T15:00:34 Z MohamedAhmed04 Long Distance Coach (JOI17_coach) C++14
100 / 100
454 ms 23888 KB
#pragma GCC optimize("trapv")

#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) ;
			//for(int j = i-1 ; j >= 0 ; --j)
			//	dp[i] = min(dp[i] , dp[j] + pref[i] - pref[j] + (i-j) * val[i] * w) ;
		}
		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 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 1 ms 340 KB Output is correct
9 Correct 1 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 348 KB Output is correct
16 Correct 1 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 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 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 1 ms 340 KB Output is correct
9 Correct 1 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 348 KB Output is correct
16 Correct 1 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 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 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 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 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 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 1 ms 340 KB Output is correct
9 Correct 1 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 348 KB Output is correct
16 Correct 1 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 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 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 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 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 3 ms 468 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 852 KB Output is correct
41 Correct 3 ms 488 KB Output is correct
42 Correct 4 ms 468 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 3 ms 468 KB Output is correct
46 Correct 4 ms 596 KB Output is correct
47 Correct 4 ms 596 KB Output is correct
48 Correct 4 ms 596 KB Output is correct
49 Correct 3 ms 468 KB Output is correct
50 Correct 5 ms 468 KB Output is correct
51 Correct 3 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 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 1 ms 340 KB Output is correct
9 Correct 1 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 348 KB Output is correct
16 Correct 1 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 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 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 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 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 3 ms 468 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 852 KB Output is correct
41 Correct 3 ms 488 KB Output is correct
42 Correct 4 ms 468 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 3 ms 468 KB Output is correct
46 Correct 4 ms 596 KB Output is correct
47 Correct 4 ms 596 KB Output is correct
48 Correct 4 ms 596 KB Output is correct
49 Correct 3 ms 468 KB Output is correct
50 Correct 5 ms 468 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 347 ms 12992 KB Output is correct
53 Correct 454 ms 23888 KB Output is correct
54 Correct 325 ms 17384 KB Output is correct
55 Correct 317 ms 17792 KB Output is correct
56 Correct 313 ms 17672 KB Output is correct
57 Correct 315 ms 20040 KB Output is correct
58 Correct 336 ms 18384 KB Output is correct
59 Correct 316 ms 17668 KB Output is correct
60 Correct 312 ms 17488 KB Output is correct
61 Correct 327 ms 17636 KB Output is correct
62 Correct 371 ms 18124 KB Output is correct
63 Correct 374 ms 23208 KB Output is correct
64 Correct 289 ms 15688 KB Output is correct
65 Correct 440 ms 21688 KB Output is correct
66 Correct 432 ms 21316 KB Output is correct
67 Correct 417 ms 22368 KB Output is correct
68 Correct 419 ms 21992 KB Output is correct
69 Correct 355 ms 18520 KB Output is correct
70 Correct 338 ms 18460 KB Output is correct
71 Correct 362 ms 18508 KB Output is correct
72 Correct 333 ms 18512 KB Output is correct
73 Correct 361 ms 18400 KB Output is correct
74 Correct 354 ms 18112 KB Output is correct
75 Correct 347 ms 18208 KB Output is correct
76 Correct 354 ms 18172 KB Output is correct
77 Correct 311 ms 15252 KB Output is correct
78 Correct 315 ms 15644 KB Output is correct
79 Correct 377 ms 18268 KB Output is correct
80 Correct 340 ms 18400 KB Output is correct