답안 #1086035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086035 2024-09-09T11:00:17 Z Neco_arc Candies (JOI18_candies) C++17
0 / 100
1 ms 484 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});

    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:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main()
      | ^~~~
candies.cpp: In function 'int main()':
candies.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 484 KB Output isn't correct
2 Halted 0 ms 0 KB -