답안 #1050706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050706 2024-08-09T12:56:49 Z Zicrus 사탕 분배 (IOI21_candies) C++17
29 / 100
103 ms 16980 KB
#include <bits/stdc++.h>
#include "candies.h"
using namespace std;

typedef long long ll;

ll n, q;
vector<pair<ll, ll>> cap;
vector<pair<ll, ll>> tim;
vector<ll> sum;

vector<int> distribute_candies(vector<int> c, vector<int> l,
                               vector<int> r, vector<int> v) {
    n = c.size(); q = v.size();
    cap = vector<pair<ll, ll>>(n);
    tim = {{-n+1, 0}};
    sum = vector<ll>(q+1);
    for (int i = 0; i < q; i++) {
        sum[i+1] = sum[i] + v[i];
    }
    for (int i = 0; i < n; i++) {
        cap[i] = {c[i], i};
    }
    sort(cap.begin(), cap.end());

    for (int i = 0; i < q; i++) {
        ll mx = cap[-tim.back().first].first;
        ll nw = sum[i+1] - sum[abs(tim.back().second)];
        if (tim.back().second < 0) nw += mx;
        ll tId = tim.size()-1;
        while (tId > 0 && (nw < 0 || nw > mx)) {
            tId--;
            mx = cap[-tim[tId].first].first;
            nw = sum[i+1] - sum[abs(tim[tId].second)];
            if (tim[tId].second < 0) nw += mx;
        }
        
        ll left = -1, right = -tim[tId].first;
        while (left < right) {
            ll mid = (left+right+1) / 2;
            pair<ll, ll> d = {-mid, 1000000000000ll};
            ll nId = upper_bound(tim.begin(), tim.end(), d) - tim.begin() - 1;
            ll v = sum[i+1] - sum[abs(tim[nId].second)];
            if (tim[nId].second < 0) v += cap[mid].first;
            if (v < 0 || v > cap[mid].first) {
                left = mid;
            }
            else {
                right = mid-1;
            }
        }
        while (tId != tim.size()-1) tim.pop_back();
        if (-left == tim.back().first) tim.back().second = v[i] < 0 ? (i+1) : -(i+1);
        else if (left >= 0) tim.push_back({-left, v[i] < 0 ? (i+1) : -(i+1)});
    }

    vector<int> res(n);
    for (int i = 0; i < n; i++) {
        while (i > -tim.back().first) tim.pop_back();
        res[cap[i].second] = sum[q] - sum[abs(tim.back().second)];
        if (tim.back().second < 0) res[cap[i].second] += cap[i].first;
    }
    return res;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:52:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         while (tId != tim.size()-1) tim.pop_back();
      |                ~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 100 ms 12116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 52 ms 9184 KB Output is correct
4 Correct 38 ms 7180 KB Output is correct
5 Correct 100 ms 15684 KB Output is correct
6 Correct 103 ms 16228 KB Output is correct
7 Correct 100 ms 16932 KB Output is correct
8 Correct 99 ms 15444 KB Output is correct
9 Correct 71 ms 16980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -