답안 #659488

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659488 2022-11-17T23:56:12 Z pere_gil 메기 농장 (IOI22_fish) C++17
61 / 100
1000 ms 2097152 KB
#include "fish.h"
#include "bits/stdc++.h"
using namespace std;
                 
typedef long long ll;
#define all(x) x.begin(),x.end()
     
void fill(vector<ll> &pier, vector<ll> &fish, vector<ll> &v){
	for(int i=0,j=0;i<(int)pier.size();)
		if(j==(int)fish.size()-1 || (pier[i]>=fish[j] && pier[i]<fish[j+1])){
			v[i]=j;
			i++;
		}
		else j++;
}
     
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){
	vector<ll> sum[n],fish[n],temp_pier[n],pier[n];
	vector<pair<ll,ll>> inf_fish[n];
	for(int i=0;i<m;i++) inf_fish[x[i]].push_back({y[i]+1,w[i]});
	for(int i=0;i<n;i++){
		sum[i].push_back(0); fish[i].push_back(0); temp_pier[i].push_back(0);
     
		sort(all(inf_fish[i]));
    		
		for(int j=0;j<(int)inf_fish[i].size();j++){
			fish[i].push_back(inf_fish[i][j].first);
			sum[i].push_back(inf_fish[i][j].second);
			if(i) temp_pier[i-1].push_back(inf_fish[i][j].first);
			if(i!=n-1) temp_pier[i+1].push_back(inf_fish[i][j].first);
		}
	}
	for(int i=0;i<n;i++){
     
		sort(all(temp_pier[i]));
		pier[i].push_back(temp_pier[i][0]);
		for(int j=1;j<(int)temp_pier[i].size();j++)
			if(temp_pier[i][j]!=temp_pier[i][j-1])
				pier[i].push_back(temp_pier[i][j]);
     
		for(int j=1;j<(int)fish[i].size();j++)
			sum[i][j]+=sum[i][j-1];
	}
	vector<ll> left[n],me[n],right[n];
	for(int i=0;i<n;i++){
		left[i].assign(pier[i].size(),0);
		me[i].assign(pier[i].size(),0);
		right[i].assign(pier[i].size(),0);
     
		if(i) fill(pier[i],fish[i-1],left[i]);
		fill(pier[i],fish[i],me[i]);
		if(i!=n-1) fill(pier[i],fish[i+1],right[i]);
	}
    	
	vector<vector<ll>> dec[n],inc[n];
	for(int i=0;i<n;i++){
		int j=(i) ? pier[i-1].size() : 1;
		int k=pier[i].size();
		dec[i].assign(j,vector<ll>(k,0));
		inc[i].assign(j,vector<ll>(k,0));
	}
     
	for(int i=0;i<(int)pier[0].size();i++)
		for(int j=0;j<(int)pier[1].size();j++){
			ll aux=0;
			if(pier[0][i]>=pier[1][j])
				aux+=sum[1][right[0][i]]-sum[1][me[1][j]];
			else
				aux+=sum[0][left[1][j]]-sum[0][me[0][i]];
			dec[1][i][j]=inc[1][i][j]=aux;
		}
     
	for(int i=2;i<n;i++){
		for(int j=0;j<(int)pier[i-1].size();j++){
     
			//decreasing:
			if(pier[i-1][j]){
				ll prev=0;
				for(int k=0;k<(int)pier[i-2].size();k++){
					if(pier[i-2][k]<pier[i-1][j]) continue;
					prev=max(prev,max(dec[i-1][k][j],inc[i-1][k][j]));
				}
				for(int k=0;k<(int)pier[i].size();k++){
					if(pier[i][k]>pier[i-1][j]) break;
					dec[i][j][k]+=prev;
					dec[i][j][k]+=sum[i][right[i-1][j]]-sum[i][me[i][k]];
				}
			}
			else{
				ll prev=0;
				int pos=0;
				for(int k=0;k<(int)pier[i-2].size();k++){
					ll aux=max(dec[i-1][k][j],inc[i-1][k][j]);
					if(aux>=prev){
						prev=aux;
						pos=k;
					}
				}
				for(int k=0;k<(int)pier[i].size();k++){
					dec[i][j][k]+=prev;
					if(pier[i][k]<pier[i-2][pos]) continue;
					dec[i][j][k]+=sum[i-1][left[i][k]]-sum[i-1][right[i-2][pos]];
				}
			}
     
			//increasing:
			ll prev=0;
			for(int k=0;k<(int)pier[i-2].size();k++){
				if(pier[i-2][k]>pier[i-1][j]) break;
				prev=max(prev,inc[i-1][k][j]);
				if(!pier[i-2][k]) prev=max(prev,dec[i-1][k][j]);
			}
			for(int k=0;k<(int)pier[i].size();k++){
				inc[i][j][k]+=prev;
				if(pier[i-1][j]>=pier[i][k])
					inc[i][j][k]+=sum[i][right[i-1][j]]-sum[i][me[i][k]];
				else
					inc[i][j][k]+=sum[i-1][left[i][k]]-sum[i-1][me[i-1][j]];
			}
		}
	}
     
	ll res=0;
	for(int i=0;i<(int)pier[n-2].size();i++)
		for(int j=0;j<(int)pier[n-1].size();j++)
			res=max({res,dec[n-1][i][j],inc[n-1][i][j]});
    	
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 70468 KB Output is correct
2 Correct 154 ms 80312 KB Output is correct
3 Correct 96 ms 58144 KB Output is correct
4 Correct 90 ms 58112 KB Output is correct
5 Correct 329 ms 174776 KB Output is correct
6 Correct 493 ms 177120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1155 ms 1408404 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 58188 KB Output is correct
2 Correct 95 ms 58288 KB Output is correct
3 Correct 126 ms 63560 KB Output is correct
4 Correct 128 ms 66360 KB Output is correct
5 Correct 184 ms 78556 KB Output is correct
6 Correct 180 ms 78520 KB Output is correct
7 Correct 177 ms 78484 KB Output is correct
8 Correct 183 ms 78564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 1236 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 2 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 1236 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 2 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 4 ms 3768 KB Output is correct
17 Correct 272 ms 259196 KB Output is correct
18 Correct 247 ms 243380 KB Output is correct
19 Correct 170 ms 169308 KB Output is correct
20 Correct 134 ms 122540 KB Output is correct
21 Correct 147 ms 117072 KB Output is correct
22 Correct 448 ms 443684 KB Output is correct
23 Correct 24 ms 18900 KB Output is correct
24 Correct 168 ms 139620 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 20 ms 15164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 1236 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 2 ms 980 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 4 ms 3768 KB Output is correct
17 Correct 272 ms 259196 KB Output is correct
18 Correct 247 ms 243380 KB Output is correct
19 Correct 170 ms 169308 KB Output is correct
20 Correct 134 ms 122540 KB Output is correct
21 Correct 147 ms 117072 KB Output is correct
22 Correct 448 ms 443684 KB Output is correct
23 Correct 24 ms 18900 KB Output is correct
24 Correct 168 ms 139620 KB Output is correct
25 Correct 2 ms 980 KB Output is correct
26 Correct 20 ms 15164 KB Output is correct
27 Correct 6 ms 2900 KB Output is correct
28 Execution timed out 1054 ms 2097152 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 58188 KB Output is correct
2 Correct 95 ms 58288 KB Output is correct
3 Correct 126 ms 63560 KB Output is correct
4 Correct 128 ms 66360 KB Output is correct
5 Correct 184 ms 78556 KB Output is correct
6 Correct 180 ms 78520 KB Output is correct
7 Correct 177 ms 78484 KB Output is correct
8 Correct 183 ms 78564 KB Output is correct
9 Correct 213 ms 88680 KB Output is correct
10 Correct 131 ms 49736 KB Output is correct
11 Correct 282 ms 99136 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 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 90 ms 58100 KB Output is correct
19 Correct 86 ms 58196 KB Output is correct
20 Correct 83 ms 58144 KB Output is correct
21 Correct 86 ms 58204 KB Output is correct
22 Correct 268 ms 94140 KB Output is correct
23 Correct 360 ms 133340 KB Output is correct
24 Correct 380 ms 141012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 70468 KB Output is correct
2 Correct 154 ms 80312 KB Output is correct
3 Correct 96 ms 58144 KB Output is correct
4 Correct 90 ms 58112 KB Output is correct
5 Correct 329 ms 174776 KB Output is correct
6 Correct 493 ms 177120 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Execution timed out 1155 ms 1408404 KB Time limit exceeded
9 Halted 0 ms 0 KB -