# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
950844 |
2024-03-20T19:28:49 Z |
sysia |
Catfish Farm (IOI22_fish) |
C++17 |
|
148 ms |
32224 KB |
//Sylwia Sapkowska
#include <bits/stdc++.h>
#include "fish.h"
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
typedef pair<int, int> T;
const ll oo = 1e18;
void ckmax(ll &a, ll b){
a = max(a, b);
}
ll max_weights(int n, int m, vector<int>x, vector<int>y, vector<int>w){
vector<vector<T>>where(n+2);
vector<vector<int>>valid(n+1), pref(n+1);
for (int i = 0; i<m; i++){
where[x[i]+1].emplace_back(y[i]+1, w[i]);
}
valid[0].emplace_back(0);
where[0].emplace_back(0, 0);
pref[0].emplace_back(0);
for (int i = 1; i<=n; i++){
valid[i].emplace_back(0);
for (auto [j, val]: where[i]) valid[i].emplace_back(j-1);
for (auto [j, val]: where[i-1]) valid[i].emplace_back(j);
for (auto [j, val]: where[i+1]) valid[i].emplace_back(j);
sort(valid[i].begin(), valid[i].end());
where[i].emplace_back(0, 0);
sort(where[i].begin(), where[i].end());
pref[i].resize((int)where[i].size());
for (int j = 1; j<(int)where[i].size(); j++) pref[i][j] = pref[i][j-1] + where[i][j].second;
valid[i].erase(unique(valid[i].begin(), valid[i].end()), valid[i].end());
debug(i, where[i], pref[i], valid[i]);
}
vector dp(1, vector<ll>(3, -oo));
dp[0][0] = 0;
dp[0][1] = 0;
auto less = [&](int i, int h){//ostatni <= h w where[i]
int l = 0, r = (int)where[i].size()-1;
int ans = 0;
while (r >= l){
int m = (l+r)/2;
if (where[i][m].first <= h){
ans = m;
l = m+1;
} else r = m-1;
}
return ans;
};
for (int i = 1; i<=n; i++){
int s = (int)valid[i].size();
int t = (int)valid[i-1].size();
vector new_dp(s, vector<ll>(3, -oo));
debug(i);
//h = 0
//1) poprzednia miala dodatnie pole
for (int j = 1; j<t; j++){
int h = valid[i-1][j];
ckmax(new_dp[0][2], max(dp[j][1], dp[j][0]) + pref[i][less(i, h)]); //<= h
}
//2) poprzednia byla zerem
new_dp[0][0] = max(dp[0][2], dp[0][0]);
//h > 0
//1) poprzednia byla pusta
for (int j = 1; j<s; j++){
int h = valid[i][j];
new_dp[j][0] = new_dp[j][1] = max(dp[0][2], dp[0][0] + pref[i-1][less(i-1, h)]);
}
//2) poprzednia cos miala miau
ll mx = -oo;
int ptr = -1;
for (int j = 1; j<s; j++){
int h = valid[i][j];
while (ptr + 1 < (int)valid[i-1].size() && valid[i-1][ptr+1] <= h){
ptr++;
mx = max(mx, dp[ptr][0] - pref[i-1][less(i-1, valid[i-1][ptr])]);
}
int tt = less(i-1, h);
ckmax(new_dp[j][0], mx+pref[i-1][tt]);
ckmax(new_dp[j][1], mx+pref[i-1][tt]);
}
mx = -oo; ptr = t;
for (int j = s-1; j>=1; j--){
int h = valid[i][j];
while (ptr >= 1 && valid[i-1][ptr-1] >= h){
ptr--;
mx = max(mx, dp[ptr][1] + pref[i][less(i, valid[i-1][ptr])]);
}
ckmax(new_dp[j][1], mx-pref[i][less(i, h)]);
}
for (int j = 0; j<s; j++){
int h = valid[i][j];
debug(h, new_dp[j]);
}
swap(dp, new_dp);
}
debug(dp);
ll ans = 0;
for (int j = 0; j<(int)dp.size(); j++){
for (int rep = 0; rep < 3; rep++){
ans = max(ans, dp[j][rep]);
}
}
return ans;
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:115:17: warning: unused variable 'h' [-Wunused-variable]
115 | int h = valid[i][j];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
27548 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '4294861544' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
148 ms |
32224 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '8579116350' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
16888 KB |
Output is correct |
2 |
Correct |
26 ms |
16732 KB |
Output is correct |
3 |
Correct |
45 ms |
16980 KB |
Output is correct |
4 |
Correct |
44 ms |
18768 KB |
Output is correct |
5 |
Correct |
71 ms |
22332 KB |
Output is correct |
6 |
Correct |
64 ms |
21692 KB |
Output is correct |
7 |
Correct |
78 ms |
22320 KB |
Output is correct |
8 |
Correct |
66 ms |
22100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 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 |
344 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '165904432401' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 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 |
344 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '165904432401' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 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 |
344 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '165904432401' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
16888 KB |
Output is correct |
2 |
Correct |
26 ms |
16732 KB |
Output is correct |
3 |
Correct |
45 ms |
16980 KB |
Output is correct |
4 |
Correct |
44 ms |
18768 KB |
Output is correct |
5 |
Correct |
71 ms |
22332 KB |
Output is correct |
6 |
Correct |
64 ms |
21692 KB |
Output is correct |
7 |
Correct |
78 ms |
22320 KB |
Output is correct |
8 |
Correct |
66 ms |
22100 KB |
Output is correct |
9 |
Correct |
71 ms |
22120 KB |
Output is correct |
10 |
Correct |
49 ms |
14160 KB |
Output is correct |
11 |
Correct |
99 ms |
28112 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
34 ms |
16872 KB |
Output is correct |
19 |
Correct |
27 ms |
16732 KB |
Output is correct |
20 |
Correct |
26 ms |
16732 KB |
Output is correct |
21 |
Correct |
26 ms |
16732 KB |
Output is correct |
22 |
Correct |
88 ms |
22608 KB |
Output is correct |
23 |
Correct |
120 ms |
28116 KB |
Output is correct |
24 |
Correct |
112 ms |
28492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
27548 KB |
1st lines differ - on the 1st token, expected: '40313272768926', found: '4294861544' |
2 |
Halted |
0 ms |
0 KB |
- |