Submission #129553

# Submission time Handle Problem Language Result Execution time Memory
129553 2019-07-12T14:00:22 Z BThero Candies (JOI18_candies) C++17
0 / 100
5 ms 1016 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin(), (x).end()
 
#define fi first
#define se second
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> pll;   
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
const int MAXN = (int)2e5 + 5;
const ll INF = (ll)1e18;
 
ll arr[MAXN], ans[MAXN];

int n;
 
pll rev(pll x) {
    return mp(x.se, x.fi);
}

void solve() {
    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%lld", &arr[i]);
    }

    set<pll> S, S2;

    for (int i = 0; i < n; ++i) {
        S.insert(mp(arr[i], i));
        S2.insert(mp(i, arr[i]));
    }

    for (int i = 1; i <= (n + 1) / 2; ++i) {
        ans[i] = ans[i - 1] + S.rbegin() -> fi;
        auto it = S2.lower_bound(rev(*S.rbegin()));

        if (it == --S2.end()) {
            S.erase(rev(*S2.rbegin()));
            S2.erase(--S2.end());
            S.erase(rev(*S2.rbegin()));
            S2.erase(--S2.end());
        }
        else if (it == S2.begin()) {
            S.erase(rev(*S2.begin()));
            S2.erase(S2.begin());
            S.erase(rev(*S2.begin()));
            S2.erase(S2.begin());
        }
        else {
            --it;
            pll A = *it++;
            pll B = *it++;
            pll C = *it++;

            ll nw = A.se + C.se - B.se;
            S.erase(rev(A));
            S2.erase(A);
            S.erase(rev(B));
            S2.erase(B);
            S.erase(rev(C));
            S2.erase(C);
            S.insert(mp(nw, A.fi));
            S2.insert(mp(A.fi, nw));
        }
    }

    for (int i = 1; i <= (n + 1) / 2; ++i) {
        printf("%lld\n", ans[i]);
    }
}
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 
    int tt = 1;
 
    while (tt--) {
        solve();
    }
 
    return 0;
}

Compilation message

candies.cpp: In function 'void solve()':
candies.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Runtime error 5 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 4 ms 632 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 4 ms 632 KB Output is correct
10 Correct 4 ms 632 KB Output is correct
11 Runtime error 5 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -