제출 #1351878

#제출 시각아이디문제언어결과실행 시간메모리
1351878viettrungCandies (JOI18_candies)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fi first
#define se second
#define mll map<ll, ll>
#define sll set<ll>
const ll du = 1e9 + 7;
const ll ars = 2e5 + 5;

int n;
ll a[ars];
priority_queue<pll> q;
ll ans = 0;
bool vs[ars];
int L[ars], R[ars];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "tenshi"
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        L[i] = i - 1;
        R[i] = i + 1;
        q.push({a[i], i});  
    }
    int T = (n + 1) / 2;
    for(int t = 1; t <= T; t++){
        auto[val, i] = q.top();
        q.pop();
        if(vs[i]){
            t--;
            continue;
        }
        ans += val;
        cout << ans << '\n';

        int l = L[i], r = R[i];
        if(l >= 1) vs[l] = true;
        if(r <= n) vs[r] = true;

        int nl = (l >= 1 ? L[l] : 0);
        int nr = (r <= n ? R[r] : n + 1);

        if(l >= 1 && r <= n){
            a[i] = a[l] + a[r] - a[i];
            q.push({a[i], i});
        }

        L[i] = nl;
        R[i] = nr;

        if(nl >= 1) R[nl] = i;
        if(nr <= n) L[nr] = i;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

candies.cpp: In function 'int main()':
candies.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...