Submission #44898

#TimeUsernameProblemLanguageResultExecution timeMemory
44898PowerOfNinjaGoCandies (JOI18_candies)C++17
0 / 100
3 ms504 KiB
//Power Of Ninja Go #include <bits/stdc++.h> //#ifdef atom #else #endif using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii; #define X first #define Y second #define pb push_back const int maxn = 2e5+5; int pred[maxn], succ[maxn]; ll cost[maxn]; bool dong[maxn]; int n; bool val(int x) { return x>=1 && x<= n; } int main() { scanf("%d", &n); for(int i = 1; i<= n; i++) { pred[i] = i-1; succ[i] = i+1; } for(int i = 1; i<= n; i++) scanf("%d", &cost[i]); priority_queue< pair<ll, int> > pq; for(int i = 1; i<= n; i++) pq.push(make_pair(cost[i], i)); ll ans = 0; int rounds = (n+1)/2; while(!pq.empty() && rounds) { auto k = pq.top(); pq.pop(); ll w = k.X; int u = k.Y; if(dong[u]) continue; rounds--; ans += cost[u]; printf("%lld\n", ans); bool bad = false; cost[u] = cost[pred[u]]+cost[succ[u]]-cost[u]; dong[pred[u]] = dong[succ[u]] = true; if(pred[u]) { pred[u] = pred[pred[u]]; succ[pred[u]] = u; } else bad = true; if(succ[u] != n+1) { succ[u] = succ[succ[u]]; pred[succ[u]] = u; } else bad = true; if(!bad) pq.push(make_pair(cost[u], u)); } }

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:24:52: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll* {aka long long int*}' [-Wformat=]
     for(int i = 1; i<= n; i++) scanf("%d", &cost[i]);
                                            ~~~~~~~~^
candies.cpp:32:12: warning: unused variable 'w' [-Wunused-variable]
         ll w = k.X; int u = k.Y;
            ^
candies.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:24:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i<= n; i++) scanf("%d", &cost[i]);
                                ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...