답안 #795407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795407 2023-07-27T09:08:51 Z nonono Lightning Conductor (POI11_pio) C++14
82 / 100
292 ms 23044 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 5e5 + 10;
int n;
int h[mxN];
long double a[mxN], b[mxN];

deque<array<int, 3>> dq;

long double eval(pair<int, int> a, int x) {
    return (long double)a.second + (long double)sqrt(x - a.first);
}

int slope(pair<int, int> x, pair<int, int> y) {
    int low = y.first, right = n;
    
    while(low <= right) {
        int mid = (low + right) / 2;
        if(sqrt(mid - x.first) + x.second >= sqrt(mid - y.first) + y.second) {
            low = mid + 1;
        } else {
            right = mid - 1;
        }
    }
    
    return low;
}

void ins(pair<int, int> newLine) {
    while(!dq.empty()) {
        dq.back()[2] = slope({dq.back()[0], dq.back()[1]}, newLine);
        if(dq.size() > 1 && dq[dq.size() - 2][2] >= dq.back()[2]) dq.pop_back(); 
        else break ;
    }
    
    dq.push_back({newLine.first, newLine.second, n + 1});
}

void solve(long double dp[]) {
    dq.clear();
    
    for(int i = 1; i <= n; i ++) {
        ins({i, h[i]});
    
        while(!dq.empty() && dq.front()[2] < i) dq.pop_front();
        dp[i] = eval({dq.front()[0], dq.front()[1]}, i);
    }
}

int main() {
    #define taskname ""

    if (fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n;
    
    for(int i = 1; i <= n; i ++) cin >> h[i];
    
    solve(a);
    reverse(h + 1, h + 1 + n);
    
    solve(b);
    reverse(h + 1, h + 1 + n);
    reverse(b + 1, b + 1 + n);
    
    for(int i = 1; i <= n; i ++) cout << (int)ceil(max(a[i], b[i])) - h[i] << "\n";
    return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pio.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 1800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 2696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 3044 KB Output is correct
2 Correct 29 ms 2888 KB Output is correct
3 Correct 35 ms 3168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 4328 KB Output is correct
2 Correct 52 ms 4204 KB Output is correct
3 Correct 50 ms 4796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 9528 KB Output is correct
2 Correct 119 ms 9304 KB Output is correct
3 Correct 117 ms 9988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 16232 KB Output is correct
2 Correct 201 ms 14120 KB Output is correct
3 Correct 184 ms 16336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 292 ms 23000 KB Output is correct
2 Correct 276 ms 20000 KB Output is correct
3 Correct 272 ms 23032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 20544 KB Output is correct
2 Correct 273 ms 20040 KB Output is correct
3 Correct 272 ms 23044 KB Output is correct