답안 #834396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834396 2023-08-22T13:58:31 Z Rafi22 메기 농장 (IOI22_fish) C++17
81 / 100
1000 ms 141296 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;


vector<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]].pb(Y[i]-1);
		S[X[i]-1].pb(Y[i]);
		S[X[i]+1].pb(Y[i]);
		V[X[i]].pb({Y[i],W[i]});
	}
	for(int i=1;i<=n;i++)
	{
		S[i].pb(0);
		sort(all(S[i]));
		for(int j=0;j<sz(S[i]);j++) if(j==0||S[i][j]!=S[i][j-1]) points[i].pb(S[i][j]);
		sort(all(V[i]));
		for(auto x:S[i]) points[i].pb(x);
		DP[0][i].resize(sz(points[i]),0);
		DP[1][i].resize(sz(points[i]),0);
		L[i].resize(sz(points[i]),0);
		R[i].resize(sz(points[i]),0);
		M[i].resize(sz(points[i]),0);
	}
	for(int i=1;i<=n;i++)
	{
		vector<pair<pair<int,int>,int>>P;
		for(auto [y,c]:V[i-1]) P.pb({{y,-c},1});
		for(auto [y,c]:V[i]) P.pb({{y,-c},2});
		for(auto [y,c]:V[i+1]) P.pb({{y,-c},3});
		for(int j=0;j<sz(points[i]);j++) P.pb({{points[i][j],j},0});
		sort(all(P));
		ll sum1=0,sum2=0,sum3=0;
		for(auto [y,c]:P)
		{
			if(c==0) 
			{
				L[i][y.nd]=sum1;
				M[i][y.nd]=sum2;
				R[i][y.nd]=sum3;
			}
			else if(c==1) sum1+=(ll)-y.nd;
			else if(c==2) sum2+=(ll)-y.nd;
			else sum3+=(ll)-y.nd;
		}
	}
	for(int i=0;i<sz(points[1]);i++) DP[1][1][i]=-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(int j=0;j<sz(points[i]);j++) P.pb({points[i][j],j});
		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()
{
	int n=100000,m=100000;
	//cin>>n>>m;
	vector<int>X(m),Y(m),C(m);
	for(int i=0;i<m;i++)
	{
		//cin>>X[i]>>Y[i]>>C[i];
		X[i]=rand()%n;
		Y[i]=rand()%n;
		C[i]=rand()%1000000+1;
	}
	cout<<max_weights(n,m,X,Y,C)<<endl;
	return 0;
}*/
    

# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 62840 KB Output is correct
2 Correct 314 ms 72184 KB Output is correct
3 Correct 82 ms 40984 KB Output is correct
4 Correct 74 ms 40984 KB Output is correct
5 Execution timed out 1078 ms 141296 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 412 ms 85352 KB Output is correct
3 Correct 543 ms 97220 KB Output is correct
4 Correct 236 ms 62864 KB Output is correct
5 Correct 287 ms 72252 KB Output is correct
6 Correct 10 ms 18964 KB Output is correct
7 Correct 12 ms 19036 KB Output is correct
8 Correct 10 ms 19028 KB Output is correct
9 Correct 11 ms 19068 KB Output is correct
10 Correct 71 ms 40948 KB Output is correct
11 Correct 73 ms 40944 KB Output is correct
12 Correct 293 ms 69912 KB Output is correct
13 Correct 382 ms 80968 KB Output is correct
14 Correct 322 ms 66660 KB Output is correct
15 Correct 266 ms 67232 KB Output is correct
16 Correct 261 ms 66512 KB Output is correct
17 Correct 302 ms 73764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 40928 KB Output is correct
2 Correct 77 ms 41012 KB Output is correct
3 Correct 173 ms 50696 KB Output is correct
4 Correct 128 ms 48972 KB Output is correct
5 Correct 216 ms 63592 KB Output is correct
6 Correct 203 ms 63644 KB Output is correct
7 Correct 204 ms 63700 KB Output is correct
8 Correct 213 ms 63716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19076 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 9 ms 19024 KB Output is correct
4 Correct 10 ms 19028 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 11 ms 19096 KB Output is correct
8 Correct 12 ms 19028 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 12 ms 19684 KB Output is correct
11 Correct 13 ms 19332 KB Output is correct
12 Correct 11 ms 19468 KB Output is correct
13 Correct 11 ms 19120 KB Output is correct
14 Correct 13 ms 19284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19076 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 9 ms 19024 KB Output is correct
4 Correct 10 ms 19028 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 11 ms 19096 KB Output is correct
8 Correct 12 ms 19028 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 12 ms 19684 KB Output is correct
11 Correct 13 ms 19332 KB Output is correct
12 Correct 11 ms 19468 KB Output is correct
13 Correct 11 ms 19120 KB Output is correct
14 Correct 13 ms 19284 KB Output is correct
15 Correct 11 ms 19156 KB Output is correct
16 Correct 14 ms 19668 KB Output is correct
17 Correct 93 ms 30276 KB Output is correct
18 Correct 96 ms 30320 KB Output is correct
19 Correct 102 ms 30116 KB Output is correct
20 Correct 97 ms 29868 KB Output is correct
21 Correct 76 ms 29824 KB Output is correct
22 Correct 160 ms 40524 KB Output is correct
23 Correct 29 ms 21972 KB Output is correct
24 Correct 83 ms 27788 KB Output is correct
25 Correct 11 ms 19412 KB Output is correct
26 Correct 28 ms 21720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19076 KB Output is correct
2 Correct 9 ms 19028 KB Output is correct
3 Correct 9 ms 19024 KB Output is correct
4 Correct 10 ms 19028 KB Output is correct
5 Correct 9 ms 19028 KB Output is correct
6 Correct 9 ms 19028 KB Output is correct
7 Correct 11 ms 19096 KB Output is correct
8 Correct 12 ms 19028 KB Output is correct
9 Correct 9 ms 19156 KB Output is correct
10 Correct 12 ms 19684 KB Output is correct
11 Correct 13 ms 19332 KB Output is correct
12 Correct 11 ms 19468 KB Output is correct
13 Correct 11 ms 19120 KB Output is correct
14 Correct 13 ms 19284 KB Output is correct
15 Correct 11 ms 19156 KB Output is correct
16 Correct 14 ms 19668 KB Output is correct
17 Correct 93 ms 30276 KB Output is correct
18 Correct 96 ms 30320 KB Output is correct
19 Correct 102 ms 30116 KB Output is correct
20 Correct 97 ms 29868 KB Output is correct
21 Correct 76 ms 29824 KB Output is correct
22 Correct 160 ms 40524 KB Output is correct
23 Correct 29 ms 21972 KB Output is correct
24 Correct 83 ms 27788 KB Output is correct
25 Correct 11 ms 19412 KB Output is correct
26 Correct 28 ms 21720 KB Output is correct
27 Correct 15 ms 20412 KB Output is correct
28 Correct 422 ms 71680 KB Output is correct
29 Correct 727 ms 95520 KB Output is correct
30 Correct 688 ms 117348 KB Output is correct
31 Correct 707 ms 117000 KB Output is correct
32 Correct 585 ms 89572 KB Output is correct
33 Correct 723 ms 118236 KB Output is correct
34 Correct 736 ms 118232 KB Output is correct
35 Correct 256 ms 52832 KB Output is correct
36 Correct 723 ms 108768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 40928 KB Output is correct
2 Correct 77 ms 41012 KB Output is correct
3 Correct 173 ms 50696 KB Output is correct
4 Correct 128 ms 48972 KB Output is correct
5 Correct 216 ms 63592 KB Output is correct
6 Correct 203 ms 63644 KB Output is correct
7 Correct 204 ms 63700 KB Output is correct
8 Correct 213 ms 63716 KB Output is correct
9 Correct 207 ms 63680 KB Output is correct
10 Correct 173 ms 53248 KB Output is correct
11 Correct 307 ms 87552 KB Output is correct
12 Correct 11 ms 19028 KB Output is correct
13 Correct 10 ms 19028 KB Output is correct
14 Correct 10 ms 19028 KB Output is correct
15 Correct 10 ms 19028 KB Output is correct
16 Correct 10 ms 19028 KB Output is correct
17 Correct 9 ms 19092 KB Output is correct
18 Correct 75 ms 41000 KB Output is correct
19 Correct 81 ms 40916 KB Output is correct
20 Correct 69 ms 40996 KB Output is correct
21 Correct 77 ms 40988 KB Output is correct
22 Correct 327 ms 71920 KB Output is correct
23 Correct 474 ms 93304 KB Output is correct
24 Correct 429 ms 94416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 222 ms 62840 KB Output is correct
2 Correct 314 ms 72184 KB Output is correct
3 Correct 82 ms 40984 KB Output is correct
4 Correct 74 ms 40984 KB Output is correct
5 Execution timed out 1078 ms 141296 KB Time limit exceeded
6 Halted 0 ms 0 KB -