# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
816922 |
2023-08-09T07:32:52 Z |
GEN 이지후(#10378) |
Ants and Sugar (JOI22_sugar) |
C++17 |
|
4000 ms |
21500 KB |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
lint q, l;
cin >> q >> l;
vector<array<lint, 3>> qry(q);
vector<int> vect;
for (int i = 0; i < q; i++) {
for (int j = 0; j < 3; j++) {
cin >> qry[i][j];
}
if (qry[i][0] == 1) {
qry[i][1] -= l;
}
if (qry[i][0] == 2)
vect.push_back(qry[i][1]);
}
sort(all(vect));
vect.resize(unique(all(vect)) - vect.begin());
// (my weight, R mode, T mode)
vector<array<lint, 3>> values(sz(vect));
lint sugsum = 0;
for (int i = 0; i < q; i++) {
if (qry[i][0] == 1) {
auto it = lower_bound(all(vect), qry[i][1]) - vect.begin();
if (it < sz(vect))
values[it][1] += qry[i][2];
for (int pos = it; pos < sz(vect); pos++) {
if (vect[pos] - qry[i][1] <= 2 * l)
values[pos][2] += qry[i][2];
else
break;
}
} else {
auto it = lower_bound(all(vect), qry[i][1]) - vect.begin();
values[it][0] += qry[i][2];
sugsum += qry[i][2];
}
vector<array<lint, 3>> dp(sz(vect) + 1);
dp[0][1] = dp[0][2] = -1e18;
for (int i = 1; i <= sz(vect); i++) {
dp[i][0] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]});
dp[i][1] = max({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) + values[i - 1][0] - values[i - 1][2];
if (i > 1 && vect[i - 1] - vect[i - 2] <= 2 * l) {
dp[i][2] = max({dp[i - 1][1], dp[i - 1][2]}) + values[i - 1][0] - values[i - 1][1];
} else
dp[i][2] = -1e18;
}
cout << sugsum - *max_element(all(dp.back())) << "\n";
}
}
# |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
12 ms |
424 KB |
Output is correct |
7 |
Correct |
10 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
30 ms |
540 KB |
Output is correct |
11 |
Correct |
31 ms |
548 KB |
Output is correct |
12 |
Correct |
29 ms |
468 KB |
Output is correct |
13 |
Correct |
29 ms |
560 KB |
Output is correct |
14 |
Correct |
57 ms |
612 KB |
Output is correct |
15 |
Correct |
57 ms |
628 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
29 ms |
544 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
31 ms |
456 KB |
Output is correct |
22 |
Correct |
1 ms |
452 KB |
Output is correct |
23 |
Correct |
28 ms |
548 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
30 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Execution timed out |
4042 ms |
21500 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
4025 ms |
13112 KB |
Time limit exceeded |
3 |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
12 ms |
424 KB |
Output is correct |
7 |
Correct |
10 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
30 ms |
540 KB |
Output is correct |
11 |
Correct |
31 ms |
548 KB |
Output is correct |
12 |
Correct |
29 ms |
468 KB |
Output is correct |
13 |
Correct |
29 ms |
560 KB |
Output is correct |
14 |
Correct |
57 ms |
612 KB |
Output is correct |
15 |
Correct |
57 ms |
628 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
29 ms |
544 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
31 ms |
456 KB |
Output is correct |
22 |
Correct |
1 ms |
452 KB |
Output is correct |
23 |
Correct |
28 ms |
548 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
30 ms |
560 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Execution timed out |
4042 ms |
21500 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |