# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1063384 | qwusha | Distributing Candies (IOI21_candies) | C++17 | 69 ms | 13680 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ld eps = 1e-8;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const ll inf = 1e18;
const ll mod = 1e9 + 7;
#include "candies.h"
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
ll n = c.size();
int q = l.size();
vector<int> res(n);
bool ch = 1;
for (int i = 0; i < q; i++) {
if (l[i] != 0 || r[i] != n - 1)
ch = 0;
}
if (ch) {
vector<int> s = {0};
int maxi = 0;
for (int i = 0; i < q; i++) {
int x = s.back() + v[i];
x = max(x, 0);
maxi = max(maxi, x);
s.push_back(x);
}
vector<int> res(n);
for (int i = 0; i < n; i++) {
if (maxi > c[i]) {
res[i] = max(0, s.back() - (maxi - c[i]));
}
}
return res;
}
if (n <= 2000 && q <= 2000) {
for (int qw = 0; qw < l.size(); qw++) {
for (int i = l[qw]; i <= r[qw]; i++) {
if (v[qw] > 0) {
res[i] = min(res[i] + v[qw], c[i]);
} else {
res[i] = max(res[i] + v[qw], 0);
}
}
}
return res;
}
vector<ll> pref(n + 1);
for (int qw = 0; qw < q; qw++) {
pref[l[qw]] += v[qw];
pref[r[qw] + 1] -= v[qw];
}
for (int i = 1; i < n; i++) {
pref[i] += pref[i - 1];
}
for (int i = 0; i < n; i++) {
res[i] = min((ll)c[i], pref[i]);
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |