Submission #336679

# Submission time Handle Problem Language Result Execution time Memory
336679 2020-12-16T11:45:42 Z mehrdad_sohrabi Candies (JOI18_candies) C++14
100 / 100
2083 ms 515928 KB
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <pii> seg[2][2][N*4];
ll a[N];
void build(ll nod,ll l,ll r){
    if (r-l==1){
        seg[1][1][nod].pb({1,a[l]});
        seg[0][0][nod].pb({0,0});
        return ;
    }
    ll mid=(r+l)/2;
    build(nod*2,l,mid);
    build(nod*2+1,mid,r);
  //  cout << "KIR" << " " << l << " " << r << endl;
    for (int l1=0;l1<=1;l1++){
        for (int r1=0;r1<=1;r1++){
            for (int l2=0;l2<=1;l2++){
                for (int r2=0;r2<=1;r2++){
                    if (r1==1 && l2==1) continue;
                    vector <pii> a=seg[l1][r1][nod*2],b=seg[l2][r2][nod*2+1];
                    a.pb({0,(ll)-1e18});
                    b.pb(a.back());
                    ll p1=0,p2=0;
                   // cout << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
                    while(p1<a.size()-1 && p2<b.size()-1){
                        seg[l1][r2][nod].pb({a[p1].F+b[p2].F,a[p1].S+b[p2].S});
                        if (a[p1+1].S-a[p1].S>b[p2+1].S-b[p2].S) p1++;
                        else p2++;
                    }
                }
            }
        }
    }
  //  cout << "KOS" << endl;
    for (int l1=0;l1<2;l1++){
        for (int r1=0;r1<2;r1++){
            sort(seg[l1][r1][nod].begin(),seg[l1][r1][nod].end());
            vector <pii> a=seg[l1][r1][nod],b;
            reverse(a.begin(),a.end());
            if (a.size()==0){
       //         cout << l << " " << r << " " << l1 << " " << r1 << endl;
                continue;
            }
            b.pb(a[0]);
            for (int i=1;i<a.size();i++){
                if (a[i].F==a[i-1].F) continue;
                b.pb(a[i]);
            }
            reverse(b.begin(),b.end());
            seg[l1][r1][nod]=b;
        }
    }
}
ll ans[N];
int32_t main(){
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    build(1,1,n+1);
    for (int l=0;l<2;l++){
        for (int r=0;r<2;r++){
            for (auto u : seg[l][r][1]){
                ans[u.F]=max(ans[u.F],u.S);
            }
        }
    }
    for (int i=1;i<=(n+1)/2;i++){
        cout << ans[i] << endl;
    }
}

Compilation message

candies.cpp: In function 'void build(ll, ll, ll)':
candies.cpp:37:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                     while(p1<a.size()-1 && p2<b.size()-1){
      |                           ~~^~~~~~~~~~~
candies.cpp:37:46: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                     while(p1<a.size()-1 && p2<b.size()-1){
      |                                            ~~^~~~~~~~~~~
candies.cpp:57:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for (int i=1;i<a.size();i++){
      |                          ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 78316 KB Output is correct
2 Correct 62 ms 78316 KB Output is correct
3 Correct 62 ms 78188 KB Output is correct
4 Correct 62 ms 78188 KB Output is correct
5 Correct 60 ms 78188 KB Output is correct
6 Correct 61 ms 78188 KB Output is correct
7 Correct 62 ms 78188 KB Output is correct
8 Correct 60 ms 78188 KB Output is correct
9 Correct 61 ms 78188 KB Output is correct
10 Correct 63 ms 78276 KB Output is correct
11 Correct 61 ms 78316 KB Output is correct
12 Correct 62 ms 78316 KB Output is correct
13 Correct 61 ms 78188 KB Output is correct
14 Correct 61 ms 78188 KB Output is correct
15 Correct 62 ms 78188 KB Output is correct
16 Correct 63 ms 78188 KB Output is correct
17 Correct 61 ms 78188 KB Output is correct
18 Correct 61 ms 78188 KB Output is correct
19 Correct 61 ms 78444 KB Output is correct
20 Correct 62 ms 78188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 78316 KB Output is correct
2 Correct 62 ms 78316 KB Output is correct
3 Correct 62 ms 78188 KB Output is correct
4 Correct 62 ms 78188 KB Output is correct
5 Correct 60 ms 78188 KB Output is correct
6 Correct 61 ms 78188 KB Output is correct
7 Correct 62 ms 78188 KB Output is correct
8 Correct 60 ms 78188 KB Output is correct
9 Correct 61 ms 78188 KB Output is correct
10 Correct 63 ms 78276 KB Output is correct
11 Correct 61 ms 78316 KB Output is correct
12 Correct 62 ms 78316 KB Output is correct
13 Correct 61 ms 78188 KB Output is correct
14 Correct 61 ms 78188 KB Output is correct
15 Correct 62 ms 78188 KB Output is correct
16 Correct 63 ms 78188 KB Output is correct
17 Correct 61 ms 78188 KB Output is correct
18 Correct 61 ms 78188 KB Output is correct
19 Correct 61 ms 78444 KB Output is correct
20 Correct 62 ms 78188 KB Output is correct
21 Correct 2082 ms 515640 KB Output is correct
22 Correct 2083 ms 515512 KB Output is correct
23 Correct 2064 ms 515700 KB Output is correct
24 Correct 1936 ms 515628 KB Output is correct
25 Correct 1930 ms 515884 KB Output is correct
26 Correct 1987 ms 515928 KB Output is correct
27 Correct 1988 ms 515904 KB Output is correct
28 Correct 2001 ms 515628 KB Output is correct
29 Correct 1991 ms 515756 KB Output is correct
30 Correct 2003 ms 515892 KB Output is correct
31 Correct 1994 ms 515500 KB Output is correct
32 Correct 1999 ms 515756 KB Output is correct
33 Correct 2009 ms 515772 KB Output is correct
34 Correct 2021 ms 515768 KB Output is correct
35 Correct 2013 ms 515892 KB Output is correct
36 Correct 2065 ms 515656 KB Output is correct
37 Correct 2066 ms 515728 KB Output is correct
38 Correct 2067 ms 515736 KB Output is correct
39 Correct 1917 ms 515440 KB Output is correct
40 Correct 1916 ms 515700 KB Output is correct
41 Correct 1917 ms 515612 KB Output is correct
42 Correct 1984 ms 515736 KB Output is correct
43 Correct 2001 ms 515612 KB Output is correct
44 Correct 1981 ms 515752 KB Output is correct
45 Correct 1993 ms 515668 KB Output is correct
46 Correct 1997 ms 515844 KB Output is correct
47 Correct 1996 ms 515612 KB Output is correct
48 Correct 2009 ms 515868 KB Output is correct
49 Correct 2021 ms 515740 KB Output is correct
50 Correct 2015 ms 515752 KB Output is correct