답안 #412659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412659 2021-05-27T09:41:41 Z amoo_safar Long Distance Coach (JOI17_coach) C++17
71 / 100
2000 ms 7440 KB
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

ll dp[N];
ll rif[N];
ll mn[N];

typedef pll Line;
vector< pair<ll, Line> > CHT;
ll Inter(Line A, Line B){
	return (A.S - B.S) / (B.F - A.F) + ((A.S - B.S) % (B.F - A.F) > 0);
}
void Add(Line A){
	while(!CHT.empty() && Inter(CHT.back().S, A) <= CHT.back().F)
		CHT.pop_back();
	CHT.pb({CHT.empty() ? -Inf : Inter(CHT.back().S, A), A});
}
ll Get(ll X){
	int idx = upper_bound(all(CHT), pair<ll, Line>(X, pll(Inf, Inf))) - CHT.begin();
	idx --;
	return CHT[idx].S.F * X + CHT[idx].S.S;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll X, n, m, W, T;
	cin >> X >> n >> m >> W >> T;
	
	vector<pll> D = { {0, 0} }; // D, C
	for(int i = 0; i < n; i++)
		cin >> rif[i];
	rif[n] = X;

	int d, c;
	for(int i = 0; i < m; i++){
		cin >> d >> c;
		D.pb({d, c});
	}
	sort(all(D));
	for(int i = 1; i <= m; i++) D[i].S += D[i - 1].S;
	memset(mn, 31, sizeof mn);
	for(int i = 0; i <= n; i++){
		int idx = lower_bound(all(D), pll(rif[i] % T, -1)) - D.begin();
		idx --;
		assert(0 <= idx);
		mn[idx] = min(mn[idx], rif[i]);
	}
	dp[0] = ((X + T) / T) * W;
	for(int i = 1; i <= m; i++){
		Add({-(i - 1), dp[i - 1] - D[i - 1].S});
		dp[i] = dp[i - 1] + ( 1 + ((X - D[i].F) / T) ) * W;
		// debug(mn[i]);
		if(mn[i] >= Inf) continue;
		
		ll fac = mn[i] / T;
		// debug(fac);
		for(int j = 0; j < i; j++)
			dp[i] = min(dp[i], D[i].S + i * fac * W + Get(fac * W));
	}

	//
	// for(auto [d, c] : D) cerr << "(" << d << ", " << c << ")\n";
	// for(int i = 0; i <= m; i++) cerr << dp[i] << ' ';
	// cerr << '\n';
	//
	cout << dp[m] << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1852 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1868 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1856 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 2 ms 1856 KB Output is correct
16 Correct 2 ms 1868 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
18 Correct 1 ms 1868 KB Output is correct
19 Correct 2 ms 1856 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1856 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1852 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1868 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1856 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 2 ms 1856 KB Output is correct
16 Correct 2 ms 1868 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
18 Correct 1 ms 1868 KB Output is correct
19 Correct 2 ms 1856 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1856 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1856 KB Output is correct
24 Correct 2 ms 1860 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1868 KB Output is correct
29 Correct 2 ms 1868 KB Output is correct
30 Correct 2 ms 1868 KB Output is correct
31 Correct 2 ms 1868 KB Output is correct
32 Correct 2 ms 1868 KB Output is correct
33 Correct 2 ms 1868 KB Output is correct
34 Correct 2 ms 1852 KB Output is correct
35 Correct 2 ms 1868 KB Output is correct
36 Correct 2 ms 1868 KB Output is correct
37 Correct 2 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1852 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1868 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1856 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 2 ms 1856 KB Output is correct
16 Correct 2 ms 1868 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
18 Correct 1 ms 1868 KB Output is correct
19 Correct 2 ms 1856 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1856 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1856 KB Output is correct
24 Correct 2 ms 1860 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1868 KB Output is correct
29 Correct 2 ms 1868 KB Output is correct
30 Correct 2 ms 1868 KB Output is correct
31 Correct 2 ms 1868 KB Output is correct
32 Correct 2 ms 1868 KB Output is correct
33 Correct 2 ms 1868 KB Output is correct
34 Correct 2 ms 1852 KB Output is correct
35 Correct 2 ms 1868 KB Output is correct
36 Correct 2 ms 1868 KB Output is correct
37 Correct 2 ms 1868 KB Output is correct
38 Correct 13 ms 1992 KB Output is correct
39 Correct 21 ms 2032 KB Output is correct
40 Correct 22 ms 1996 KB Output is correct
41 Correct 10 ms 2020 KB Output is correct
42 Correct 10 ms 1912 KB Output is correct
43 Correct 10 ms 2012 KB Output is correct
44 Correct 11 ms 2036 KB Output is correct
45 Correct 10 ms 2028 KB Output is correct
46 Correct 46 ms 2056 KB Output is correct
47 Correct 20 ms 2028 KB Output is correct
48 Correct 11 ms 1996 KB Output is correct
49 Correct 10 ms 2036 KB Output is correct
50 Correct 12 ms 1996 KB Output is correct
51 Correct 13 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1852 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1868 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 1856 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1868 KB Output is correct
13 Correct 2 ms 1868 KB Output is correct
14 Correct 2 ms 1868 KB Output is correct
15 Correct 2 ms 1856 KB Output is correct
16 Correct 2 ms 1868 KB Output is correct
17 Correct 1 ms 1868 KB Output is correct
18 Correct 1 ms 1868 KB Output is correct
19 Correct 2 ms 1856 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1856 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1856 KB Output is correct
24 Correct 2 ms 1860 KB Output is correct
25 Correct 2 ms 1868 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1868 KB Output is correct
29 Correct 2 ms 1868 KB Output is correct
30 Correct 2 ms 1868 KB Output is correct
31 Correct 2 ms 1868 KB Output is correct
32 Correct 2 ms 1868 KB Output is correct
33 Correct 2 ms 1868 KB Output is correct
34 Correct 2 ms 1852 KB Output is correct
35 Correct 2 ms 1868 KB Output is correct
36 Correct 2 ms 1868 KB Output is correct
37 Correct 2 ms 1868 KB Output is correct
38 Correct 13 ms 1992 KB Output is correct
39 Correct 21 ms 2032 KB Output is correct
40 Correct 22 ms 1996 KB Output is correct
41 Correct 10 ms 2020 KB Output is correct
42 Correct 10 ms 1912 KB Output is correct
43 Correct 10 ms 2012 KB Output is correct
44 Correct 11 ms 2036 KB Output is correct
45 Correct 10 ms 2028 KB Output is correct
46 Correct 46 ms 2056 KB Output is correct
47 Correct 20 ms 2028 KB Output is correct
48 Correct 11 ms 1996 KB Output is correct
49 Correct 10 ms 2036 KB Output is correct
50 Correct 12 ms 1996 KB Output is correct
51 Correct 13 ms 2028 KB Output is correct
52 Execution timed out 2068 ms 7440 KB Time limit exceeded
53 Halted 0 ms 0 KB -