#include "candies.h"
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int root = 450;
int buck[500];
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n = c.size(), q = l.size();
std::vector<int> s(n);
for(int i=0; i<q; i++){
int sb = l[i]/root, lb = r[i]/root;
int esb = (sb + 1)*root - 1, slb = lb*root;
if(sb == lb){
for(int j=l[i]; j<=r[i]; j++){
if(v[i] > 0) s[j] = min(c[j], s[j] + v[i]);
else s[j] = max(0,s[j] + v[i]);
}
continue;
}
for(int j=l[i]; j<=esb; j++){
if(v[i] > 0) s[j] = min(c[j], s[j] + v[i]);
else s[j] = max(0,s[j] + v[i]);
}
for(int j=sb+1; j<=lb-1; j++){
if(v[i] > 0) buck[j] = min(c[j], buck[j] + v[i]);
else buck[j] = max(0,buck[j] + v[i]);
}
for(int j=slb; j<=r[i]; j++){
if(v[i] > 0) s[j] = min(c[j], s[j] + v[i]);
else s[j] = max(0,s[j] + v[i]);
}
}
for(int i=0; i<n; i++){
s[i] = min(c[i], s[i] + buck[i/root]);
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
229 ms |
12060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
118 ms |
8008 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |