# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548916 | 2022-04-14T17:26:14 Z | cig32 | Distributing Candies (IOI21_candies) | C++17 | 4925 ms | 2097152 KB |
#include "candies.h" #include "bits/stdc++.h" using namespace std; #include <cassert> #include <cstdio> #include <vector> 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(); std::vector<int> s(n); int q = l.size(); vector<long long> list[n]; for(int i=0; i<n; i++) { list[i].push_back(1e15); list[i].push_back(-1e15); } for(int i=0; i<q; i++) { for(int j=l[i]; j<=r[i]; j++) list[j].push_back(v[i]); } for(int i=0; i<n; i++) { int k = list[i].size(); long long ps[k]; ps[0] = list[i][0]; for(int j=1; j<k; j++) ps[j] = ps[j-1] + list[i][j]; long long smax[k], smin[k]; smax[k-1] = ps[k-1]; smin[k-1] = ps[k-1]; for(int j=k-2; j>=0; j--) { smax[j] = max(smax[j+1], ps[j]); smin[j] = min(smin[j+1], ps[j]); } int idx = -1; long long optl, optr; long long lb = 0, rb = c[i]; for(int j=0; j<k; j++) { bool crash = 0; if(ps[j] >= rb) { long long q = ps[j] - rb; rb += q; lb += q; crash = 1; } if(ps[j] <= lb) { long long q = lb - ps[j]; rb -= q; lb -= q; crash = 1; } if(crash && smax[j] - smin[j] <= c[i]) { idx = j; optl = lb, optr = rb; } if(crash && smax[j] - smin[j] <= c[i]) { idx = j; optl = lb, optr = rb; } } if(idx == -1) { optl = 0, optr = c[i]; } s[i] = ps[k-1] - optl; } return s; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 2 ms | 468 KB | Output is correct |
4 | Correct | 2 ms | 1108 KB | Output is correct |
5 | Correct | 27 ms | 13908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 4925 ms | 2097152 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 508 KB | Output is correct |
2 | Correct | 3015 ms | 1109340 KB | Output is correct |
3 | Correct | 3930 ms | 1299848 KB | Output is correct |
4 | Runtime error | 4799 ms | 2097152 KB | Execution killed with signal 9 |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Runtime error | 4653 ms | 2097152 KB | Execution killed with signal 9 |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 2 ms | 468 KB | Output is correct |
4 | Correct | 2 ms | 1108 KB | Output is correct |
5 | Correct | 27 ms | 13908 KB | Output is correct |
6 | Runtime error | 4925 ms | 2097152 KB | Execution killed with signal 9 |
7 | Halted | 0 ms | 0 KB | - |