제출 #312201

#제출 시각아이디문제언어결과실행 시간메모리
312201two_sidesHoliday (IOI14_holiday)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 3e5 + 5;
ll f[N], g[N], p[N], a[N];
int start, n, d;

void calc1(int l, int r, int optl, int optr){
    int m = (l + r) / 2, optm; ll sum = 0;
    priority_queue <int,
    vector <int>, greater <int>> pq;
    for (int i = start; i < optl; i++){
        sum += a[i]; pq.push(a[i]);
    }
    for (int i = optl; i <= optr; i++){
        sum += a[i]; pq.push(a[i]);
        if (i - start > m) break;
        while (pq.size() > m - i + start){
            sum -= pq.top(); pq.pop();
        }
        if (sum > f[m]){
            f[m] = sum; optm = i;
        }
    }
    p[m] = optm;
    if (l < m) calc1(l, m - 1, optl, optm);
    if (m < r) calc1(m + 1, r, optm, optr);
}

void calc2(int l, int r, int optl, int optr){
    if (optl < optr) return;
    int m = (l + r) / 2, optm; ll sum = 0;
    priority_queue <int,
    vector <int>, greater <int>> pq;
    for (int i = start - 1; i > optl; i--){
        sum += a[i]; pq.push(a[i]);
    }
    for (int i = optl; i >= optr; i--){
        sum += a[i]; pq.push(a[i]);
        if (start - 1 - i > m) break;
        while (pq.size() > m + i - start + 1){
            sum -= pq.top(); pq.pop();
        }
        if (sum > g[m]){
            g[m] = sum; optm = i;
        }
    }
    if (l < m) calc2(l, m - 1, optl, optm);
    if (m < r) calc2(m + 1, r, optm, optr);
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> start >> d; start++;
    for (int i = 1; i <= n; i++) cin >> a[i];
    calc1(1, d, start, n);
    calc2(1, d, start - 1, 1);
    ll res = 0;
    for (int i = 1; i <= d; i++){
        res = max(res, f[i]);
        if (d - i - (p[i] - start) > 0)
            res = max(res, f[i] +
            g[d - i - p[i] + start - 1]);
    }
    cout << res << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

holiday.cpp: In function 'void calc1(int, int, int, int)':
holiday.cpp:20:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |         while (pq.size() > m - i + start){
      |                ~~~~~~~~~~^~~~~~~~~~~~~~~
holiday.cpp: In function 'void calc2(int, int, int, int)':
holiday.cpp:43:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |         while (pq.size() > m + i - start + 1){
      |                ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
holiday.cpp:51:21: warning: 'optm' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |     if (m < r) calc2(m + 1, r, optm, optr);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
holiday.cpp: In function 'void calc1(int, int, int, int)':
holiday.cpp:27:12: warning: 'optm' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |     p[m] = optm;
      |            ^~~~
/tmp/ccRPKrza.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccrBJNHj.o:holiday.cpp:(.text.startup+0x0): first defined here
/tmp/ccRPKrza.o: In function `main':
grader.cpp:(.text.startup+0x89): undefined reference to `findMaxAttraction(int, int, int, int*)'
collect2: error: ld returned 1 exit status