답안 #44890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44890 2018-04-09T05:55:46 Z PowerOfNinjaGo Candies (JOI18_candies) C++17
0 / 100
3 ms 504 KB
//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 main()
{
    int n; 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(ii(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;
        ans += w;
        rounds--;
        cost[u] = cost[pred[u]]+cost[succ[u]]-cost[u];
        dong[pred[u]] = dong[succ[u]] = true;
        succ[pred[pred[u]]] = u; pred[u] = pred[pred[u]];
        pred[succ[succ[u]]] = u; succ[u] = succ[succ[u]];
        pq.push(ii(cost[u], u));
        printf("%lld\n", ans);
    }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:19: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:14:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d", &n);
            ~~~~~^~~~~~~~~~
candies.cpp:19: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]);
                                ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -