답안 #202254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202254 2020-02-14T15:07:44 Z quocnguyen1012 Candies (JOI18_candies) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 2e5 + 5;
const ll linf = 1e18;

int N;
ll a[maxn]; int prf[maxn], nxt[maxn];
priority_queue<pair<ll, int>> pq;

bool del(int idx)
{
  prf[nxt[idx]] = prf[idx];
  nxt[prf[idx]] = nxt[idx];
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N;
  for (int i = 1; i <= N; ++i){
    cin >> a[i];
    prf[i] = i - 1;
    nxt[i] = i + 1;
    pq.push(mp(a[i], i));
  }
  ll res = 0;
  for (int i = 1; i <= (N + 1) / 2; ++i){
    while (pq.size() && a[pq.top().se] != pq.top().fi) pq.pop();
    auto now = pq.top(); pq.pop();
    res += now.fi;
    cout << res << '\n';
    int pos = now.se;
    a[pos] = max(-inf, a[prf[pos]] + a[nxt[pos]] - a[pos]);
    int L = prf[pos], R = nxt[pos];
    del(L); del(R);
    a[L] = a[R] = -inf;
    pq.push(mp(a[pos], pos));
  }
}

Compilation message

candies.cpp: In function 'bool del(int)':
candies.cpp:22:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
candies.cpp: In function 'int main()':
candies.cpp:45:19: error: 'inf' was not declared in this scope
     a[pos] = max(-inf, a[prf[pos]] + a[nxt[pos]] - a[pos]);
                   ^~~
candies.cpp:45:19: note: suggested alternative: 'linf'
     a[pos] = max(-inf, a[prf[pos]] + a[nxt[pos]] - a[pos]);
                   ^~~
                   linf
candies.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
candies.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~