# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
211266 |
2020-03-19T20:26:23 Z |
tri |
Candies (JOI18_candies) |
C++14 |
|
630 ms |
185260 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
namespace debug {
const int DEBUG = true;
template<class T1, class T2>
void pr(const pair<T1, T2> &x);
template<class T, size_t SZ>
void pr(const array<T, SZ> &x);
template<class T>
void pr(const vector<T> &x);
template<class T>
void pr(const set<T> &x);
template<class T1, class T2>
void pr(const map<T1, T2> &x);
template<class T>
void pr(const T &x) { if (DEBUG) cout << x; }
template<class T, class... Ts>
void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }
template<class T1, class T2>
void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }
template<class T>
void prIn(const T &x) {
pr("{");
bool fst = 1;
for (auto &a : x) {
pr(fst ? "" : ", ", a), fst = 0;
}
pr("}");
}
template<class T, size_t SZ>
void pr(const array<T, SZ> &x) { prIn(x); }
template<class T>
void pr(const vector<T> &x) { prIn(x); }
template<class T>
void pr(const set<T> &x) { prIn(x); }
template<class T1, class T2>
void pr(const map<T1, T2> &x) { prIn(x); }
void ps() { pr("\n"), cout << flush; }
template<class Arg, class... Args>
void ps(const Arg &first, const Args &... rest) {
pr(first, " ");
ps(rest...);
}
}
using namespace debug;
const int MAXN = 2e5 + 10;
const ll INF = 1e15;
vl costs[4 * MAXN][4];
ll v[MAXN];
int N;
void merge(vl &a, vl &b, vl &res) {
int most = a.size() + b.size() - 2;
// ps(res.size(), most + 1);
if (res.size() <= most + 1) {
res.resize(most + 1, 0);
}
ll sum = 0;
int aI = 1, bI = 1;
res[0] = 0;
for (int i = 1; i <= most; i++) {
if (aI < a.size() && bI < b.size()) {
if (a[aI] - a[aI - 1] > b[bI] - b[bI - 1]) {
sum += a[aI] - a[aI - 1];
aI++;
} else {
sum += b[bI] - b[bI - 1];
bI++;
}
} else if (aI < a.size()) {
sum += a[aI] - a[aI - 1];
aI++;
} else {
assert(bI < b.size());
sum += b[bI] - b[bI - 1];
bI++;
}
res[i] = max(res[i], sum);
}
}
void compute(int i, int l, int r) {
if (l != r) {
int mid = (l + r) / 2;
compute(i * 2, l, mid);
compute(i * 2 + 1, mid + 1, r);
for (int cS = 0; cS < 4; cS++) {
for (int wSide = 0; wSide < 2; wSide++) {
int lS = (cS & 1) + (wSide == 0 ? 2 : 0);
int rS = (cS & 2) + (wSide == 1 ? 1 : 0);
// ps(cS, wSide, lS, rS);
// ps(l, r);
//
// ps(costs[i * 2][lS]);
// ps(costs[i * 2 + 1][rS]);
merge(costs[i * 2][lS], costs[i * 2 + 1][rS], costs[i][cS]);
// if (i == 1 && cS == 0) {
// ps(costs[i][cS]);
// ps("flag");
// }
}
}
} else {
costs[i][0] = {0, v[l]};
costs[i][1] = {0};
costs[i][2] = {0};
costs[i][3] = {0};
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> v[i];
}
compute(1, 0, N - 1);
vl &ans = costs[1][0];
assert(ans.size() - 1 == (N + 1) / 2);
for (int i = 1; i < ans.size(); i++) {
cout << ans[i] << endl;
}
// ps("debug");
// ps(costs[1][0]);
// ps(costs[2][0]);
// ps(costs[3][0]);
// ps(costs[3][1]);
}
Compilation message
candies.cpp: In function 'void merge(vl&, vl&, vl&)':
candies.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (res.size() <= most + 1) {
~~~~~~~~~~~^~~~~~~~~~~
candies.cpp:98:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (aI < a.size() && bI < b.size()) {
~~~^~~~~~~~~~
candies.cpp:98:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (aI < a.size() && bI < b.size()) {
~~~^~~~~~~~~~
candies.cpp:106:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
} else if (aI < a.size()) {
~~~^~~~~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from candies.cpp:1:
candies.cpp:110:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(bI < b.size());
~~~^~~~~~~~~~
candies.cpp: In function 'int main()':
candies.cpp:163:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(ans.size() - 1 == (N + 1) / 2);
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
candies.cpp:165:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < ans.size(); i++) {
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
76408 KB |
Output is correct |
2 |
Correct |
54 ms |
76408 KB |
Output is correct |
3 |
Correct |
58 ms |
76408 KB |
Output is correct |
4 |
Correct |
57 ms |
76408 KB |
Output is correct |
5 |
Correct |
59 ms |
76416 KB |
Output is correct |
6 |
Correct |
54 ms |
76416 KB |
Output is correct |
7 |
Correct |
58 ms |
76344 KB |
Output is correct |
8 |
Correct |
59 ms |
76408 KB |
Output is correct |
9 |
Correct |
60 ms |
76344 KB |
Output is correct |
10 |
Correct |
56 ms |
76324 KB |
Output is correct |
11 |
Correct |
54 ms |
76408 KB |
Output is correct |
12 |
Correct |
57 ms |
76408 KB |
Output is correct |
13 |
Correct |
57 ms |
76408 KB |
Output is correct |
14 |
Correct |
57 ms |
76444 KB |
Output is correct |
15 |
Correct |
52 ms |
76408 KB |
Output is correct |
16 |
Correct |
61 ms |
76408 KB |
Output is correct |
17 |
Correct |
61 ms |
76408 KB |
Output is correct |
18 |
Correct |
55 ms |
76408 KB |
Output is correct |
19 |
Correct |
59 ms |
76408 KB |
Output is correct |
20 |
Correct |
51 ms |
76408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
76408 KB |
Output is correct |
2 |
Correct |
54 ms |
76408 KB |
Output is correct |
3 |
Correct |
58 ms |
76408 KB |
Output is correct |
4 |
Correct |
57 ms |
76408 KB |
Output is correct |
5 |
Correct |
59 ms |
76416 KB |
Output is correct |
6 |
Correct |
54 ms |
76416 KB |
Output is correct |
7 |
Correct |
58 ms |
76344 KB |
Output is correct |
8 |
Correct |
59 ms |
76408 KB |
Output is correct |
9 |
Correct |
60 ms |
76344 KB |
Output is correct |
10 |
Correct |
56 ms |
76324 KB |
Output is correct |
11 |
Correct |
54 ms |
76408 KB |
Output is correct |
12 |
Correct |
57 ms |
76408 KB |
Output is correct |
13 |
Correct |
57 ms |
76408 KB |
Output is correct |
14 |
Correct |
57 ms |
76444 KB |
Output is correct |
15 |
Correct |
52 ms |
76408 KB |
Output is correct |
16 |
Correct |
61 ms |
76408 KB |
Output is correct |
17 |
Correct |
61 ms |
76408 KB |
Output is correct |
18 |
Correct |
55 ms |
76408 KB |
Output is correct |
19 |
Correct |
59 ms |
76408 KB |
Output is correct |
20 |
Correct |
51 ms |
76408 KB |
Output is correct |
21 |
Correct |
630 ms |
184244 KB |
Output is correct |
22 |
Correct |
593 ms |
184348 KB |
Output is correct |
23 |
Correct |
586 ms |
184220 KB |
Output is correct |
24 |
Correct |
553 ms |
184188 KB |
Output is correct |
25 |
Correct |
570 ms |
184092 KB |
Output is correct |
26 |
Correct |
565 ms |
184080 KB |
Output is correct |
27 |
Correct |
556 ms |
184220 KB |
Output is correct |
28 |
Correct |
547 ms |
184348 KB |
Output is correct |
29 |
Correct |
587 ms |
184348 KB |
Output is correct |
30 |
Correct |
562 ms |
184312 KB |
Output is correct |
31 |
Correct |
578 ms |
184256 KB |
Output is correct |
32 |
Correct |
556 ms |
184348 KB |
Output is correct |
33 |
Correct |
603 ms |
184108 KB |
Output is correct |
34 |
Correct |
577 ms |
183964 KB |
Output is correct |
35 |
Correct |
574 ms |
183964 KB |
Output is correct |
36 |
Correct |
592 ms |
185188 KB |
Output is correct |
37 |
Correct |
598 ms |
185092 KB |
Output is correct |
38 |
Correct |
615 ms |
184860 KB |
Output is correct |
39 |
Correct |
561 ms |
185048 KB |
Output is correct |
40 |
Correct |
552 ms |
184832 KB |
Output is correct |
41 |
Correct |
587 ms |
184732 KB |
Output is correct |
42 |
Correct |
558 ms |
184900 KB |
Output is correct |
43 |
Correct |
556 ms |
185260 KB |
Output is correct |
44 |
Correct |
579 ms |
184860 KB |
Output is correct |
45 |
Correct |
591 ms |
184988 KB |
Output is correct |
46 |
Correct |
574 ms |
184988 KB |
Output is correct |
47 |
Correct |
559 ms |
184860 KB |
Output is correct |
48 |
Correct |
558 ms |
184876 KB |
Output is correct |
49 |
Correct |
566 ms |
184732 KB |
Output is correct |
50 |
Correct |
591 ms |
184732 KB |
Output is correct |