# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
839024 |
2023-08-28T13:40:07 Z |
abczz |
Catfish Farm (IOI22_fish) |
C++17 |
|
182 ms |
33868 KB |
#include "fish.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <map>
#include <queue>
#define ll long long
using namespace std;
vector <array<ll, 2>> V[100000];
vector <ll> pre;
vector <array<ll, 2>> dp[100000];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
ll f = -1e18, j, k, l, s = 0, t = 0, v, x, u, p = -1e18, mx, mx2, cur;
map <ll, ll> mp;
for (int i=0; i<M; ++i) {
V[X[i]].push_back({Y[i], W[i]});
}
for (int i=0; i<N; ++i) {
sort(V[i].begin(), V[i].end());
}
for (auto [y, w] : V[1]) {
dp[0].push_back({y, 0});
}
for (int i=1; i<N; ++i) {
if (i >= 3) {
j = 0;
s = 0;
for (auto [y, w] : dp[i-3]) {
while (j < V[i-2].size() && V[i-2][j][0] <= y) {
s += V[i-2][j][1];
++j;
}
p = max(p, s+w);
}
}
mp.clear();
mx = mx2 = -1e18, s = 0;
if (i >= 2) {
j = 0;
for (auto [y, w] : dp[i-2]) {
while (j < V[i-1].size() && V[i-1][j][0] <= y) {
s += V[i-1][j][1];
++j;
}
mx = max(mx, w);
mx2 = max(mx2, w+s);
}
}
for (auto [y, w] : V[i-1]) {
++mp[y];
}
if (i != N-1) {
for (auto [y, w] : V[i+1]) {
++mp[y];
}
}
s = j = k = t = 0;
v = x = -1e18;
pre.clear();
for (auto [y, w] : dp[i-1]) {
while (j < V[i].size() && V[i][j][0] <= y) {
s += V[i][j][1];
++j;
}
while (k < V[i-1].size() && V[i-1][k][0] <= y) {
t += V[i-1][k][1];
++k;
}
v = max(v, w+s);
x = max(x, w-t);
}
s = j = k = t = l = u = 0;
for (auto [y, z] : mp) {
while (j < V[i].size() && V[i][j][0] <= y) {
s += V[i][j][1];
++j;
}
while (k < V[i-1].size() && V[i-1][k][0] <= y) {
t += V[i-1][k][1];
++k;
}
while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) {
u += V[i+1][l][1];
++l;
}
cur = max(max(t, p), max(mx2, mx+t));
cur = max(cur, max(v-s, x+t));
dp[i].push_back({y, cur});
//cout << i << " " << y << " " << cur << endl;
f = max(f, cur + u);
}
}
return f;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:32:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | while (j < V[i-2].size() && V[i-2][j][0] <= y) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:44:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while (j < V[i-1].size() && V[i-1][j][0] <= y) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:64:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | while (j < V[i].size() && V[i][j][0] <= y) {
| ~~^~~~~~~~~~~~~
fish.cpp:68:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | while (k < V[i-1].size() && V[i-1][k][0] <= y) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:77:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | while (j < V[i].size() && V[i][j][0] <= y) {
| ~~^~~~~~~~~~~~~
fish.cpp:81:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | while (k < V[i-1].size() && V[i-1][k][0] <= y) {
| ~~^~~~~~~~~~~~~~~
fish.cpp:85:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | while (i != N-1 && l < V[i+1].size() && V[i+1][l][0] <= y) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
16680 KB |
Output is correct |
2 |
Correct |
54 ms |
18572 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
182 ms |
33868 KB |
Output is correct |
6 |
Correct |
163 ms |
33644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
86 ms |
22944 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '80957127419834' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
24 ms |
10104 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4948 KB |
1st lines differ - on the 1st token, expected: '8866', found: '7755' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4948 KB |
1st lines differ - on the 1st token, expected: '8866', found: '7755' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Incorrect |
3 ms |
4948 KB |
1st lines differ - on the 1st token, expected: '8866', found: '7755' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
24 ms |
10104 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
16680 KB |
Output is correct |
2 |
Correct |
54 ms |
18572 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
182 ms |
33868 KB |
Output is correct |
6 |
Correct |
163 ms |
33644 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
86 ms |
22944 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '80957127419834' |
9 |
Halted |
0 ms |
0 KB |
- |