Submission #133902

#TimeUsernameProblemLanguageResultExecution timeMemory
133902dualityCandies (JOI18_candies)C++11
100 / 100
169 ms11052 KiB
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; int A[200000]; int l[200001],r[200001]; LLI rs[200001]; priority_queue<pair<LLI,pii> > H; int main() { int i; int N; scanf("%d",&N); for (i = 0; i < N; i++) scanf("%d",&A[i]); LLI ans = 0; for (i = 0; i <= N; i++) { l[i] = i-1,r[i] = i+1; if (i < N) rs[i] = A[i],H.push(mp(A[i],mp(i,i+1))); } while (!H.empty()) { int a = H.top().second.first,b = H.top().second.second; LLI d = H.top().first; H.pop(); if ((r[a] != b) || (l[b] != a)) continue; ans += d,printf("%lld\n",ans); if (l[a] != -1) r[l[a]] = r[b]; if (r[b] != N+1) l[r[b]] = l[a]; if ((l[a] != -1) && (r[b] != N+1)) { H.push(mp(rs[l[a]]-d+rs[b],mp(l[a],r[b]))); rs[l[a]] = rs[l[a]]-d+rs[b]; } } return 0; }

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
candies.cpp:18:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < N; i++) scanf("%d",&A[i]);
                             ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...