Submission #494814

# Submission time Handle Problem Language Result Execution time Memory
494814 2021-12-16T15:34:06 Z blue Discharging (NOI20_discharging) C++17
100 / 100
402 ms 27148 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
#define sz(x) int(x.size())

const ll INF = 1'000'000'000'000'000'000LL;


struct line
{
    double a;
    double b;
};

double intersect(line A, line B)
{
    return (B.b-A.b)/(A.a-B.a);
}


int main()
{
    int N;
    cin >> N;

    int TS = N;

    vector<pll> T;

    T.push_back({0, 0});
    for(int i = 1; i <= N; i++)
    {
        ll t;
        cin >> t;
        if(t <= T.back().first)
            T.back().second++;
        else
            T.push_back({t, 1});
    }

    N = sz(T)-1;

    vll suff(1+N, 0);
    suff[0] = TS;
    for(int i = 1; i <= N; i++) suff[i] = suff[i-1] - T[i].second;


    vll dp(1+N, INF);

    dp[0] = 0;

    vector<line> L;
    L.push_back(line{double(suff[0]), double(dp[0])});

    // for(int i = 0; i <= N; i++) cerr << T[i].first << ' ' << T[i].second << ' ' << suff[i] << '\n';

    for(int i = 1; i <= N; i++)
    {
        int lo = 0;
        int hi = sz(L) - 1;

        double x = T[i].first;

        while(lo != hi)
        {
            int mid = (lo+hi)/2;
            if(intersect(L[mid], L[mid+1]) <= x)    ///!!!!!!!!
                lo = mid+1;
            else
                hi = mid;
        }

        // if(i == 2)
        // {
        //     cerr << "!!!\n";
        //     cerr << intersect(L[0], L[1]) << '\n';
        //     cerr << "x = " << x << '\n';
        // }

        dp[i] = ll(L[lo].a) * T[i].first  +  ll(L[lo].b);

        // for(auto y: L) cerr << y.a << "/" << y.b << " ";
        // cerr << '\n';
        // cerr << "lo = " << lo << '\n';

        // cerr << i << " : " << dp[i] << '\n';

        if(i < N)
        {
            line new_line{double(suff[i]), double(dp[i])};
            while(sz(L) >= 2 && intersect(L[sz(L)-2], L[sz(L)-1]) >= intersect(L[sz(L)-1], new_line)) //!!!!!!!!!!!
                L.pop_back();

            L.push_back(new_line);
        }
    }
    cout << dp[N] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 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 324 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 308 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 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 324 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 308 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 273 ms 14872 KB Output is correct
17 Correct 305 ms 20232 KB Output is correct
18 Correct 232 ms 13536 KB Output is correct
19 Correct 291 ms 20128 KB Output is correct
20 Correct 290 ms 21472 KB Output is correct
21 Correct 302 ms 20196 KB Output is correct
22 Correct 290 ms 18520 KB Output is correct
23 Correct 333 ms 25428 KB Output is correct
24 Correct 310 ms 23044 KB Output is correct
25 Correct 322 ms 23248 KB Output is correct
26 Correct 360 ms 27148 KB Output is correct
27 Correct 266 ms 16228 KB Output is correct
28 Correct 311 ms 20768 KB Output is correct
29 Correct 313 ms 23572 KB Output is correct
30 Correct 353 ms 26124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 368 ms 956 KB Output is correct
2 Correct 384 ms 2136 KB Output is correct
3 Correct 366 ms 2192 KB Output is correct
4 Correct 368 ms 2068 KB Output is correct
5 Correct 395 ms 2204 KB Output is correct
6 Correct 358 ms 2068 KB Output is correct
7 Correct 402 ms 2096 KB Output is correct
8 Correct 366 ms 2180 KB Output is correct
9 Correct 354 ms 2036 KB Output is correct
10 Correct 367 ms 2000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 308 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 324 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 308 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 300 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 208 KB Output is correct
34 Correct 1 ms 208 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 ms 208 KB Output is correct
37 Correct 1 ms 208 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 208 KB Output is correct
40 Correct 1 ms 208 KB Output is correct
41 Correct 1 ms 208 KB Output is correct
42 Correct 1 ms 208 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 208 KB Output is correct
45 Correct 1 ms 208 KB Output is correct
46 Correct 1 ms 208 KB Output is correct
47 Correct 1 ms 208 KB Output is correct
48 Correct 1 ms 208 KB Output is correct
49 Correct 1 ms 208 KB Output is correct
50 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 308 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 324 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 308 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 273 ms 14872 KB Output is correct
31 Correct 305 ms 20232 KB Output is correct
32 Correct 232 ms 13536 KB Output is correct
33 Correct 291 ms 20128 KB Output is correct
34 Correct 290 ms 21472 KB Output is correct
35 Correct 302 ms 20196 KB Output is correct
36 Correct 290 ms 18520 KB Output is correct
37 Correct 333 ms 25428 KB Output is correct
38 Correct 310 ms 23044 KB Output is correct
39 Correct 322 ms 23248 KB Output is correct
40 Correct 360 ms 27148 KB Output is correct
41 Correct 266 ms 16228 KB Output is correct
42 Correct 311 ms 20768 KB Output is correct
43 Correct 313 ms 23572 KB Output is correct
44 Correct 353 ms 26124 KB Output is correct
45 Correct 368 ms 956 KB Output is correct
46 Correct 384 ms 2136 KB Output is correct
47 Correct 366 ms 2192 KB Output is correct
48 Correct 368 ms 2068 KB Output is correct
49 Correct 395 ms 2204 KB Output is correct
50 Correct 358 ms 2068 KB Output is correct
51 Correct 402 ms 2096 KB Output is correct
52 Correct 366 ms 2180 KB Output is correct
53 Correct 354 ms 2036 KB Output is correct
54 Correct 367 ms 2000 KB Output is correct
55 Correct 1 ms 300 KB Output is correct
56 Correct 1 ms 208 KB Output is correct
57 Correct 1 ms 208 KB Output is correct
58 Correct 1 ms 208 KB Output is correct
59 Correct 1 ms 208 KB Output is correct
60 Correct 1 ms 300 KB Output is correct
61 Correct 1 ms 208 KB Output is correct
62 Correct 1 ms 208 KB Output is correct
63 Correct 1 ms 300 KB Output is correct
64 Correct 1 ms 208 KB Output is correct
65 Correct 1 ms 208 KB Output is correct
66 Correct 1 ms 208 KB Output is correct
67 Correct 1 ms 208 KB Output is correct
68 Correct 1 ms 336 KB Output is correct
69 Correct 1 ms 208 KB Output is correct
70 Correct 1 ms 208 KB Output is correct
71 Correct 1 ms 208 KB Output is correct
72 Correct 1 ms 208 KB Output is correct
73 Correct 1 ms 208 KB Output is correct
74 Correct 1 ms 208 KB Output is correct
75 Correct 1 ms 208 KB Output is correct
76 Correct 263 ms 6400 KB Output is correct
77 Correct 250 ms 6284 KB Output is correct
78 Correct 230 ms 5704 KB Output is correct
79 Correct 237 ms 5896 KB Output is correct
80 Correct 257 ms 6580 KB Output is correct
81 Correct 230 ms 5832 KB Output is correct
82 Correct 238 ms 5800 KB Output is correct
83 Correct 262 ms 6216 KB Output is correct
84 Correct 251 ms 6092 KB Output is correct
85 Correct 256 ms 6312 KB Output is correct
86 Correct 235 ms 5628 KB Output is correct
87 Correct 235 ms 5520 KB Output is correct
88 Correct 251 ms 6028 KB Output is correct
89 Correct 236 ms 6088 KB Output is correct
90 Correct 234 ms 5632 KB Output is correct
91 Correct 231 ms 5448 KB Output is correct
92 Correct 328 ms 23072 KB Output is correct
93 Correct 314 ms 20412 KB Output is correct
94 Correct 230 ms 5380 KB Output is correct
95 Correct 278 ms 6656 KB Output is correct
96 Correct 236 ms 5632 KB Output is correct
97 Correct 242 ms 5764 KB Output is correct
98 Correct 243 ms 6032 KB Output is correct
99 Correct 233 ms 5704 KB Output is correct
100 Correct 248 ms 5888 KB Output is correct