# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
811030 | 2023-08-06T21:07:33 Z | Ozy | 사탕 분배 (IOI21_candies) | C++17 | 102 ms | 17592 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; } 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; } //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); res[i] = last.in + acu[n]; if (last.p >= 0) res[i] -= acu[last.p]; } return res; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 102 ms | 17592 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 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 | 1 ms | 340 KB | Output is correct |
3 | Incorrect | 46 ms | 16976 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 1 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |