답안 #48404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48404 2018-05-12T19:24:07 Z choikiwon Candies (JOI18_candies) C++17
0 / 100
3 ms 376 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MN = 200010;

int N;
int A[MN], pre[MN], nxt[MN];
priority_queue<pii> pq;

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    for(int i = 0; i < N; i++) {
        pre[i] = i - 1;
        nxt[i] = i + 1;
        pq.push({ A[i], i });
    }

    ll sum = 0;
    for(int i = 1; i <= (N + 1) / 2; i++) {
        pii t;
        while(!pq.empty()) {
            t = pq.top(); pq.pop();
            if(A[t.second] == t.first) break;
        }
        sum += t.first;
        printf("%lld\n", sum);

        A[t.second] = -A[t.second];
        if(pre[t.second] != -1) {
            A[t.second] += A[ pre[t.second] ];
            A[ pre[t.second] ] = -1e9;
            pre[t.second] = pre[ pre[t.second] ];
            nxt[ pre[t.second] ] = t.second;
        }
        if(nxt[t.second] != N) {
            A[t.second] += A[ nxt[t.second] ];
            A[ nxt[t.second] ] = -1e9;
            nxt[t.second] = nxt[ nxt[t.second] ];
            pre[ nxt[t.second] ] = t.second;
        }
        pq.push({ A[t.second], t.second });
    }
}

Compilation message

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