Submission #1086038

# Submission time Handle Problem Language Result Execution time Memory
1086038 2024-09-09T11:08:08 Z vjudge1 Candies (JOI18_candies) C++17
100 / 100
78 ms 11464 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;

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:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main()
      | ^~~~
candies.cpp: In function 'int main()':
candies.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 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 600 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 604 KB Output is correct
12 Correct 1 ms 604 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 624 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 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 600 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 604 KB Output is correct
12 Correct 1 ms 604 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 624 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 72 ms 11340 KB Output is correct
22 Correct 71 ms 11256 KB Output is correct
23 Correct 78 ms 11452 KB Output is correct
24 Correct 54 ms 11456 KB Output is correct
25 Correct 59 ms 11456 KB Output is correct
26 Correct 58 ms 11260 KB Output is correct
27 Correct 63 ms 11452 KB Output is correct
28 Correct 63 ms 11464 KB Output is correct
29 Correct 63 ms 11460 KB Output is correct
30 Correct 69 ms 11372 KB Output is correct
31 Correct 62 ms 11456 KB Output is correct
32 Correct 59 ms 11456 KB Output is correct
33 Correct 65 ms 11364 KB Output is correct
34 Correct 66 ms 11464 KB Output is correct
35 Correct 65 ms 11328 KB Output is correct
36 Correct 68 ms 11368 KB Output is correct
37 Correct 73 ms 11456 KB Output is correct
38 Correct 74 ms 11460 KB Output is correct
39 Correct 57 ms 11452 KB Output is correct
40 Correct 65 ms 11220 KB Output is correct
41 Correct 57 ms 11328 KB Output is correct
42 Correct 63 ms 11456 KB Output is correct
43 Correct 61 ms 11452 KB Output is correct
44 Correct 67 ms 11344 KB Output is correct
45 Correct 64 ms 11456 KB Output is correct
46 Correct 64 ms 11456 KB Output is correct
47 Correct 64 ms 11456 KB Output is correct
48 Correct 65 ms 11456 KB Output is correct
49 Correct 72 ms 11456 KB Output is correct
50 Correct 63 ms 11452 KB Output is correct