#include "fish.h"
#include "bits/stdc++.h";
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct pii{int a, b;};
ll INF = 1e16;
ll rSum(int i, vector<pii>& wx, vll& psa) {
int ind = upper_bound(all(wx), i, [](int a, pii b){return a < b.a;}) - wx.begin();
if(ind - 1 == -1) return 0;
return psa[ind-1];
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vector<vector<pii>> wx(N);
forR(i, M) wx[X[i]].push_back({Y[i], W[i]});
forR(i, N) sort(all(wx[i]), [](pii a, pii b){return a.a < b.a;});
vvll wpsa(N);
forR(i, N) if(!wx[i].empty()) {
wpsa[i].push_back(wx[i][0].b);
REP(j, 1, wx[i].size()) wpsa[i].push_back(wx[i][j].b + wpsa[i].back());
}
vector<set<int>> sidPos(N), sePos(N);
forR(i, M) {
if(X[i] > 0) sidPos[X[i]-1].insert(Y[i] + 1);
if(X[i] + 1 < N) sidPos[X[i] + 1].insert(Y[i] + 1);
if(X[i] > 1) sidPos[X[i]-2].insert(Y[i] + 1);
if(X[i] + 2 < N) sidPos[X[i] + 2].insert(Y[i] + 1);
sidPos[X[i]].insert(Y[i]+1);
if(X[i] > 0) sePos[X[i]-1].insert(Y[i] + 1);
if(X[i] + 1 < N) sePos[X[i] + 1].insert(Y[i] + 1);
if(X[i] > 1) sePos[X[i]-2].insert(Y[i] + 1);
if(X[i] + 2 < N) sePos[X[i] + 2].insert(Y[i] + 1);
sePos[X[i]].insert(Y[i]+1);
}
forR(i, N) {
sePos[i].insert(0);
}
vector<vi> idPos(N), ePos(N);
forR(i, N) {
for(int j : sidPos[i]) idPos[i].push_back(j);
for(int j : sePos[i]) ePos[i].push_back(j);
}
vvll I(N), D(N), E(N);
forR(i, N) I[i].resize(idPos[i].size()), D[i].resize(idPos[i].size()), E[i].resize(ePos[i].size());
// h = HEIGHT, not the index of last element!
forR(i, N) {
ll besIE = -INF, besII = -INF;
if(i > 0) {
forR(ki, ePos[i-1].size()) {
int k = ePos[i-1][ki];
besIE = max(besIE, E[i-1][ki] - rSum(k-1, wx[i-1], wpsa[i-1]));
}
}
int api = 0;
forR(hi, idPos[i].size()) {
int h = idPos[i][hi];
if(h > 0) {
if(i == 0) I[i][hi] = 0;
else {
I[i][hi] = max(I[i][hi], besIE + rSum(h-1, wx[i-1], wpsa[i-1]));
while(api < idPos[i-1].size() && idPos[i-1][api] <= h) {
int k = idPos[i-1][api];
besII = max(besII, I[i-1][api] - rSum(k-1, wx[i-1], wpsa[i-1]));
++api;
}
I[i][hi] = max(I[i][hi], besII + rSum(h-1, wx[i-1], wpsa[i-1]));
}
}
}
api = (int) idPos[i-1].size() - 1;
ll besD = -INF;
for(int hi = (int) idPos[i].size() - 1; hi >= 0; --hi){
int h = idPos[i][hi];
if(h > 0) {
if(i == 0) D[i][hi] = 0;
else {
while(api >= 0 && idPos[i-1][api] >= h + 1) {
int k = idPos[i-1][api];
besD = max(besD, max(I[i-1][api], D[i-1][api]) + rSum(k-1, wx[i], wpsa[i]));
--api;
}
D[i][hi] = max(D[i][hi], besD - rSum(h-1, wx[i], wpsa[i]));
}
}
}
ll besE = -INF;
if(i > 0) {
forR(yi, ePos[i-1].size()) besE = max(besE, E[i-1][yi]);
}
forR(hi, ePos[i].size()){
int h = ePos[i][hi];
if(i == 0) E[i][hi] = 0;
else {
int pi = lower_bound(all(idPos[i-1]), h) - idPos[i-1].begin();
if(idPos[i-1][pi] == h) {
ll tot = max(I[i-1][pi], D[i-1][pi]) + rSum(h-1, wx[i], wpsa[i]);
E[i][hi] = max(E[i][hi], max(tot, besE));
}
}
}
}
ll mx = 0;
forR(hi, idPos[N-1].size()) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
forR(hi, ePos[N-1].size()) mx = max(mx, E[N-1][hi]);
return mx;
}
Compilation message
fish.cpp:2:25: warning: extra tokens at end of #include directive
2 | #include "bits/stdc++.h";
| ^
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pii>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
| ^
fish.cpp:30:5: note: in expansion of macro 'REP'
30 | REP(j, 1, wx[i].size()) wpsa[i].push_back(wx[i][j].b + wpsa[i].back());
| ^~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:61:7: note: in expansion of macro 'forR'
61 | forR(ki, ePos[i-1].size()) {
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:67:5: note: in expansion of macro 'forR'
67 | forR(hi, idPos[i].size()) {
| ^~~~
fish.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | while(api < idPos[i-1].size() && idPos[i-1][api] <= h) {
| ~~~~^~~~~~~~~~~~~~~~~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:102:7: note: in expansion of macro 'forR'
102 | forR(yi, ePos[i-1].size()) besE = max(besE, E[i-1][yi]);
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:104:5: note: in expansion of macro 'forR'
104 | forR(hi, ePos[i].size()){
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:117:3: note: in expansion of macro 'forR'
117 | forR(hi, idPos[N-1].size()) mx = max(mx, max(I[N-1][hi], D[N-1][hi]));
| ^~~~
fish.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
| ^
fish.cpp:118:3: note: in expansion of macro 'forR'
118 | forR(hi, ePos[N-1].size()) mx = max(mx, E[N-1][hi]);
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
168 ms |
135496 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
344 ms |
169024 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
36 ms |
75000 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
592 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '199904465818' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
592 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '199904465818' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
592 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '199904465818' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
36 ms |
75000 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
168 ms |
135496 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |