Submission #1086037

# Submission time Handle Problem Language Result Execution time Memory
1086037 2024-09-09T11:05:24 Z Neco_arc Candies (JOI18_candies) C++17
100 / 100
75 ms 13504 KB
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL

#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Candies"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
#define int long long

using namespace std;

const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;

/// if i is a center of an interval, L[i] R[i] is the border, if not, L[i] R[i] point toward the center
int n;
ll a[maxn];
int L[maxn], R[maxn], del[maxn];

void solve()
{

    cin >> n;
    fi(i, 1, n) {
        cin >> a[i];
        L[i] = i - 1, R[i] = i + 1;
    }

    ll ans = 0;
    priority_queue<pair<ll, int>> q;
    fi(i, 1, n) q.push({a[i], i});

    a[0] = a[n + 1] = -1e18;

    fi(_, 1, (n + 1) / 2) {
        while(del[q.top().second]) q.pop();
        ll w, id; tie(w, id) = q.top(); q.pop();
        ans += w;

        cout << ans << '\n';

        del[L[id]] = 1, del[R[id]] = 1;
        a[id] = a[L[id]] + a[R[id]] - a[id];

        L[id] = L[L[id]];
        R[L[id]] = id;

        R[id] = R[R[id]];
        L[R[id]] = id;

        q.push({a[id], id});
    }


}


main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message

candies.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
candies.cpp: In function 'int main()':
candies.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 480 KB Output is correct
12 Correct 1 ms 480 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 480 KB Output is correct
12 Correct 1 ms 480 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 856 KB Output is correct
21 Correct 74 ms 13248 KB Output is correct
22 Correct 75 ms 13244 KB Output is correct
23 Correct 74 ms 13244 KB Output is correct
24 Correct 58 ms 13252 KB Output is correct
25 Correct 58 ms 13240 KB Output is correct
26 Correct 57 ms 13164 KB Output is correct
27 Correct 61 ms 13252 KB Output is correct
28 Correct 65 ms 13256 KB Output is correct
29 Correct 70 ms 13256 KB Output is correct
30 Correct 64 ms 13356 KB Output is correct
31 Correct 63 ms 13240 KB Output is correct
32 Correct 64 ms 13252 KB Output is correct
33 Correct 67 ms 12996 KB Output is correct
34 Correct 72 ms 13108 KB Output is correct
35 Correct 66 ms 13248 KB Output is correct
36 Correct 71 ms 13248 KB Output is correct
37 Correct 73 ms 13304 KB Output is correct
38 Correct 71 ms 13240 KB Output is correct
39 Correct 56 ms 13244 KB Output is correct
40 Correct 57 ms 13156 KB Output is correct
41 Correct 55 ms 13248 KB Output is correct
42 Correct 65 ms 13248 KB Output is correct
43 Correct 69 ms 13252 KB Output is correct
44 Correct 67 ms 13248 KB Output is correct
45 Correct 62 ms 13252 KB Output is correct
46 Correct 66 ms 13248 KB Output is correct
47 Correct 62 ms 13504 KB Output is correct
48 Correct 66 ms 12996 KB Output is correct
49 Correct 70 ms 12988 KB Output is correct
50 Correct 65 ms 12996 KB Output is correct