Submission #284246

# Submission time Handle Problem Language Result Execution time Memory
284246 2020-08-27T04:57:37 Z 임성재(#5754) Discharging (NOI20_discharging) C++17
72 / 100
852 ms 18168 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;

bool cross(int i, int j, ll x) {
	return v[i].fi * x + v[i].se > v[j].fi * x + v[j].se;
}

bool chk(pll x) {
	pll f = v[v.size()-2];
	pll s = v[v.size()-1];

	//cout << (x.se - s.se) * (f.fi - x.fi) << "!! " << (x.se - f.se) * (s.fi - x.fi) << endl;

	return (x.se - s.se) * (f.fi - x.fi) <= (x.se - f.se) * (s.fi - x.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(idx, idx+1, t[i])) idx++;
			else break;
		}

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

		while(v.size() > 1 && chk(mp(n-i, dp[i]))) v.pop_back();

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

		/*cout << i << "\n";

		for(auto j : v) {
			cout << j.fi << " " << j.se << "\n"; 
		}
		cout << dp[i] << " " << v.size() << "\n";
		cout << "\n";*/
	}

	cout << dp[n];
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:52: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]
   52 |   while(idx+1 < v.size()) {
      |         ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 276 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 416 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 384 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 1 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 3 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 1 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 384 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 1 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 3 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 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 511 ms 18168 KB Output is correct
17 Correct 568 ms 17876 KB Output is correct
18 Correct 463 ms 17912 KB Output is correct
19 Correct 570 ms 17912 KB Output is correct
20 Correct 555 ms 18008 KB Output is correct
21 Correct 560 ms 17784 KB Output is correct
22 Correct 532 ms 17804 KB Output is correct
23 Correct 608 ms 17912 KB Output is correct
24 Correct 577 ms 18008 KB Output is correct
25 Correct 596 ms 17784 KB Output is correct
26 Correct 649 ms 17808 KB Output is correct
27 Correct 504 ms 17784 KB Output is correct
28 Correct 580 ms 17784 KB Output is correct
29 Correct 581 ms 17784 KB Output is correct
30 Correct 602 ms 17784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 832 ms 18040 KB Output is correct
2 Correct 835 ms 17528 KB Output is correct
3 Correct 840 ms 17492 KB Output is correct
4 Correct 833 ms 17528 KB Output is correct
5 Correct 838 ms 17528 KB Output is correct
6 Correct 832 ms 17528 KB Output is correct
7 Correct 832 ms 17460 KB Output is correct
8 Correct 852 ms 17528 KB Output is correct
9 Correct 846 ms 17424 KB Output is correct
10 Correct 844 ms 17556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 276 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 416 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 384 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 1 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 3 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 1 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 1 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 2 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 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 2 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 2 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 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 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 276 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 416 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 384 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 1 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 3 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 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 511 ms 18168 KB Output is correct
31 Correct 568 ms 17876 KB Output is correct
32 Correct 463 ms 17912 KB Output is correct
33 Correct 570 ms 17912 KB Output is correct
34 Correct 555 ms 18008 KB Output is correct
35 Correct 560 ms 17784 KB Output is correct
36 Correct 532 ms 17804 KB Output is correct
37 Correct 608 ms 17912 KB Output is correct
38 Correct 577 ms 18008 KB Output is correct
39 Correct 596 ms 17784 KB Output is correct
40 Correct 649 ms 17808 KB Output is correct
41 Correct 504 ms 17784 KB Output is correct
42 Correct 580 ms 17784 KB Output is correct
43 Correct 581 ms 17784 KB Output is correct
44 Correct 602 ms 17784 KB Output is correct
45 Correct 832 ms 18040 KB Output is correct
46 Correct 835 ms 17528 KB Output is correct
47 Correct 840 ms 17492 KB Output is correct
48 Correct 833 ms 17528 KB Output is correct
49 Correct 838 ms 17528 KB Output is correct
50 Correct 832 ms 17528 KB Output is correct
51 Correct 832 ms 17460 KB Output is correct
52 Correct 852 ms 17528 KB Output is correct
53 Correct 846 ms 17424 KB Output is correct
54 Correct 844 ms 17556 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 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 2 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 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 2 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 2 ms 384 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 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 1 ms 384 KB Output is correct
76 Correct 568 ms 17656 KB Output is correct
77 Correct 573 ms 17656 KB Output is correct
78 Correct 545 ms 17248 KB Output is correct
79 Correct 549 ms 17276 KB Output is correct
80 Incorrect 595 ms 17400 KB Output isn't correct
81 Halted 0 ms 0 KB -