답안 #1089836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1089836 2024-09-17T09:26:59 Z Pekiban Candies (JOI18_candies) C++17
8 / 100
5000 ms 5732 KB
#include <bits/stdc++.h>
    
using namespace std;
using ll = long long;
#define pb push_back
    
vector<ll> mxconv(vector<ll> &a, vector<ll> &b) {
    int n = a.size(), m = b.size();
    vector<ll> c(n+m, -1e15);
    c[0] = 0;
    int i = 1, j = 1;
    while (i < n || j < m) {
        if (i == n) ++j;
        else if (j == m)    ++i;
        else {
            if (a[i] - a[i-1] > b[j] - b[j-1])  ++i;
            else    ++j;
        }
        c[i+j-2] = a[i-1] + b[j-1];
    }
    return c;
}
vector<ll> dq(vector<ll> &a) {
    int n = a.size();
    if (n == 0) return {0};
    if (n == 1) return {0, a[0]};
    vector<ll> L, R;
    for (int i = 0; i < n/2; ++i)   L.pb(a[i]);
    for (int i = n/2; i < n; ++i)   R.pb(a[i]);
    reverse(R.begin(), R.end());
    auto A = dq(L);
    L.pop_back();
    auto B = dq(L);
    auto C = dq(R);
    R.pop_back();
    auto D = dq(R);
    auto E = mxconv(A, D);
    auto F = mxconv(C, B);
    for (int i = 0; i < E.size(); ++i)  E[i] = max(E[i], F[i]);
    return E;
}
// proof by ac lol
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    auto ans = dq(a);
    for (int i = 1; i <= (n+1)/2; ++i) {
        cout << ans[i] << '\n';
    }
}

Compilation message

candies.cpp: In function 'std::vector<long long int> dq(std::vector<long long int>&)':
candies.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < E.size(); ++i)  E[i] = max(E[i], F[i]);
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 548 KB Output is correct
2 Correct 105 ms 344 KB Output is correct
3 Correct 93 ms 348 KB Output is correct
4 Correct 93 ms 348 KB Output is correct
5 Correct 93 ms 344 KB Output is correct
6 Correct 99 ms 532 KB Output is correct
7 Correct 110 ms 344 KB Output is correct
8 Correct 95 ms 536 KB Output is correct
9 Correct 93 ms 348 KB Output is correct
10 Correct 96 ms 592 KB Output is correct
11 Correct 93 ms 344 KB Output is correct
12 Correct 94 ms 344 KB Output is correct
13 Correct 93 ms 344 KB Output is correct
14 Correct 109 ms 536 KB Output is correct
15 Correct 93 ms 348 KB Output is correct
16 Correct 104 ms 540 KB Output is correct
17 Correct 112 ms 528 KB Output is correct
18 Correct 107 ms 536 KB Output is correct
19 Correct 100 ms 548 KB Output is correct
20 Correct 104 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 548 KB Output is correct
2 Correct 105 ms 344 KB Output is correct
3 Correct 93 ms 348 KB Output is correct
4 Correct 93 ms 348 KB Output is correct
5 Correct 93 ms 344 KB Output is correct
6 Correct 99 ms 532 KB Output is correct
7 Correct 110 ms 344 KB Output is correct
8 Correct 95 ms 536 KB Output is correct
9 Correct 93 ms 348 KB Output is correct
10 Correct 96 ms 592 KB Output is correct
11 Correct 93 ms 344 KB Output is correct
12 Correct 94 ms 344 KB Output is correct
13 Correct 93 ms 344 KB Output is correct
14 Correct 109 ms 536 KB Output is correct
15 Correct 93 ms 348 KB Output is correct
16 Correct 104 ms 540 KB Output is correct
17 Correct 112 ms 528 KB Output is correct
18 Correct 107 ms 536 KB Output is correct
19 Correct 100 ms 548 KB Output is correct
20 Correct 104 ms 548 KB Output is correct
21 Execution timed out 5071 ms 5732 KB Time limit exceeded
22 Halted 0 ms 0 KB -