Submission #952558

# Submission time Handle Problem Language Result Execution time Memory
952558 2024-03-24T08:47:18 Z serifefedartar Lightning Conductor (POI11_pio) C++17
27 / 100
293 ms 13828 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;
vector<int> dp1, dp2;
int sq(int x) {
    int l = 0;
    int r = 1000;
    int ans = 1000;
    while (r >= l) {
        int mid = l + (r - l) / 2;
        if (mid * mid >= x) {
            ans = mid;
            r = mid - 1;
        } else
            l = mid + 1;
    }
    return ans;
}

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

    int mx = 0, opt = -1;
    int mid = l + (r - l) / 2;
    for (int now = opt_l; now <= min(mid, opt_r); now++) {
        if (h[now] + sq(mid - now) >= mx) {
            mx = h[now] + sq(mid - now);
            opt = now;
        }
    }
    dp[mid] = 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(dp1[i], dp2[n - i + 1]) - h[n - i + 1] << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 2748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 126 ms 5408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 191 ms 9984 KB Output is correct
2 Incorrect 190 ms 7912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 278 ms 13828 KB Output is correct
2 Incorrect 275 ms 10936 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 293 ms 11192 KB Output isn't correct
2 Halted 0 ms 0 KB -