Submission #697512

# Submission time Handle Problem Language Result Execution time Memory
697512 2023-02-10T07:27:55 Z Bobonbush Discharging (NOI20_discharging) C++17
100 / 100
191 ms 15988 KB
#include <bits/stdc++.h>
#define foreach for
#define in :
using namespace std;
typedef long long ll ;
const int LOG = 18;
const long long base = 31;
const long long MODULO = 1e9+7;
const long long INF = 1e18+1;
template<class X ,class Y>
    bool Minimize(X &x , Y y)
    {
        if(x > y)
        {
            x = y;
            return true;
        }
        return false;
    }
template<class X , class Y>
    bool Maximize(X &x , Y y)
    {
        if(x < y)
        {
            x = y;
            return true;
        }
        return false;
    }
struct lines
{
    ll a ,b;
    lines(ll _a , ll _b )
    {
        a = _a;
        b = _b;
    }
    ll eval(ll x)
    {
        return a *x + b;
    }
};
deque<lines>adu;


bool bad(lines &l1 , lines &l2 ,lines &l3)
{
    return (long double)(l3.b - l1.b) * (l1.a - l2.a) < (long double)(l2.b - l1.b) * (l1.a - l3.a);
}
void Add(lines x)
{
    while((int)adu.size() >= 2 && bad( adu[(int)adu.size()-2] , adu[(int)adu.size()-1] , x  ))
    {
        adu.pop_back();
    }
    adu.push_back(x);
}

ll Get(ll x)
{
    while((int)adu.size() >= 2 && adu[0].eval(x) >= adu[1].eval(x)  )adu.pop_front();
    return adu[0].eval(x);
}
const int N = 1e6+1;
int n , a[N];
int _next[N];
long long dp[N];
void Input()
{
    cin >> n ;
    for(int i = 1; i <= n ; i++)
    {
        cin >> a[i];
        if(a[_next[i-1]]  <=  a[i])_next[i] = i;
        else _next[i] = _next[i-1];
    }
}
void Process()
{
    Add(lines(0 , 0));
    for(int i =1 ; i <= n ; i++)
    {
        if(_next[i] != i)dp[i] = dp[i-1];
        else dp[i] = Get(a[i]) + n *1LL * a[i];
        Add(lines( -i * 1LL , dp[i] ));
    }
    cout << dp[n];
}
int main()
{
    ios_base :: sync_with_stdio(0);cin.tie(0);
    int test = 1;
    while(test--)
    {
        Input();
        Process();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 105 ms 15900 KB Output is correct
17 Correct 111 ms 15872 KB Output is correct
18 Correct 104 ms 15900 KB Output is correct
19 Correct 133 ms 15828 KB Output is correct
20 Correct 191 ms 15924 KB Output is correct
21 Correct 105 ms 15932 KB Output is correct
22 Correct 107 ms 15988 KB Output is correct
23 Correct 113 ms 15932 KB Output is correct
24 Correct 107 ms 15928 KB Output is correct
25 Correct 104 ms 15960 KB Output is correct
26 Correct 141 ms 15880 KB Output is correct
27 Correct 102 ms 15880 KB Output is correct
28 Correct 119 ms 15852 KB Output is correct
29 Correct 106 ms 15908 KB Output is correct
30 Correct 122 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 15948 KB Output is correct
2 Correct 151 ms 15904 KB Output is correct
3 Correct 129 ms 15904 KB Output is correct
4 Correct 109 ms 15880 KB Output is correct
5 Correct 111 ms 15876 KB Output is correct
6 Correct 112 ms 15876 KB Output is correct
7 Correct 112 ms 15960 KB Output is correct
8 Correct 105 ms 15888 KB Output is correct
9 Correct 108 ms 15904 KB Output is correct
10 Correct 120 ms 15856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 105 ms 15900 KB Output is correct
31 Correct 111 ms 15872 KB Output is correct
32 Correct 104 ms 15900 KB Output is correct
33 Correct 133 ms 15828 KB Output is correct
34 Correct 191 ms 15924 KB Output is correct
35 Correct 105 ms 15932 KB Output is correct
36 Correct 107 ms 15988 KB Output is correct
37 Correct 113 ms 15932 KB Output is correct
38 Correct 107 ms 15928 KB Output is correct
39 Correct 104 ms 15960 KB Output is correct
40 Correct 141 ms 15880 KB Output is correct
41 Correct 102 ms 15880 KB Output is correct
42 Correct 119 ms 15852 KB Output is correct
43 Correct 106 ms 15908 KB Output is correct
44 Correct 122 ms 15948 KB Output is correct
45 Correct 106 ms 15948 KB Output is correct
46 Correct 151 ms 15904 KB Output is correct
47 Correct 129 ms 15904 KB Output is correct
48 Correct 109 ms 15880 KB Output is correct
49 Correct 111 ms 15876 KB Output is correct
50 Correct 112 ms 15876 KB Output is correct
51 Correct 112 ms 15960 KB Output is correct
52 Correct 105 ms 15888 KB Output is correct
53 Correct 108 ms 15904 KB Output is correct
54 Correct 120 ms 15856 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 93 ms 15948 KB Output is correct
77 Correct 95 ms 15856 KB Output is correct
78 Correct 92 ms 15968 KB Output is correct
79 Correct 86 ms 15888 KB Output is correct
80 Correct 99 ms 15956 KB Output is correct
81 Correct 92 ms 15960 KB Output is correct
82 Correct 84 ms 15940 KB Output is correct
83 Correct 89 ms 15856 KB Output is correct
84 Correct 91 ms 15912 KB Output is correct
85 Correct 89 ms 15948 KB Output is correct
86 Correct 90 ms 15948 KB Output is correct
87 Correct 87 ms 15860 KB Output is correct
88 Correct 86 ms 15896 KB Output is correct
89 Correct 84 ms 15928 KB Output is correct
90 Correct 87 ms 15856 KB Output is correct
91 Correct 95 ms 15868 KB Output is correct
92 Correct 103 ms 15932 KB Output is correct
93 Correct 95 ms 15948 KB Output is correct
94 Correct 101 ms 15960 KB Output is correct
95 Correct 91 ms 15860 KB Output is correct
96 Correct 86 ms 15864 KB Output is correct
97 Correct 92 ms 15904 KB Output is correct
98 Correct 89 ms 15868 KB Output is correct
99 Correct 85 ms 15948 KB Output is correct
100 Correct 88 ms 15936 KB Output is correct