답안 #751262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751262 2023-05-31T10:04:26 Z dsyz Discharging (NOI20_discharging) C++17
100 / 100
138 ms 33596 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
struct ConvexHull {
	deque<pair<ll,ll> > dq;
	ll f(pair<ll,ll> line,ll x){
		return line.first * x + line.second;
	}
	ll query(ll x){
		while(dq.size() > 1){
			if(f(dq[0],x) < f(dq[1],x)){
				dq.pop_front();
			}else{
				break;
			}
		}
		return f(dq[0],x);
	}
	long double Intersect(ll a,ll b,ll c,ll d){
		return (long double)(d - b) / (a - c);
	}
	long double intersect(pair<ll,ll> p1,pair<ll,ll> p2){
		return Intersect(p1.first,p1.second,p2.first,p2.second);
	}
	void ins(ll m,ll c){
		pair<ll,ll> line = make_pair(m,c);
		while(dq.size() > 1){
			ll s = dq.size();
			if(intersect(dq[s - 1],line) <= intersect(dq[s - 2],line)){
				dq.pop_back();
			}else{
				break;
			}
		}
		dq.push_back(line);
	}
} CH; //returns maximum y
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll N;
	cin>>N;
	ll T[N + 1];
	for(ll i = 1;i <= N;i++){
		cin>>T[i];
	}
	T[0] = 0;
	ll premaxT[N + 1];
	premaxT[0] = 0;
	for(ll i = 1;i <= N;i++){
		premaxT[i] = max(premaxT[i - 1],T[i]);
	}
	ll dp[N + 1];
	dp[0] = 0;
	CH.dq.clear();
	CH.ins(-N,0);
	for(ll i = 1;i <= N;i++){
		if(premaxT[i - 1] < T[i]){
			dp[i] = -CH.query(T[i]);
			ll ptr = i;
			while(ptr < N && T[ptr] <= T[i]){
				ptr++;
			}
			CH.ins(ptr - N - 1,-dp[i]);
		}else{
			dp[i] = dp[i - 1];
		}
	}
	cout<<dp[N]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 424 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 424 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 100 ms 28840 KB Output is correct
17 Correct 99 ms 29624 KB Output is correct
18 Correct 81 ms 28096 KB Output is correct
19 Correct 93 ms 29488 KB Output is correct
20 Correct 106 ms 29392 KB Output is correct
21 Correct 93 ms 29496 KB Output is correct
22 Correct 97 ms 29104 KB Output is correct
23 Correct 114 ms 30228 KB Output is correct
24 Correct 99 ms 29616 KB Output is correct
25 Correct 110 ms 30012 KB Output is correct
26 Correct 116 ms 30384 KB Output is correct
27 Correct 100 ms 28856 KB Output is correct
28 Correct 103 ms 29644 KB Output is correct
29 Correct 106 ms 29872 KB Output is correct
30 Correct 105 ms 30128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 33580 KB Output is correct
2 Correct 120 ms 33336 KB Output is correct
3 Correct 138 ms 33416 KB Output is correct
4 Correct 103 ms 33344 KB Output is correct
5 Correct 113 ms 33464 KB Output is correct
6 Correct 128 ms 33460 KB Output is correct
7 Correct 106 ms 33464 KB Output is correct
8 Correct 109 ms 33340 KB Output is correct
9 Correct 130 ms 33592 KB Output is correct
10 Correct 116 ms 33596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 424 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 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 328 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 304 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 424 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 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 100 ms 28840 KB Output is correct
31 Correct 99 ms 29624 KB Output is correct
32 Correct 81 ms 28096 KB Output is correct
33 Correct 93 ms 29488 KB Output is correct
34 Correct 106 ms 29392 KB Output is correct
35 Correct 93 ms 29496 KB Output is correct
36 Correct 97 ms 29104 KB Output is correct
37 Correct 114 ms 30228 KB Output is correct
38 Correct 99 ms 29616 KB Output is correct
39 Correct 110 ms 30012 KB Output is correct
40 Correct 116 ms 30384 KB Output is correct
41 Correct 100 ms 28856 KB Output is correct
42 Correct 103 ms 29644 KB Output is correct
43 Correct 106 ms 29872 KB Output is correct
44 Correct 105 ms 30128 KB Output is correct
45 Correct 104 ms 33580 KB Output is correct
46 Correct 120 ms 33336 KB Output is correct
47 Correct 138 ms 33416 KB Output is correct
48 Correct 103 ms 33344 KB Output is correct
49 Correct 113 ms 33464 KB Output is correct
50 Correct 128 ms 33460 KB Output is correct
51 Correct 106 ms 33464 KB Output is correct
52 Correct 109 ms 33340 KB Output is correct
53 Correct 130 ms 33592 KB Output is correct
54 Correct 116 ms 33596 KB Output is correct
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 328 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 320 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 320 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 328 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 304 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 95 ms 29752 KB Output is correct
77 Correct 107 ms 29744 KB Output is correct
78 Correct 89 ms 29112 KB Output is correct
79 Correct 87 ms 29356 KB Output is correct
80 Correct 107 ms 30004 KB Output is correct
81 Correct 80 ms 29232 KB Output is correct
82 Correct 86 ms 29240 KB Output is correct
83 Correct 96 ms 29740 KB Output is correct
84 Correct 86 ms 29504 KB Output is correct
85 Correct 94 ms 29752 KB Output is correct
86 Correct 113 ms 29220 KB Output is correct
87 Correct 83 ms 29116 KB Output is correct
88 Correct 87 ms 29492 KB Output is correct
89 Correct 86 ms 29244 KB Output is correct
90 Correct 81 ms 29236 KB Output is correct
91 Correct 84 ms 28976 KB Output is correct
92 Correct 113 ms 30384 KB Output is correct
93 Correct 100 ms 29500 KB Output is correct
94 Correct 95 ms 28732 KB Output is correct
95 Correct 91 ms 30132 KB Output is correct
96 Correct 95 ms 29228 KB Output is correct
97 Correct 90 ms 29388 KB Output is correct
98 Correct 85 ms 29496 KB Output is correct
99 Correct 81 ms 29132 KB Output is correct
100 Correct 84 ms 29244 KB Output is correct