답안 #498766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498766 2021-12-26T10:13:15 Z jiahng Discharging (NOI20_discharging) C++14
100 / 100
141 ms 22596 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define MOD 1000000007
#define maxn 1000010
#define INF (ll)1e18

int N;
int dp[maxn], T[maxn];
int f(pi line, int x){
	return line.f * x + line.s;
}

ld intersect(pi line1, pi line2){
	return (line2.s - line1.s) / (line1.f - line2.f);
}

struct Hull{ // Min, decreasing gradients, increasing queries
	deque <pi> dq;
	int query(int x){
		while (dq.size() > 1 && f(dq[0], x) > f(dq[1], x)) dq.pop_front();
		return f(dq[0], x);
	}
	void insert(pi line){
		while (dq.size() > 1 && intersect(line, dq.back()) <= intersect(line, dq[dq.size() - 2])) dq.pop_back();
		dq.pb(line);
	}
}hull;
pi ssmx[maxn];

int32_t main(){
    fast;
    
	cin >> N;
	FOR(i,1,N) cin >> T[i];
	int mx = 1;
	
	int co = 1;
	FOR(i,1,N){
		if (T[i] >= T[mx]) mx = i;
		while (co <= mx){
			hull.insert(pi(-co, dp[co-1]));
			co++;
		}
		if (i > 1) dp[i] = min(T[mx]*N, hull.query(T[mx]) + T[mx] * (N + 1));
		else dp[i] = T[1] * N;
		
		
		//~ cout << dp[i] << ' ';
	}
	cout << dp[N];
	
}



# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 100 ms 15880 KB Output is correct
17 Correct 132 ms 21804 KB Output is correct
18 Correct 97 ms 20364 KB Output is correct
19 Correct 131 ms 21844 KB Output is correct
20 Correct 141 ms 21572 KB Output is correct
21 Correct 128 ms 21720 KB Output is correct
22 Correct 122 ms 21348 KB Output is correct
23 Correct 119 ms 22324 KB Output is correct
24 Correct 127 ms 21792 KB Output is correct
25 Correct 111 ms 22228 KB Output is correct
26 Correct 128 ms 22596 KB Output is correct
27 Correct 109 ms 20940 KB Output is correct
28 Correct 115 ms 21792 KB Output is correct
29 Correct 123 ms 22020 KB Output is correct
30 Correct 114 ms 22280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 15940 KB Output is correct
2 Correct 112 ms 15912 KB Output is correct
3 Correct 99 ms 15872 KB Output is correct
4 Correct 98 ms 15936 KB Output is correct
5 Correct 105 ms 15928 KB Output is correct
6 Correct 115 ms 15912 KB Output is correct
7 Correct 103 ms 15900 KB Output is correct
8 Correct 100 ms 15936 KB Output is correct
9 Correct 98 ms 15860 KB Output is correct
10 Correct 99 ms 15900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 100 ms 15880 KB Output is correct
31 Correct 132 ms 21804 KB Output is correct
32 Correct 97 ms 20364 KB Output is correct
33 Correct 131 ms 21844 KB Output is correct
34 Correct 141 ms 21572 KB Output is correct
35 Correct 128 ms 21720 KB Output is correct
36 Correct 122 ms 21348 KB Output is correct
37 Correct 119 ms 22324 KB Output is correct
38 Correct 127 ms 21792 KB Output is correct
39 Correct 111 ms 22228 KB Output is correct
40 Correct 128 ms 22596 KB Output is correct
41 Correct 109 ms 20940 KB Output is correct
42 Correct 115 ms 21792 KB Output is correct
43 Correct 123 ms 22020 KB Output is correct
44 Correct 114 ms 22280 KB Output is correct
45 Correct 127 ms 15940 KB Output is correct
46 Correct 112 ms 15912 KB Output is correct
47 Correct 99 ms 15872 KB Output is correct
48 Correct 98 ms 15936 KB Output is correct
49 Correct 105 ms 15928 KB Output is correct
50 Correct 115 ms 15912 KB Output is correct
51 Correct 103 ms 15900 KB Output is correct
52 Correct 100 ms 15936 KB Output is correct
53 Correct 98 ms 15860 KB Output is correct
54 Correct 99 ms 15900 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 1 ms 332 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 1 ms 332 KB Output is correct
68 Correct 1 ms 332 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 1 ms 332 KB Output is correct
74 Correct 1 ms 332 KB Output is correct
75 Correct 1 ms 332 KB Output is correct
76 Correct 130 ms 21972 KB Output is correct
77 Correct 119 ms 21920 KB Output is correct
78 Correct 112 ms 21328 KB Output is correct
79 Correct 107 ms 21628 KB Output is correct
80 Correct 111 ms 22264 KB Output is correct
81 Correct 115 ms 21560 KB Output is correct
82 Correct 120 ms 21392 KB Output is correct
83 Correct 110 ms 22012 KB Output is correct
84 Correct 119 ms 21692 KB Output is correct
85 Correct 138 ms 22112 KB Output is correct
86 Correct 123 ms 21444 KB Output is correct
87 Correct 105 ms 21280 KB Output is correct
88 Correct 119 ms 21680 KB Output is correct
89 Correct 110 ms 21452 KB Output is correct
90 Correct 113 ms 21372 KB Output is correct
91 Correct 107 ms 21100 KB Output is correct
92 Correct 129 ms 22400 KB Output is correct
93 Correct 108 ms 21712 KB Output is correct
94 Correct 108 ms 20936 KB Output is correct
95 Correct 110 ms 22240 KB Output is correct
96 Correct 109 ms 21116 KB Output is correct
97 Correct 114 ms 21636 KB Output is correct
98 Correct 115 ms 21708 KB Output is correct
99 Correct 110 ms 21444 KB Output is correct
100 Correct 111 ms 21392 KB Output is correct