답안 #71247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
71247 2018-08-24T08:58:58 Z khohko 매트 (KOI15_mat) C++17
0 / 100
49 ms 17484 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#define ll int
#define pb push_back
#define fr first
#define sc second
#define MAX ((ll)(1e9+100))
#define MX ((ll)(1e6+100))
#define ARRS ((ll)(2e6+100))
#define HS ((ll)(1049))
#define MOD ((ll)(1000000861))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;

string s,t;
vector<pair<pair<ll,ll> ,pair<ll,ll> > > a;
vector<pair<pair<ll,ll> ,pair<ll,ll> > > b;
ll dp[4100][4100];

struct node{
	node *L,*R;
	ll x;
	node(){
		L=R=NULL;
		x=-MAX;
	}
	void updt(){
		x=-MAX;
		if(L)x=max(x,L->x);
		if(R)x=max(x,R->x);
	}
};

ll wl,wr,wi,wx;
void updt(ll l,ll r,node *& x){
	if(wi<l||r-1<wi)return;
	if(!x)x=new node();
	if(l==r-1){
		x->x=max(x->x,wx);
		return;
	}
	updt(l,l+r>>1,x->L);
	updt(l+r>>1,r,x->R);
	x->updt();
}

ll quer(ll l,ll r,node *& x){
	if(wr<l||r-1<wl)return -MAX;
	if(!x)return -MAX;
	if(wl<=l&r-1<=wr)return x->x;
	return max(quer(l,l+r>>1,x->L),
					quer(l+r>>1,r,x->R));
}

node *rtl[4000];
node *rtr[4000];

map<ll,ll> mp;

int main(){
	#ifdef KHOKHO
		freopen("in.in","r",stdin);
		freopen("out.out","w",stdout);
	#endif
	ll n,w,l,r,d,k,c;
	cin>>n>>w;
	a.pb({{0,0},{0,0}});
	b.pb({{0,0},{w,0}});
	vector<ll> ve;
	ve.pb(0);
	ve.pb(w);
	for(int i=0; i<n; i++){
		cin>>k;
		if(k){
			cin>>l>>r>>d>>c;
			ve.pb(l);
			ve.pb(r);
			ve.pb(d);
			a.pb({{l,r},{d,c}});
		}
		else {
			cin>>l>>r>>d>>c;
			ve.pb(l);
			ve.pb(r);
			ve.pb(w-d);
			b.pb({{l,r},{w-d,c}});
		}
	}
	sort(ve.begin(),ve.end());
	c=2;
	for(auto x:ve)
		mp[x]=c++;

	for(auto x:a){
		x.fr.fr=mp[x.fr.fr];
		x.fr.sc=mp[x.fr.sc];
		x.sc.fr=mp[x.sc.fr];
	}
	for(auto x:b){
		x.fr.fr=mp[x.fr.fr];
		x.fr.sc=mp[x.fr.sc];
		x.sc.fr=mp[x.sc.fr];
	}



	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for(int i=0; i<=a.size(); i++)
		for(int j=0; j<=b.size(); j++)
			dp[i][j]=-MAX;
	for(int i=0; i<=a.size(); i++)rtl[i]=NULL;
	for(int i=0; i<=b.size(); i++)rtr[i]=NULL;
	dp[0][0]=0;
	ll pas=0;
	for(int i=0; i<a.size(); i++){
		for(int j=0; j<b.size(); j++){
			if(b[j].fr.fr<=a[i].fr.fr&&(a[i].fr.fr>=b[j].fr.sc||a[i].sc.fr<=b[j].sc.fr)){
				wl=0;
				wr=a[i].fr.fr;
				ll k=quer(0,c+2,rtr[j]);
				dp[i][j]=max(dp[i][j],k+a[i].sc.sc);

//				for(int k=0; k<i; k++){
//					if(a[k].fr.sc<=a[i].fr.fr)
//						dp[i][j]=max(dp[i][j],dp[k][j]+a[i].sc.sc);
//				}
			}

			if(b[j].fr.fr>=a[i].fr.fr&&(b[j].fr.fr>=a[i].fr.sc||a[i].sc.fr<=b[j].sc.fr)){
				wl=0;
				wr=b[j].fr.fr;
				ll k=quer(0,c+2,rtl[i]);
				dp[i][j]=max(dp[i][j],k+b[j].sc.sc);

//				for(int k=0; k<j; k++){
//					if(b[k].fr.sc<=b[j].fr.fr)
//						dp[i][j]=max(dp[i][j],dp[i][k]+b[j].sc.sc);
//				}
			}
			wi=a[i].fr.sc;
			wx=dp[i][j];
			updt(0,c+2,rtr[j]);

			wi=b[j].fr.sc;
			wx=dp[i][j];
			updt(0,c+2,rtl[i]);
			//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;

			pas=max(pas,dp[i][j]);
		}
	}
	cout<<pas;
}

Compilation message

mat.cpp: In function 'void updt(int, int, node*&)':
mat.cpp:45:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  updt(l,l+r>>1,x->L);
         ~^~
mat.cpp:46:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  updt(l+r>>1,r,x->R);
       ~^~
mat.cpp: In function 'int quer(int, int, node*&)':
mat.cpp:53:7: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
  if(wl<=l&r-1<=wr)return x->x;
     ~~^~~
mat.cpp:54:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  return max(quer(l,l+r>>1,x->L),
                    ~^~
mat.cpp:55:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
      quer(l+r>>1,r,x->R));
           ~^~
mat.cpp: In function 'int main()':
mat.cpp:112:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<=a.size(); i++)
               ~^~~~~~~~~~
mat.cpp:113:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<=b.size(); j++)
                ~^~~~~~~~~~
mat.cpp:115:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<=a.size(); i++)rtl[i]=NULL;
               ~^~~~~~~~~~
mat.cpp:116:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<=b.size(); i++)rtr[i]=NULL;
               ~^~~~~~~~~~
mat.cpp:119:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<a.size(); i++){
               ~^~~~~~~~~
mat.cpp:120:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<b.size(); j++){
                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 2100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 17484 KB Output is correct
2 Incorrect 49 ms 17484 KB Output isn't correct
3 Halted 0 ms 0 KB -