Submission #284250

# Submission time Handle Problem Language Result Execution time Memory
284250 2020-08-27T05:09:13 Z 임성재(#5754) Discharging (NOI20_discharging) C++17
100 / 100
886 ms 18200 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n;
ll t[1000010];
ll dp[1000010];
vector<pll> v;

ll cross(pll x, pll y) {
	if(x.fi < y.fi) swap(x, y);

	return (y.se - x.se) / (x.fi - y.fi);
}

int main() {
	cin >> n;

	for(int i=1; i<=n; i++) {
		cin >> t[i];
		t[i] = max(t[i], t[i-1]);
	}

	v.eb(n, 0);
	int idx = 0;

	for(int i=1; i<=n; i++) {
		dp[i] = INF;

		if(t[i] == t[i+1]) continue;

		while(idx+1 < v.size()) {
			if(cross(v[idx], v[idx+1]) < t[i]) idx++;
			else break;
		}

		dp[i] = v[idx].fi * t[i] + v[idx].se;

		while(v.size() > 1) {
			pll f = v[v.size()-2];
			pll s = v[v.size()-1];

			if(cross(f, s) >= cross(s, mp(n-i, dp[i])))	v.pop_back();
			else break;
		} 

		v.eb(n - i, dp[i]);
	}

	cout << dp[n];
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:45:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   while(idx+1 < v.size()) {
      |         ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 532 ms 17144 KB Output is correct
17 Correct 587 ms 16888 KB Output is correct
18 Correct 498 ms 17016 KB Output is correct
19 Correct 591 ms 16920 KB Output is correct
20 Correct 587 ms 16832 KB Output is correct
21 Correct 613 ms 17032 KB Output is correct
22 Correct 556 ms 16888 KB Output is correct
23 Correct 658 ms 17044 KB Output is correct
24 Correct 601 ms 16888 KB Output is correct
25 Correct 616 ms 16888 KB Output is correct
26 Correct 654 ms 16888 KB Output is correct
27 Correct 528 ms 17016 KB Output is correct
28 Correct 603 ms 16908 KB Output is correct
29 Correct 605 ms 17016 KB Output is correct
30 Correct 622 ms 16888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 843 ms 16976 KB Output is correct
2 Correct 850 ms 17016 KB Output is correct
3 Correct 838 ms 16888 KB Output is correct
4 Correct 867 ms 16808 KB Output is correct
5 Correct 886 ms 16888 KB Output is correct
6 Correct 836 ms 17016 KB Output is correct
7 Correct 847 ms 16816 KB Output is correct
8 Correct 866 ms 17016 KB Output is correct
9 Correct 876 ms 16996 KB Output is correct
10 Correct 851 ms 16884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 512 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 532 ms 17144 KB Output is correct
31 Correct 587 ms 16888 KB Output is correct
32 Correct 498 ms 17016 KB Output is correct
33 Correct 591 ms 16920 KB Output is correct
34 Correct 587 ms 16832 KB Output is correct
35 Correct 613 ms 17032 KB Output is correct
36 Correct 556 ms 16888 KB Output is correct
37 Correct 658 ms 17044 KB Output is correct
38 Correct 601 ms 16888 KB Output is correct
39 Correct 616 ms 16888 KB Output is correct
40 Correct 654 ms 16888 KB Output is correct
41 Correct 528 ms 17016 KB Output is correct
42 Correct 603 ms 16908 KB Output is correct
43 Correct 605 ms 17016 KB Output is correct
44 Correct 622 ms 16888 KB Output is correct
45 Correct 843 ms 16976 KB Output is correct
46 Correct 850 ms 17016 KB Output is correct
47 Correct 838 ms 16888 KB Output is correct
48 Correct 867 ms 16808 KB Output is correct
49 Correct 886 ms 16888 KB Output is correct
50 Correct 836 ms 17016 KB Output is correct
51 Correct 847 ms 16816 KB Output is correct
52 Correct 866 ms 17016 KB Output is correct
53 Correct 876 ms 16996 KB Output is correct
54 Correct 851 ms 16884 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 2 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 2 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 512 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 2 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 2 ms 384 KB Output is correct
76 Correct 574 ms 17276 KB Output is correct
77 Correct 574 ms 16888 KB Output is correct
78 Correct 527 ms 16888 KB Output is correct
79 Correct 547 ms 17144 KB Output is correct
80 Correct 599 ms 17016 KB Output is correct
81 Correct 539 ms 18024 KB Output is correct
82 Correct 546 ms 17912 KB Output is correct
83 Correct 569 ms 18200 KB Output is correct
84 Correct 567 ms 18040 KB Output is correct
85 Correct 583 ms 18040 KB Output is correct
86 Correct 540 ms 18040 KB Output is correct
87 Correct 533 ms 18040 KB Output is correct
88 Correct 552 ms 18040 KB Output is correct
89 Correct 557 ms 18040 KB Output is correct
90 Correct 536 ms 17912 KB Output is correct
91 Correct 521 ms 18192 KB Output is correct
92 Correct 666 ms 18168 KB Output is correct
93 Correct 596 ms 17912 KB Output is correct
94 Correct 526 ms 18040 KB Output is correct
95 Correct 630 ms 18040 KB Output is correct
96 Correct 576 ms 18192 KB Output is correct
97 Correct 539 ms 17912 KB Output is correct
98 Correct 579 ms 17924 KB Output is correct
99 Correct 539 ms 17912 KB Output is correct
100 Correct 546 ms 18184 KB Output is correct