Submission #914828

# Submission time Handle Problem Language Result Execution time Memory
914828 2024-01-22T17:52:08 Z Amirreza_Fakhri Candies (JOI18_candies) C++17
8 / 100
41 ms 18988 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e5+5;

int n, a[maxn], pre[maxn], nxt[maxn];
set <pii, greater <pii> > st;

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        st.insert(mp(a[i], i));
        pre[i] = i-1, nxt[i] = i+1;
    }
    nxt[0] = 1, pre[n+1] = n;
    int ans = 0;
    for (int i = 0; i < (n+1)/2; i++) {
        int v = st.begin() -> F, j = st.begin() -> S;
        ans += v;
        cout << ans << '\n';
        st.erase(st.begin());
        if (pre[j] == 0) {
            st.erase(mp(a[nxt[j]], nxt[j]));
            nxt[pre[nxt[nxt[j]]] = 0] = nxt[nxt[j]];
        }
        else if (nxt[j] == n+1) {
            st.erase(mp(a[pre[j]], pre[j]));
            pre[nxt[pre[pre[j]]] = n+1] = pre[pre[j]];
        }
        else {
            st.erase(mp(a[pre[j]], pre[j])), st.erase(mp(a[nxt[j]], nxt[j]));
            a[j] = a[pre[j]]+a[nxt[j]]-a[j];
            nxt[pre[nxt[nxt[j]]] = j] = nxt[nxt[j]];
            pre[nxt[pre[pre[j]]] = j] = pre[pre[j]];
            st.insert(mp(a[j], j));
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 2 ms 2664 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2520 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2880 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 2 ms 2664 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2520 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 2 ms 2880 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2648 KB Output is correct
21 Runtime error 41 ms 18988 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -