답안 #811073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
811073 2023-08-06T23:09:49 Z Ozy 사탕 분배 (IOI21_candies) C++17
29 / 100
95 ms 22316 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>

#define MAX 200000
//para el pll de last
#define p first
#define in second

struct x {
    lli g_v;
    lli g_id;
    lli ch_v;
    lli ch_id;
    lli dif;
};

lli n;
lli acu[MAX+2];
x arr[MAX+2];
vector<int> res;


std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> valor) {
    
    n = valor.size();

    rep(i,1,n) {
        acu[i] = valor[i-1];
        acu[i] += acu[i-1];
    }

    arr[n] = {acu[n],n,acu[n],n,0};
    repa(i,n-1,0) {
        arr[i] = arr[i+1];
        
        if (acu[i] < arr[i].ch_v) {
            arr[i].ch_v = acu[i];
            arr[i].ch_id = i;
            arr[i].dif = arr[i].g_v - arr[i].ch_v; 
        }
        if (acu[i] > arr[i].g_v) {
            arr[i].g_v = acu[i];
            arr[i].g_id = i;
            arr[i].dif = arr[i].g_v - arr[i].ch_v;
        }

        //debugsl(i);
        //debug(arr[i].dif);
    }

    res.resize(c.size());
    rep(i,0,c.size()-1) {
        lli act = c[i];
        lli ini = 0;
        lli mitad,fin = n;
        pll last = {-1,0};

        while (ini <= fin) {
            mitad = (ini+fin)/2;
            if(arr[mitad].dif >= act) {
                if (arr[mitad].g_id > arr[mitad].ch_id) {
                    last.in = act;
                    last.p = arr[mitad].g_id;
                }
                else {
                    last.p = arr[mitad].ch_id;
                    last.in = 0;
                }
                ini = mitad+1;
            }
            else fin = mitad - 1;
        }

        //debugsl(last.p);
        //debug(last.in);

        if (last.p < 0) {
            last.p = arr[0].ch_id;
            last.in = 0;
        }

        res[i] = last.in + acu[n];
        res[i] -= acu[last.p];
    }

    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:7:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
candies.cpp:59:5: note: in expansion of macro 'rep'
   59 |     rep(i,0,c.size()-1) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 17480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 45 ms 14316 KB Output is correct
4 Correct 40 ms 4900 KB Output is correct
5 Correct 88 ms 21036 KB Output is correct
6 Correct 89 ms 21596 KB Output is correct
7 Correct 91 ms 22240 KB Output is correct
8 Correct 88 ms 20832 KB Output is correct
9 Correct 93 ms 22316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -