# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
627724 |
2022-08-12T20:33:55 Z |
tutis |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
37476 KB |
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long max_weights(int N, int MM, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<pair<int, ll>>P[N];
vector<int>G_[N + 2];
vector<int>Q_[N + 2];
vector<int>*G = G_ + 1;
vector<int>*Q = Q_ + 1;
for (int i = 0; i < MM; i++)
{
P[X[i]].push_back({Y[i], W[i]});
G[X[i]].push_back(Y[i]);
Q[X[i]].push_back(Y[i]);
G[X[i] - 1].push_back(Y[i]);
}
for (int i = -1; i <= N; i++)
{
G[i].push_back(N - 1);
Q[i].push_back(N - 1);
}
for (int i = 0; i < N; i++)
{
sort(P[i].begin(), P[i].end());
for (int j = 1; j < (int)P[i].size(); j++)
P[i][j].second += P[i][j - 1].second;
sort(G[i].begin(), G[i].end());
sort(Q[i].begin(), Q[i].end());
G[i].erase(unique(G[i].begin(), G[i].end()), G[i].end());
}
ll dp_[N + 3];
ll* dp = dp_ + 2;
for (int i = -2; i <= N; i++)
dp[i] = 0;
vector<ll> u[N];
vector<ll> d[N];
auto get = [&](int x, int y)->ll
{
if (x < 0 || x >= N)
return 0;
auto it = lower_bound(P[x].begin(), P[x].end(), make_pair(y + 1, -1ll));
if (it == P[x].begin())
return 0;
it--;
return it->second;
};
map<int, ll>M;
for (int i = -1; i <= N; i++)
M[i] = 0;
map<int, ll>K;
for (int i = -1; i <= N; i++)
K[i] = 0;
auto get1 = [&](int y)->ll
{
ll ret = 0;
for (auto i : M)
if (i.first <= y)
ret = max(ret, i.second);
return ret;
};
auto get2 = [&](int y)->ll
{
ll ret = 0;
for (auto i : K)
if (i.first >= y)
ret = max(ret, i.second);
return ret;
};
ll vv = 0;
for (int x = 0; x < N; x++)
{
dp[x] = dp[x - 1];
dp[x] = max(dp[x], vv);
vv = 0;
for (int y : Q[x - 1])
{
u[x].push_back(0);
ll&v = u[x].back();
v = max(v, dp[x - 1]);
v = max(v, dp[x - 2] + get(x - 1, y));
for (int y1 : Q[x - 1])
{
if (y1 > y)
break;
v = max(v, get(x - 1, y) - get(x - 1, y1 - 1) + get1(y1 - 1));
}
dp[x] = max(dp[x], v);
vv = max(vv, v + get(x + 1, y));
}
for (int i = 0; i < Q[x - 1].size(); i++)
{
ll v = u[x][i];
int y = Q[x - 1][i];
M[y] = max(M[y], v);
}
for (int y : Q[x + 1])
{
d[x].push_back(0);
ll&v = d[x].back();
if (y == N - 1)
v = max(v, u[x].back());
v = max(v, get2(y + 1));
dp[x] = max(dp[x], v);
vv = max(vv, v + get(x + 1, y));
}
for (int i = 0; i < Q[x + 1].size(); i++)
{
ll v = d[x][i];
int y = Q[x - 1][i];
for (int y1 : Q[x - 1])
{
if (y1 > y)
break;
ll v1 = v + get(x + 1, y) - get(x + 1, y1 - 1);
K[y1] = max(K[y1], v1);
}
}
}
return dp[N - 1];
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:93:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int i = 0; i < Q[x - 1].size(); i++)
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for (int i = 0; i < Q[x + 1].size(); i++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
32728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1093 ms |
37476 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1100 ms |
31596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Incorrect |
1 ms |
212 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1100 ms |
31596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
32728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |