Submission #1077232

# Submission time Handle Problem Language Result Execution time Memory
1077232 2024-08-27T03:39:14 Z pcc Catfish Farm (IOI22_fish) C++17
35 / 100
104 ms 13872 KB
#include "fish.h"

#include <vector>
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fs first
#define sc second
#define tiii tuple<int,int,int>
#define tlll tuple<ll,ll,ll>

const ll inf = 1e18;
const int mxn = 330;
vector<pii> fish[mxn];
vector<pll> dp[mxn][2];
ll big = 0;

ll f(int idx,int s,int e){
	ll re = 0;
	for(auto &[pos,w]:fish[idx]){
		if(pos>s&&pos<=e)re += w;
	}
	return re;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
	for(int i = 0;i<M;i++){
		fish[X[i]].push_back(pii(Y[i],W[i]));
	}
	for(int i = 0;i<N;i++)fish[i].push_back(pii(N,0));
	for(int i = 0;i<N;i++)sort(fish[i].begin(),fish[i].end());

	{
		vector<pii> v;
		for(auto &[pos,w]:fish[0]){
			if(pos)v.push_back(pii(pos-1,-1));
		}
		for(auto &[pos,w]:fish[1]){
			v.push_back(pii(pos,w));
			v.push_back(pii(pos,-1));
		}
		sort(v.begin(),v.end());
		ll sum = 0;
		for(auto &[a,b]:v){
			if(b == -1)dp[0][0].push_back(pll(a,sum));
			else sum += b;
		}
		sort(dp[0][0].begin(),dp[0][0].end());
		dp[0][0].resize(unique(dp[0][0].begin(),dp[0][0].end())-dp[0][0].begin());
	}

	for(int i = 1;i<N;i++){
		ll ls = 0,ms = 0,rs = 0;
		vector<tlll> v;

		//cerr<<"CALC "<<i<<":"<<endl;

		for(auto &[pos,w]:fish[i]){
			if(pos)v.push_back(tlll(pos-1,0,-1));
			v.push_back(tlll(pos,-4,w));
		}
		for(auto &[pos,w]:fish[i-1]){
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-3,w));
		}
		for(auto &[pos,w]:fish[i+1]){
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-5,w));
		}
		sort(v.begin(),v.end());v.resize(unique(v.begin(),v.end())-v.begin());
		for(auto &[pos,w]:dp[i-1][0])v.push_back(tlll(pos,-2,w));//tp == -2:trans
		if(i-2>=0){
			for(int j = 0;j<2;j++)for(auto &[pos,w]:dp[i-2][j])v.push_back(tlll(pos,-1,w));
		}
		sort(v.begin(),v.end());
		ll mx1 = -inf,mx2 = -inf;
		for(auto &[pos,tp,val]:v){
			//cerr<<"["<<pos<<','<<tp<<','<<val<<','<<ls<<' '<<ms<<' '<<rs<<"]"<<endl;
			if(tp == -5)rs+=val;
			else if(tp == -4)ms+=val;
			else if(tp == -3)ls+=val;
			else if(tp == -2)mx1 = max(mx1,val-ms-ls);
			else if(tp == -1)mx2 = max(mx2,val-ls);
			else{
				val = max({big+ls+rs,mx1+ls+rs,mx2+ls+rs});
			}
		}
		//cerr<<endl;
		mx1 = 0;
		reverse(v.begin(),v.end());
		for(auto &[pos,tp,val]:v){
			if(tp == -5)rs -= val;
			else if(tp == -1){
				mx1 = max(mx1,val);
			}
			else if(tp == 0){
				val = max(val,rs+mx1);
				dp[i][0].push_back(pll(pos,val));
			}
		}

		ls = rs = ms;
		mx1 = mx2 = -inf;
		v.clear();

		for(auto &[pos,w]:fish[i]){
			if(pos)v.push_back(tlll(pos-1,0,-1));
			ms += w;
			v.push_back(tlll(pos,-4,w));
		}
		for(auto &[pos,w]:fish[i-1]){
			ls += w;
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-3,w));
		}
		for(auto &[pos,w]:fish[i+1]){
			rs += w;
			v.push_back(tlll(pos,0,-1));
			v.push_back(tlll(pos,-5,w));
		}
		sort(v.begin(),v.end());v.resize(unique(v.begin(),v.end())-v.begin());
		for(auto &[pos,w]:dp[i-1][0])v.push_back(tlll(pos,2,w));//tp == 2:trans
		for(auto &[pos,w]:dp[i-1][1])v.push_back(tlll(pos,2,w));//tp == 2:trans
		sort(v.rbegin(),v.rend());
		mx1 = -inf,mx2 = -inf;
		for(auto &[pos,tp,val]:v){
			if(tp == -5)rs-=val;
			else if(tp == -4)ms-=val;
			else if(tp == -3)ls-=val;
			else if(tp == 2)mx1 = max(mx1,val);
			else{
				val = mx1-ms+rs;
				dp[i][1].push_back(pll(pos,val));
			}
		}

		if(i-2>=0){
			for(int j = 0;j<2;j++)for(auto &[a,b]:dp[i-2][j])big = max(big,b);
		}

	}
	ll ans = 0;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<2;j++){
			for(auto [a,b]:dp[i][j])ans = max(ans,b);
			//cerr<<i<<' '<<j<<":";for(auto [a,b]:dp[i][j])cerr<<a<<','<<b<<' ';cerr<<endl;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 7620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 45 ms 13872 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 1 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 Correct 1 ms 344 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 1 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 Correct 1 ms 344 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 67 ms 5844 KB Output is correct
18 Correct 64 ms 5716 KB Output is correct
19 Correct 53 ms 5748 KB Output is correct
20 Correct 39 ms 5456 KB Output is correct
21 Correct 40 ms 5200 KB Output is correct
22 Correct 104 ms 10236 KB Output is correct
23 Correct 18 ms 2128 KB Output is correct
24 Correct 56 ms 4292 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 21 ms 1952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 436 KB Output is correct
5 Correct 1 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 Correct 1 ms 344 KB Output is correct
10 Correct 4 ms 604 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 67 ms 5844 KB Output is correct
18 Correct 64 ms 5716 KB Output is correct
19 Correct 53 ms 5748 KB Output is correct
20 Correct 39 ms 5456 KB Output is correct
21 Correct 40 ms 5200 KB Output is correct
22 Correct 104 ms 10236 KB Output is correct
23 Correct 18 ms 2128 KB Output is correct
24 Correct 56 ms 4292 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 21 ms 1952 KB Output is correct
27 Runtime error 2 ms 600 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 19 ms 7620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -