답안 #995333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995333 2024-06-08T20:25:11 Z vyshniak_n Discharging (NOI20_discharging) C++17
100 / 100
112 ms 25728 KB
//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma traget("avx,avx2")

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define el '\n'
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define point pair <ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

#include <random>
mt19937 rnd(time(0));

const ll INF = 1e18 + 10;
const ll inf = 1e9 + 10;
const ll N = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll LOG = 20;
const ll K = 1e3 + 20;

struct line {
    ll k, b;
};

vector <ld> dots;
vector <line> dq;
ll dp[N], t[N];

ld cross(line l, line r) {
    return (ld)(r.b - l.b) / (ld)(l.k - r.k);
}
void add(line x) {
    while (dq.size() >= 2 && cross(x, dq[dq.size() - 2]) <= cross(dq[dq.size() - 1], dq[dq.size() - 2])) {
        dots.popb();
        dq.popb();
    }

    if (!dq.empty())
        dots.pb(cross(dq.back(), x));
    dq.pb(x);
}
ll get(ll x) {
    if (dots.empty())
        return dq[0].k * x + dq[0].b;

    ll l = -1, r = dots.size();
    while (l + 1 < r) {
        ll mid = (l + r) >> 1;

        if (dots[mid] <= x) l = mid;
        else r = mid;
    }

    l++;
    return dq[l].k * x + dq[l].b;
}

void solve() {
    ll n;
    cin >> n;

    for (ll i = 1; i <= n; i++)
        cin >> t[i];

    add({n, dp[0]});
    ll mx = 0;
    for (ll i = 1; i <= n; i++) {
        mx = max(mx, t[i]);
        dp[i] = get(mx);
        add({n - i, dp[i]});
    }

    cout << dp[n] << el;
    return;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int tests = 1;
    //cin >> tests;

    while (tests--) 
        solve();
    return 0;
}
/*
kx + b = k1x + b1;
kx - k1x = b1 - b;
x = b1 - b

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 94 ms 20980 KB Output is correct
17 Correct 83 ms 21872 KB Output is correct
18 Correct 74 ms 20336 KB Output is correct
19 Correct 89 ms 21744 KB Output is correct
20 Correct 85 ms 21652 KB Output is correct
21 Correct 92 ms 21744 KB Output is correct
22 Correct 85 ms 21584 KB Output is correct
23 Correct 96 ms 22356 KB Output is correct
24 Correct 87 ms 22096 KB Output is correct
25 Correct 87 ms 22356 KB Output is correct
26 Correct 98 ms 22528 KB Output is correct
27 Correct 82 ms 20988 KB Output is correct
28 Correct 84 ms 21844 KB Output is correct
29 Correct 87 ms 22008 KB Output is correct
30 Correct 87 ms 22404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 25716 KB Output is correct
2 Correct 112 ms 25684 KB Output is correct
3 Correct 83 ms 25596 KB Output is correct
4 Correct 96 ms 25716 KB Output is correct
5 Correct 94 ms 25592 KB Output is correct
6 Correct 86 ms 25680 KB Output is correct
7 Correct 83 ms 25684 KB Output is correct
8 Correct 84 ms 25728 KB Output is correct
9 Correct 86 ms 25684 KB Output is correct
10 Correct 90 ms 25684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 472 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 480 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 476 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 472 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 94 ms 20980 KB Output is correct
31 Correct 83 ms 21872 KB Output is correct
32 Correct 74 ms 20336 KB Output is correct
33 Correct 89 ms 21744 KB Output is correct
34 Correct 85 ms 21652 KB Output is correct
35 Correct 92 ms 21744 KB Output is correct
36 Correct 85 ms 21584 KB Output is correct
37 Correct 96 ms 22356 KB Output is correct
38 Correct 87 ms 22096 KB Output is correct
39 Correct 87 ms 22356 KB Output is correct
40 Correct 98 ms 22528 KB Output is correct
41 Correct 82 ms 20988 KB Output is correct
42 Correct 84 ms 21844 KB Output is correct
43 Correct 87 ms 22008 KB Output is correct
44 Correct 87 ms 22404 KB Output is correct
45 Correct 84 ms 25716 KB Output is correct
46 Correct 112 ms 25684 KB Output is correct
47 Correct 83 ms 25596 KB Output is correct
48 Correct 96 ms 25716 KB Output is correct
49 Correct 94 ms 25592 KB Output is correct
50 Correct 86 ms 25680 KB Output is correct
51 Correct 83 ms 25684 KB Output is correct
52 Correct 84 ms 25728 KB Output is correct
53 Correct 86 ms 25684 KB Output is correct
54 Correct 90 ms 25684 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 472 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 480 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 1 ms 476 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 74 ms 22012 KB Output is correct
77 Correct 76 ms 22352 KB Output is correct
78 Correct 77 ms 21372 KB Output is correct
79 Correct 80 ms 21584 KB Output is correct
80 Correct 83 ms 22336 KB Output is correct
81 Correct 71 ms 21492 KB Output is correct
82 Correct 77 ms 21584 KB Output is correct
83 Correct 78 ms 21892 KB Output is correct
84 Correct 72 ms 21844 KB Output is correct
85 Correct 82 ms 22096 KB Output is correct
86 Correct 73 ms 21380 KB Output is correct
87 Correct 76 ms 21328 KB Output is correct
88 Correct 76 ms 21584 KB Output is correct
89 Correct 71 ms 21584 KB Output is correct
90 Correct 71 ms 21380 KB Output is correct
91 Correct 90 ms 21328 KB Output is correct
92 Correct 88 ms 22608 KB Output is correct
93 Correct 87 ms 21712 KB Output is correct
94 Correct 79 ms 20820 KB Output is correct
95 Correct 80 ms 22276 KB Output is correct
96 Correct 87 ms 21360 KB Output is correct
97 Correct 71 ms 21584 KB Output is correct
98 Correct 109 ms 21840 KB Output is correct
99 Correct 99 ms 21376 KB Output is correct
100 Correct 79 ms 21496 KB Output is correct