Submission #18088

# Submission time Handle Problem Language Result Execution time Memory
18088 2016-01-20T05:10:39 Z comet 매트 (KOI15_mat) C++14
100 / 100
579 ms 155920 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;
typedef pair<int,int> pp;

struct mat{
	int l,r,h,k;
	bool operator<(const mat& z)const{
		return l!=z.l?l<z.l:r<z.r;
	}
}a[2][3010];

int N,W;
int sz[2];

int dp[3010][3010];
int opt[2][3010][3010];

priority_queue<pp,vector<pp>,greater<pp>> Qi[3010],Qj[3010];
int Maxi[3010];
int Maxj[3010];

bool cross(int x,int y){
	if(a[0][x].r<=a[1][y].l)return 0;
	if(a[0][x].l>=a[1][y].r)return 0;
	if(a[0][x].h+a[1][y].h<=W)return 0;
	return 1;
}

int main(){

	memset(Maxi,-1,sizeof(Maxi));
	memset(Maxj,-1,sizeof(Maxj));
	
	scanf("%d%d",&N,&W);

	for(int i=0;i<2;i++){
		a[i][sz[i]++]=mat{0,0,0,0};
	}

	int p,l,r,h,k;
	for(int i=0;i<N;i++){
		scanf("%d%d%d%d%d",&p,&l,&r,&h,&k);
		a[p][sz[p]++]=mat{l,r,h,k};
	}

	for(int i=0;i<2;i++){
		sort(a[i],a[i]+sz[i]);
		a[i][sz[i]]=mat{1e9,1e9,0,0};
	}

	for(int i=0;i<=sz[0];i++){
		for(int j=0;j<=sz[1];j++){

			dp[i][j]=-1e9;

			if(cross(i,j))continue;

			dp[i][j]=a[0][i].k+a[1][j].k;

			while(!Qi[j].empty()&&Qi[j].top().first<=a[0][i].l){
				int k=Qi[j].top().second;
				Qi[j].pop();
				if(Maxi[j]<0||dp[Maxi[j]][j]<dp[k][j]){
					Maxi[j]=k;
				}
			}

			while(!Qj[i].empty()&&Qj[i].top().first<=a[1][j].l){
				int k=Qj[i].top().second;
				Qj[i].pop();
				if(Maxj[i]<0||dp[i][Maxj[i]]<dp[i][k]){
					Maxj[i]=k;
				}
			}

			if(Maxi[j]>=0&&dp[i][j]<dp[Maxi[j]][j]+a[0][i].k){
				dp[i][j]=dp[Maxi[j]][j]+a[0][i].k;
				opt[0][i][j]=Maxi[j];
				opt[1][i][j]=opt[1][Maxi[j]][j];
			}

			if(Maxj[i]>=0&&dp[i][j]<dp[i][Maxj[i]]+a[1][j].k){
				dp[i][j]=dp[i][Maxj[i]]+a[1][j].k;
				opt[0][i][j]=opt[0][i][Maxj[i]];
				opt[1][i][j]=Maxj[i];
			}

			Qi[j].push(pp(max(a[0][i].r,a[1][opt[1][i][j]].r),i));
			Qj[i].push(pp(max(a[1][j].r,a[0][opt[0][i][j]].r),j));
			
		}
	}

	printf("%d\n",dp[sz[0]][sz[1]]);

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 107692 KB Output is correct
2 Correct 0 ms 107692 KB Output is correct
3 Correct 0 ms 107692 KB Output is correct
4 Correct 0 ms 107692 KB Output is correct
5 Correct 0 ms 107692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 107692 KB Output is correct
2 Correct 0 ms 107692 KB Output is correct
3 Correct 0 ms 107692 KB Output is correct
4 Correct 0 ms 107692 KB Output is correct
5 Correct 0 ms 107692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 107692 KB Output is correct
2 Correct 0 ms 107692 KB Output is correct
3 Correct 0 ms 107692 KB Output is correct
4 Correct 3 ms 107692 KB Output is correct
5 Correct 0 ms 107692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 107692 KB Output is correct
2 Correct 4 ms 107692 KB Output is correct
3 Correct 0 ms 107692 KB Output is correct
4 Correct 0 ms 107692 KB Output is correct
5 Correct 0 ms 107692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 107836 KB Output is correct
2 Correct 534 ms 131964 KB Output is correct
3 Correct 549 ms 131760 KB Output is correct
4 Correct 544 ms 132044 KB Output is correct
5 Correct 521 ms 135444 KB Output is correct
6 Correct 357 ms 133912 KB Output is correct
7 Correct 494 ms 130376 KB Output is correct
8 Correct 510 ms 130384 KB Output is correct
9 Correct 579 ms 155920 KB Output is correct
10 Correct 524 ms 130556 KB Output is correct