Submission #1086033

#TimeUsernameProblemLanguageResultExecution timeMemory
1086033Neco_arcCandies (JOI18_candies)C++17
0 / 100
1 ms600 KiB
#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 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; int 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}); } } int 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 (stderr)

candies.cpp: In function 'int main()':
candies.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...