# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
811024 | 2023-08-06T20:42:19 Z | Ozy | Distributing Candies (IOI21_candies) | C++17 | 101 ms | 22308 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,0,n-1) { acu[i] = valor[i]; if(i > 0) acu[i] += acu[i-1]; } arr[n-1] = {acu[n-1],n-1,acu[n-1],n-1,0}; repa(i,n-2,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; } else 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; } } res.resize(c.size()); rep(i,0,c.size()-1) { lli act = c[i]; lli ini = 0; lli mitad,fin = n-1; pll last = {-1,0}; while (ini <= fin) { mitad = (ini+fin)/2; if(arr[mitad].dif >= act) { last.p = mitad; if (arr[mitad].g_id > arr[mitad].ch_id) last.in = act; else last.in = 0; ini = mitad+1; } else fin = mitad - 1; } res[i] = last.in + acu[n-1]; if (last.p >= 0) res[i] -= acu[last.p]; } return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 101 ms | 22308 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |