Submission #151953

# Submission time Handle Problem Language Result Execution time Memory
151953 2019-09-05T16:01:13 Z dolphingarlic Lightning Conductor (POI11_pio) C++14
36 / 100
185 ms 17944 KB
#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (ll i = x; i < y; i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
 
ll h[500000], dp[500000];
 
double calc(ll k, ll i) { return h[k] + sqrt(abs(i - k)); }
 
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  FOR(i, 0, n) {
    cin >> h[i];
    dp[i] = h[i];
  }
 
  deque<ll> q;
  q.push_back(0);
  FOR(i, 1, n) {
    while (q.size() > 1 && calc(q[0], i) <= calc(q[1], i)) q.pop_front();
    dp[i] = max(dp[i], (ll)ceil(calc(q[0], i)));
    while (q.size() > 1 &&
           calc(q.back(), i + 1) - calc(q[q.size() - 2], i + 1) <=
               calc(i, i + 1) - calc(q.back(), i + 1))
      q.pop_back();
    q.push_back(i);
  }
 
  q.clear();
  q.push_back(n - 1);
  for (ll i = n - 2; i >= 0; i--) {
    while (q.size() > 1 && calc(q[0], i) <= calc(q[1], i)) q.pop_front();
    dp[i] = max(dp[i], (ll)ceil(calc(q[0], i)));
    while (q.size() > 1 &&
           calc(q.back(), i - 1) - calc(q[q.size() - 2], i - 1) <=
               calc(i, i - 1) - calc(q.back(), i - 1))
      q.pop_back();
    q.push_back(i);
  }
 
  FOR(i, 0, n) cout << dp[i] - h[i] << '\n';
  return 0;
}

Compilation message

pio.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
 #pragma GCC Optimize("O3")
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2232 KB Output is correct
2 Correct 17 ms 2296 KB Output is correct
3 Incorrect 22 ms 2296 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 3336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 7276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 132 ms 12732 KB Output is correct
2 Correct 117 ms 10764 KB Output is correct
3 Incorrect 109 ms 11384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 17944 KB Output is correct
2 Correct 165 ms 15152 KB Output is correct
3 Incorrect 157 ms 16104 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 15580 KB Output isn't correct
2 Halted 0 ms 0 KB -