답안 #979483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
979483 2024-05-11T06:18:07 Z michified Lightning Conductor (POI11_pio) C++17
45 / 100
629 ms 13968 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, i, cur = 0, at = 0, tmp, j;
    cin >> n;
    vector<int> h(n), ans(n);
    for (i = 0; i < n; i++) cin >> h[i];

    vector<int> hull = {0};
    for (i = 1; i < n; i++) {
        if (h[i] > h[hull.back()]) hull.push_back(i);
    }
    for (i = 0; i < n; i++) {
        if (at < hull.size() - 1 and i == hull[at + 1]) at++;
        j = at;
        tmp = cur;
        while (j > cur and h[hull[j]] + sqrt(i - hull[j]) >= h[hull[cur]] + sqrt(i - hull[cur])) {
            tmp = j;
            j--;
        }
        cur = tmp;
        while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
        ans[i] = max(ans[i], (int) ceil(h[hull[cur]] + sqrt(i - hull[cur])));
    }

    reverse(h.begin(), h.end());
    reverse(ans.begin(), ans.end());
    hull = {0};
    for (i = 1; i < n; i++) {
        if (h[i] > h[hull.back()]) hull.push_back(i);
    }
    cur = 0, at = 0;
    for (i = 0; i < n; i++) {
        if (at < hull.size() - 1 and i == hull[at + 1]) at++;
        j = at;
        tmp = cur;
        while (j > cur and h[hull[j]] + sqrt(i - hull[j]) >= h[hull[cur]] + sqrt(i - hull[cur])) {
            tmp = j;
            j--;
        }
        cur = tmp;
        while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
        ans[i] = max(ans[i], (int) ceil(h[hull[cur]] + sqrt(i - hull[cur])));
    }

    reverse(ans.begin(), ans.end());
    reverse(h.begin(), h.end());
    for (i = 0; i < n; i++) cout << max(0, ans[i] - h[i]) << endl;
    return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         if (at < hull.size() - 1 and i == hull[at + 1]) at++;
      |             ~~~^~~~~~~~~~~~~~~~~
pio.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
      |                ~~~~^~~~~~~~~~~~~~~~~
pio.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if (at < hull.size() - 1 and i == hull[at + 1]) at++;
      |             ~~~^~~~~~~~~~~~~~~~~
pio.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[cur + 1]] + sqrt(i - hull[cur + 1])) cur++;
      |                ~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 1828 KB Output is correct
2 Correct 73 ms 1300 KB Output is correct
3 Incorrect 77 ms 1612 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 2408 KB Output is correct
2 Correct 116 ms 2456 KB Output is correct
3 Incorrect 116 ms 2752 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 5508 KB Output is correct
2 Correct 274 ms 5092 KB Output is correct
3 Incorrect 290 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 429 ms 10064 KB Output is correct
2 Correct 411 ms 7908 KB Output is correct
3 Incorrect 439 ms 8652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 607 ms 13968 KB Output is correct
2 Correct 591 ms 11308 KB Output is correct
3 Incorrect 629 ms 12028 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 11600 KB Output is correct
2 Correct 586 ms 11252 KB Output is correct
3 Incorrect 624 ms 12036 KB Output isn't correct
4 Halted 0 ms 0 KB -