# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
828295 |
2023-08-17T07:56:54 Z |
peteza |
Catfish Farm (IOI22_fish) |
C++17 |
|
1000 ms |
73380 KB |
#include "fish.h"
#include <vector>
#include <algorithm>
#include <iostream>
#include <climits>
#include <map>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
int n, m;
vector<pll> pts[100005];
vector<int> dppoints[100005];
long long getsum(int col, int row) {
if(col == -1 || col == n) return 0;
auto it = upper_bound(pts[col].begin(), pts[col].end(), pll(row, LLONG_MAX));
if(it == pts[col].begin()) return 0;
return (--it)->second;
}
ll f1[100005], f2[100005];
map<int, ll> DP[100005];
vector<int> used;
void upd(ll*fwk, int idx, ll val) {
for(;idx<=100000;idx+=idx&-idx) {
fwk[idx] = max(fwk[idx], val);
used.push_back(idx);
}
}
ll qr(ll* fwk, int idx) {
ll cmax = 0;
for(;idx;idx-=idx&-idx)
cmax = max(cmax, fwk[idx]);
return cmax;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
n = N; m = M;
for(int i=0;i<X.size();i++) {
pts[X[i]].emplace_back(Y[i], i);
if(X[i] != 0) dppoints[X[i]-1].push_back(Y[i]);
if(X[i] != N-1)dppoints[X[i]+1].push_back(Y[i]);
}
for(int i=0;i<N;i++) {
if(pts[i].empty()) continue;
sort(pts[i].begin(), pts[i].end());
pts[i][0].second = W[pts[i][0].second];
for(int j=1;j<pts[i].size();j++) {
pts[i][j].second = pts[i][j-1].second + W[pts[i][j].second];
}
}
long long best = 0, cur_im1y = 0;
for(int col=0;col<N;col++) {
for(int row:dppoints[col]) {
ll Wij = getsum(col, row), Wipj=getsum(col+1,row), Wimj=getsum(col-1,row);
DP[col][row] = cur_im1y + Wipj + Wimj;
if(col != 0) {
//max{k <= j}(DP[i-1][k]) - sum{m<=k}(w[i][m])
//max{k > j}(DP[i-1][k]) - sum{m<=j}(w[i][m])
long long cbest = max(qr(f1, row+1), qr(f2, n-row) - Wij);
//cout << qr(f1, row+1) << ' ' << qr(f2, n-row) << '\n';
DP[col][row] = max(cbest+Wipj, DP[col][row]);
}
best = max(best, DP[col][row]);
}
if(col!=0) {
for(int e:used)
f1[e] = f2[e] = 0;
used.clear();
}
if(col > 1)
for(int row:dppoints[col-2])
cur_im1y = max(cur_im1y, DP[col-2][row]);
//cout << "-----\n" << col << '\n';
for(int row:dppoints[col]) {
//cout << row << ": " << DP[col][row] << ' ';
//cout << '\n';
upd(f1, row+1, DP[col][row] - getsum(col+1, row));
upd(f2, n-row, DP[col][row]);
} //buildfwk
}
return best;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<X.size();i++) {
| ~^~~~~~~~~
fish.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j=1;j<pts[i].size();j++) {
| ~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
29316 KB |
Output is correct |
2 |
Correct |
184 ms |
31800 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Execution timed out |
1008 ms |
73380 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9708 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
61 ms |
19024 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20883902549126' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9708 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
61 ms |
19024 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '20883902549126' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
29316 KB |
Output is correct |
2 |
Correct |
184 ms |
31800 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
5 ms |
9684 KB |
Output is correct |
5 |
Execution timed out |
1008 ms |
73380 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |