# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
626478 | 2022-08-11T13:22:33 Z | Antekb | Catfish Farm (IOI22_fish) | C++17 | 157 ms | 32304 KB |
#include "fish.h" #include <bits/stdc++.h> #define pb push_back #define st first #define nd second using namespace std; using ll = long long; const int INF=1e9+6; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { /*n=1e5; m=1e5; X.resize(m); Y.resize(m); W.resize(m); for(int i=0; i<m; i++){ X[i]=(rng()%(n/2))*2+2; Y[i]=rng()%n; W[i]=rng(); }*/ for(auto &i:X)i++; ll ans=0; for(int i:W)ans+=i; //return ans; vector<pair<int, int> > V[n+2]; vector<ll> dp[n+2][2]; ll dp2[n+2][2]; for(int i=0; i<=n+1; i++)dp2[i][0]=dp2[i][1]=0; for(int i=0; i<m; i++){ V[X[i]].pb({Y[i], W[i]}); } for(int i=0; i<=n+1; i++){ V[i].pb({n, INF}); sort(V[i].begin(), V[i].end()); dp[i][0].resize(V[i].size()); dp[i][1].resize(V[i].size()); } dp[0][1][0]=dp[0][0][0]=-1e18; for(int i=1; i<=n+1; i++){ ll s=0; int wsk=0; for(int j=0; j<V[i-1].size(); j++){ dp[i-1][0][j]-=s; s+=V[i-1][j].nd; } ll m=dp2[i-1][0]; dp2[i][0]=max(dp2[i-1][0], dp2[i-1][1]); s=0; for(int j=0; j<V[i].size(); j++){ while(wsk<V[i-1].size() && V[i][j].st>V[i-1][wsk].st){ m=max(m, dp[i-1][0][wsk]); s+=V[i-1][wsk].nd; wsk++; } dp[i][0][j]=s+m; } wsk=V[i-1].size()-1; m=dp[i-1][1][wsk]; for(int j=V[i].size()-2; j>=0; j--){ while(wsk!=0 && V[i-1][wsk-1].st>=V[i][j].st){ m=max(m, dp[i-1][1][wsk-1]); wsk--; } dp[i][1][j]=m; m+=V[i][j].nd; } for(int j=0; j<V[i-1].size(); j++)dp2[i][0]=max(dp2[i][0], dp[i-1][1][j]); dp2[i][1]=max(m, dp2[i][0]); for(int j=0; j<V[i].size(); j++){ dp[i][0][j]=max(dp[i][0][j], dp2[i-1][1]); } for(int j=0; j<V[i].size(); j++){ dp[i][1][j]=max(dp[i][0][j], dp[i][1][j]); } //cout<<i<<"\n"; //cout<<dp2[i][0]<<" "<<dp2[i][1]<<" a\n"; for(int j=0; j<V[i].size(); j++){ //cout<<dp[i][0][j]<<" "<<dp[i][1][j]<<" b\n"; } } //assert(dp2[n+1][0]==ans); return dp2[n+1][0]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 65 ms | 20288 KB | Output is correct |
2 | Correct | 60 ms | 22908 KB | Output is correct |
3 | Correct | 25 ms | 18256 KB | Output is correct |
4 | Correct | 26 ms | 18284 KB | Output is correct |
5 | Correct | 138 ms | 32304 KB | Output is correct |
6 | Correct | 157 ms | 31796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 85 ms | 24048 KB | Output is correct |
3 | Correct | 113 ms | 27716 KB | Output is correct |
4 | Correct | 51 ms | 20184 KB | Output is correct |
5 | Correct | 62 ms | 22940 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 26 ms | 18260 KB | Output is correct |
11 | Correct | 26 ms | 18224 KB | Output is correct |
12 | Correct | 60 ms | 20328 KB | Output is correct |
13 | Correct | 60 ms | 22972 KB | Output is correct |
14 | Correct | 51 ms | 20276 KB | Output is correct |
15 | Correct | 58 ms | 22480 KB | Output is correct |
16 | Correct | 51 ms | 20324 KB | Output is correct |
17 | Correct | 56 ms | 22500 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 18308 KB | Output is correct |
2 | Correct | 27 ms | 18260 KB | Output is correct |
3 | Incorrect | 50 ms | 17832 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361' |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Incorrect | 0 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 | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Incorrect | 0 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 | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Incorrect | 0 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 | 24 ms | 18308 KB | Output is correct |
2 | Correct | 27 ms | 18260 KB | Output is correct |
3 | Incorrect | 50 ms | 17832 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361' |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 65 ms | 20288 KB | Output is correct |
2 | Correct | 60 ms | 22908 KB | Output is correct |
3 | Correct | 25 ms | 18256 KB | Output is correct |
4 | Correct | 26 ms | 18284 KB | Output is correct |
5 | Correct | 138 ms | 32304 KB | Output is correct |
6 | Correct | 157 ms | 31796 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 85 ms | 24048 KB | Output is correct |
9 | Correct | 113 ms | 27716 KB | Output is correct |
10 | Correct | 51 ms | 20184 KB | Output is correct |
11 | Correct | 62 ms | 22940 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 26 ms | 18260 KB | Output is correct |
17 | Correct | 26 ms | 18224 KB | Output is correct |
18 | Correct | 60 ms | 20328 KB | Output is correct |
19 | Correct | 60 ms | 22972 KB | Output is correct |
20 | Correct | 51 ms | 20276 KB | Output is correct |
21 | Correct | 58 ms | 22480 KB | Output is correct |
22 | Correct | 51 ms | 20324 KB | Output is correct |
23 | Correct | 56 ms | 22500 KB | Output is correct |
24 | Correct | 24 ms | 18308 KB | Output is correct |
25 | Correct | 27 ms | 18260 KB | Output is correct |
26 | Incorrect | 50 ms | 17832 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361' |
27 | Halted | 0 ms | 0 KB | - |