Submission #952582

# Submission time Handle Problem Language Result Execution time Memory
952582 2024-03-24T10:02:43 Z serifefedartar Lightning Conductor (POI11_pio) C++17
100 / 100
129 ms 14064 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 20
const ll MOD = 998244353;
const ll MAXN = 2e5 + 100;

vector<int> h, dp1, dp2;
void dac(vector<int> &dp, int l, int r, int opt_l, int opt_r) {
    if (l > r)
        return ;

    double mx = 0; 
    int opt = -1;
    int mid = l + (r - l) / 2;
    for (int now = opt_l; now <= min(mid, opt_r); now++) {
        if (h[now] + sqrt(mid - now) > mx) {
            mx = h[now] + sqrt(mid - now);
            opt = now;
        }
    }
    dp[mid] = ceil(mx);

    dac(dp, l, mid-1, opt_l, opt);
    dac(dp, mid+1, r, opt, opt_r);
}

int main() {
    fast
    int n;
    cin >> n;

    h = vector<int>(n+1);
    dp1 = vector<int>(n+2);
    dp2 = vector<int>(n+2);
    for (int i = 1; i <= n; i++)
        cin >> h[i];

    dac(dp1, 1, n, 1, n);
    for (int i = 1; i <= n / 2; i++)
        swap(h[i], h[n-i+1]);
    dac(dp2, 1, n, 1, n);

    for (int i = 1; i <= n; i++)
        cout << max(0, max(dp1[i], dp2[n - i + 1]) - h[n - i + 1]) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2140 KB Output is correct
2 Correct 14 ms 1624 KB Output is correct
3 Correct 14 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2644 KB Output is correct
2 Correct 24 ms 2488 KB Output is correct
3 Correct 22 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 5696 KB Output is correct
2 Correct 58 ms 5236 KB Output is correct
3 Correct 53 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 10324 KB Output is correct
2 Correct 89 ms 8276 KB Output is correct
3 Correct 83 ms 9292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 13912 KB Output is correct
2 Correct 123 ms 11084 KB Output is correct
3 Correct 119 ms 12976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 11660 KB Output is correct
2 Correct 121 ms 13136 KB Output is correct
3 Correct 122 ms 14064 KB Output is correct