답안 #251627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251627 2020-07-22T05:16:30 Z dantoh000 Candies (JOI18_candies) C++14
0 / 100
3 ms 640 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll, ll, ll> iii;
int n;
set<iii> VLR, LRV;
ll ans = 0;
int main(){
    scanf("%d",&n);
    for (int i = 0; i < n; i++){
        int x;
        scanf("%lld",&x);
        VLR.insert({x,i,i});
        LRV.insert({i,i,x});
    }
    for (int i = 1; i <= (n+1)/2; i++){
        /*for (auto x : VLR){
            int a,b,c;
            tie(a,b,c) = x;
            printf("<%d %d %d>",a,b,c);
        }
        printf("<- VLR\n");
        for (auto x : LRV){
            int a,b,c;
            tie(a,b,c) = x;
            printf("<%d %d %d>",a,b,c);
        }
        printf("<- LRV\n");*/
        int v,l,r;
        tie(v,l,r) = *(--VLR.end());
        ans += v;
        auto it = LRV.find({l,r,v});
        v = -v;
        if (it != LRV.begin()){
            auto itL = prev(it);
            int vL, lL, rL;
            tie(lL, rL, vL) = *itL;
            v += vL;
            VLR.erase({vL,lL,rL});
            LRV.erase(itL);
        }
        if (next(it) != LRV.end()){
            auto itR = next(it);
            int vR, lR, rR;
            tie(lR, rR, vR) = *itR;
            v += vR;
            VLR.erase({vR,lR,rR});
            LRV.erase(itR);
        }
        VLR.erase(--VLR.end());
        LRV.erase(it);
        VLR.insert({v,l,r});
        LRV.insert({l,r,v});
        printf("%lld\n",ans);
    }




}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:12:24: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
         scanf("%lld",&x);
                      ~~^
candies.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
candies.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -