Submission #202255

# Submission time Handle Problem Language Result Execution time Memory
202255 2020-02-14T15:08:17 Z quocnguyen1012 Candies (JOI18_candies) C++14
0 / 100
6 ms 504 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(-linf, a[prf[pos]] + a[nxt[pos]] - a[pos]);
    int L = prf[pos], R = nxt[pos];
    del(L); del(R);
    a[L] = a[R] = -linf;
    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: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);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -