Submission #832918

# Submission time Handle Problem Language Result Execution time Memory
832918 2023-08-21T16:42:13 Z Rafi22 Catfish Farm (IOI22_fish) C++17
9 / 100
443 ms 159072 KB
#include <bits/stdc++.h>
     
using namespace std;
     
#define ll long long 
#define ld long double
#define pb push_back
#define st first
#define nd second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
int inf=1000000007;
ll infl=1000000000000000007;

const int N=100007;

set<int>S[N];
vector<int>points[N];

vector<ll>DP[2][N];
vector<ll>L[N];
vector<ll>R[N];
vector<ll>M[N];


vector<pair<int,int>>V[N];
     
ll max_weights(int n,int m,vector<int>X,vector<int>Y,vector<int>W)
{
	for(int i=0;i<m;i++)
	{
		X[i]++;
		Y[i]++;
		S[X[i]].insert(Y[i]-1);
		S[X[i]-1].insert(Y[i]);
		S[X[i]+1].insert(Y[i]);
		V[X[i]].pb({Y[i],W[i]});
	}
	for(int i=1;i<=n;i++)
	{
		S[i].insert(0);
		sort(all(V[i]));
		for(auto x:S[i]) points[i].pb(x);
		DP[0][i].resize(sz(points[i]));
		DP[1][i].resize(sz(points[i]));
		L[i].resize(sz(points[i]));
		R[i].resize(sz(points[i]));
		M[i].resize(sz(points[i]));
	}
	for(int i=1;i<=n;i++)
	{
		vector<pair<int,ll>>P;
		for(auto [y,c]:V[i-1]) P.pb({y,-c});
		for(int j=0;j<sz(points[i]);j++) P.pb({points[i][j],j});
		sort(all(P));
		ll sum=0;
		for(auto [y,c]:P)
		{
			if(c>=0) L[i][c]=sum;
			else sum+=-c;
		}
		P.clear();
		for(auto [y,c]:V[i+1]) P.pb({y,-c});
		for(int j=0;j<sz(points[i]);j++) P.pb({points[i][j],j});
		sort(all(P));
		sum=0;
		for(auto [y,c]:P)
		{
			if(c>=0) R[i][c]=sum;
			else sum+=-c;
		}
		P.clear();
		for(auto [y,c]:V[i]) P.pb({y,-c});
		for(int j=0;j<sz(points[i]);j++) P.pb({points[i][j],j});
		sort(all(P));
		sum=0;
		for(auto [y,c]:P)
		{
			if(c>=0) M[i][c]=sum;
			else sum+=-c;
		}
	}
	for(auto x:points[1]) DP[1][1][x]=-infl;
	ll ans=0;
	for(int i=2;i<=n;i++)
	{
		vector<pair<int,int>>P;
		for(int j=0;j<sz(points[i-2]);j++) P.pb({points[i-2][j],-j-1});
		//for(auto y:points[i-2]) P.pb({y,0});
		for(int j=0;j<sz(points[i]);j++) P.pb({points[i][j],j});
		//for(auto y:points[i]) P.pb({y,1});
		sort(all(P));
		ll mx=0;
		for(auto [y,c]:P)
		{
			if(c<0) mx=max({mx,DP[0][i-2][-c-1],DP[1][i-2][-c-1]});
			else DP[0][i][c]=max(DP[0][i][c],mx+L[i][c]);
		}
		reverse(all(P));
		mx=0;
		for(auto [y,c]:P)
		{
			if(c<0) mx=max(mx,max(DP[0][i-2][-c-1],DP[1][i-2][-c-1])+R[i-2][-c-1]);
			else DP[0][i][c]=max(DP[0][i][c],mx);
		}
		P.clear();
		for(int j=0;j<sz(points[i-1]);j++) P.pb({points[i-1][j],-j-1});
		//for(auto y:points[i-1]) P.pb({y,0});
		for(int j=0;j<sz(points[i]);j++) P.pb({points[i][j],j});
		//for(auto y:points[i]) P.pb({y,1});
		sort(all(P));
		mx=0;
		for(auto [y,c]:P)
		{
			if(c<0) mx=max(mx,DP[0][i-1][-c-1]-M[i-1][-c-1]);
			else DP[0][i][c]=max(DP[0][i][c],mx+L[i][c]);
		}
		reverse(all(P));
		mx=0;
		for(auto [y,c]:P)
		{
			if(c<0) mx=max(mx,max(DP[0][i-1][-c-1],DP[1][i-1][-c-1])+R[i-1][-c-1]);
			else DP[1][i][c]=max(DP[1][i][c],mx-M[i][c]);
		}
		for(int j=0;j<sz(points[i]);j++) ans=max({ans,DP[0][i][j],DP[1][i][j]});
	}
	return ans;
}
   /*
int main()
{
	cout<<max_weights(5, 4,{0, 1, 4, 3},{2, 1, 4, 3},{5, 2, 1, 3})<<endl;
	return 0;
}*/
    

# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 131264 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21428 KB Output is correct
2 Runtime error 443 ms 150812 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 44864 KB Output is correct
2 Correct 58 ms 44876 KB Output is correct
3 Correct 109 ms 48200 KB Output is correct
4 Correct 96 ms 48736 KB Output is correct
5 Correct 167 ms 55096 KB Output is correct
6 Correct 166 ms 55048 KB Output is correct
7 Correct 199 ms 54992 KB Output is correct
8 Correct 166 ms 54980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21332 KB Output is correct
2 Correct 11 ms 21348 KB Output is correct
3 Correct 10 ms 21380 KB Output is correct
4 Correct 11 ms 21392 KB Output is correct
5 Correct 11 ms 21332 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 10 ms 21340 KB Output is correct
8 Correct 10 ms 21332 KB Output is correct
9 Correct 11 ms 21460 KB Output is correct
10 Correct 12 ms 21716 KB Output is correct
11 Runtime error 27 ms 43608 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21332 KB Output is correct
2 Correct 11 ms 21348 KB Output is correct
3 Correct 10 ms 21380 KB Output is correct
4 Correct 11 ms 21392 KB Output is correct
5 Correct 11 ms 21332 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 10 ms 21340 KB Output is correct
8 Correct 10 ms 21332 KB Output is correct
9 Correct 11 ms 21460 KB Output is correct
10 Correct 12 ms 21716 KB Output is correct
11 Runtime error 27 ms 43608 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21332 KB Output is correct
2 Correct 11 ms 21348 KB Output is correct
3 Correct 10 ms 21380 KB Output is correct
4 Correct 11 ms 21392 KB Output is correct
5 Correct 11 ms 21332 KB Output is correct
6 Correct 10 ms 21332 KB Output is correct
7 Correct 10 ms 21340 KB Output is correct
8 Correct 10 ms 21332 KB Output is correct
9 Correct 11 ms 21460 KB Output is correct
10 Correct 12 ms 21716 KB Output is correct
11 Runtime error 27 ms 43608 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 44864 KB Output is correct
2 Correct 58 ms 44876 KB Output is correct
3 Correct 109 ms 48200 KB Output is correct
4 Correct 96 ms 48736 KB Output is correct
5 Correct 167 ms 55096 KB Output is correct
6 Correct 166 ms 55048 KB Output is correct
7 Correct 199 ms 54992 KB Output is correct
8 Correct 166 ms 54980 KB Output is correct
9 Correct 186 ms 59788 KB Output is correct
10 Correct 130 ms 41748 KB Output is correct
11 Correct 270 ms 62148 KB Output is correct
12 Correct 11 ms 21332 KB Output is correct
13 Correct 10 ms 21332 KB Output is correct
14 Correct 10 ms 21352 KB Output is correct
15 Correct 11 ms 21356 KB Output is correct
16 Correct 11 ms 21332 KB Output is correct
17 Correct 10 ms 21396 KB Output is correct
18 Correct 59 ms 44912 KB Output is correct
19 Correct 59 ms 44800 KB Output is correct
20 Correct 59 ms 44904 KB Output is correct
21 Correct 60 ms 44892 KB Output is correct
22 Correct 265 ms 69936 KB Output is correct
23 Correct 368 ms 81276 KB Output is correct
24 Runtime error 415 ms 159072 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 131264 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -