답안 #91924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91924 2018-12-31T13:58:39 Z Bodo171 Candies (JOI18_candies) C++14
0 / 100
2 ms 508 KB
#include <iostream>
#include <fstream>
#include <queue>
#include <climits>
using namespace std;
const int nmax=200005;
const long long inf=100000*100000*100000*10;
priority_queue< pair<long long,int> > pq;
int n,i,j,poz,st,dr;
long long val,ans,v1,v2;
long long v[nmax];
int tt[nmax],rg[nmax],l[nmax],r[nmax];
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
        pq.push({v[i],i});
        l[i]=i-1;r[i]=i+1;
    }
    int cnt=0;
    while((!pq.empty())&&cnt<(n+1)/2)
    {
        val=pq.top().first;
        poz=pq.top().second;
        pq.pop();
        if(v[poz]!=val) continue;
        cnt+=1;
        st=l[poz];dr=r[poz];
        v1=v2=0;
        v[poz]=-inf;
        if(st)
        {
            v1=v[st];
            l[poz]=l[st];
            r[l[poz]]=poz;
            v[st]=-inf;
        }
        if(dr<=n)
        {
            v2=v[dr];
            r[poz]=r[dr];
            l[r[poz]]=poz;
            v[dr]=-inf;
        }
        ans+=val;
        if(st&&dr)
        {
            v[poz]=v1+v2-val;
            v[poz]=max(v[poz],-inf);
            pq.push({v[poz],poz});
        }
        else v[poz]=-inf;
        cout<<ans<<'\n';
    }
    return 0;
}

Compilation message

candies.cpp:7:27: warning: integer overflow in expression [-Woverflow]
 const long long inf=100000*100000*100000*10;
                     ~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 508 KB Output isn't correct
2 Halted 0 ms 0 KB -