답안 #832025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832025 2023-08-20T20:44:15 Z Johann 사탕 분배 (IOI21_candies) C++17
29 / 100
118 ms 19772 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

int N, Q;
vi C, L, R, V;
vector<int> ans;

std::vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
    C = vi(all(c));
    N = sz(c);
    Q = sz(l);

    vector<pii> cap;
    for (int i = 0; i < N; ++i)
        cap.push_back({c[i], i});
    sort(all(cap));
    reverse(all(cap));

    vector<ll> value(1, 0);
    for (int q = 0; q < Q; ++q)
        value.push_back(value.back() + (ll)v[q]);

    ans.resize(N);
    ll ref = value.back();
    ll mini = ref, maxi = ref;
    for (int i = sz(value) - 1; i >= 0; --i)
    {
        if (value[i] < mini)
        {
            ll maxRange = maxi - value[i];
            while (!cap.empty() && cap.back().first <= maxRange)
            {
                ans[cap.back().second] = ref - (maxi - cap.back().first);
                cap.pop_back();
            }
            mini = value[i];
        }
        else if (value[i] > maxi)
        {
            ll maxRange = value[i] - mini;
            while (!cap.empty() && cap.back().first <= maxRange)
            {
                ans[cap.back().second] = ref - mini;
                cap.pop_back();
            }
            maxi = value[i];
        }
    }
    while (!cap.empty())
    {
        ans[cap.back().second] = ref - mini;
        cap.pop_back();
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 108 ms 16644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 45 ms 9824 KB Output is correct
4 Correct 55 ms 9368 KB Output is correct
5 Correct 118 ms 18060 KB Output is correct
6 Correct 104 ms 18988 KB Output is correct
7 Correct 103 ms 19648 KB Output is correct
8 Correct 99 ms 18268 KB Output is correct
9 Correct 88 ms 19772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -