# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
71263 |
2018-08-24T09:11:01 Z |
khohko |
매트 (KOI15_mat) |
C++17 |
|
657 ms |
158084 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];
ll fw[2][3010][6020];
//ll fw2[3010][6020];
void add(ll wa,ll w,ll i,ll x){
i++;
while(i<=6010){
fw[wa][w][i]=max(fw[wa][w][i],x);
i+=i&-i;
}
}
ll quer(ll wa,ll w,ll i){
ll p=-MAX;
i++;
while(i>1){
p=max(p,fw[wa][w][i]);
i-=i&-i;
}
return p;
}
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}});
mp[0]=1;
mp[w]=1;
for(int i=0; i<n; i++){
cin>>k;
if(k){
cin>>l>>r>>d>>c;
mp[l]=1;
mp[r]=1;
a.pb({{l,r},{d,c}});
}
else {
cin>>l>>r>>d>>c;
mp[l]=1;
mp[r]=1;
b.pb({{l,r},{w-d,c}});
}
}
ll C=1;
for(auto x:mp)
mp[x.fr]=C++;
//C+=100;
C+=2;
for(auto &x:a){
x.fr.fr=mp[x.fr.fr];
x.fr.sc=mp[x.fr.sc];
}
for(auto &x:b){
x.fr.fr=mp[x.fr.fr];
x.fr.sc=mp[x.fr.sc];
}
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<=3005; i++){
for(int j=0; j<=C; j++){
fw[0][i][j]=-MAX;
fw[1][i][j]=-MAX;
}
}
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)){
ll k=quer(1,j,a[i].fr.fr);
dp[i][j]=max(dp[i][j],k+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)){
ll k=quer(0,i,b[j].fr.fr);
dp[i][j]=max(dp[i][j],k+b[j].sc.sc);
}
add(1,j,a[i].fr.sc,dp[i][j]);
add(0,i,b[j].fr.sc,dp[i][j]);
pas=max(pas,dp[i][j]);
}
}
cout<<pas;
}
Compilation message
mat.cpp: In function 'int main()':
mat.cpp:125:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<=a.size(); i++)
~^~~~~~~~~~
mat.cpp:126:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<=b.size(); j++)
~^~~~~~~~~~
mat.cpp:138:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<a.size(); i++){
~^~~~~~~~~
mat.cpp:139:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<b.size(); j++){
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
25336 KB |
Output is correct |
2 |
Correct |
20 ms |
25448 KB |
Output is correct |
3 |
Correct |
21 ms |
25448 KB |
Output is correct |
4 |
Correct |
20 ms |
25448 KB |
Output is correct |
5 |
Correct |
22 ms |
25508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
25508 KB |
Output is correct |
2 |
Correct |
21 ms |
25508 KB |
Output is correct |
3 |
Correct |
18 ms |
25508 KB |
Output is correct |
4 |
Correct |
21 ms |
25508 KB |
Output is correct |
5 |
Correct |
21 ms |
25632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
37056 KB |
Output is correct |
2 |
Correct |
33 ms |
37056 KB |
Output is correct |
3 |
Correct |
31 ms |
37056 KB |
Output is correct |
4 |
Correct |
26 ms |
37056 KB |
Output is correct |
5 |
Correct |
30 ms |
37056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
142572 KB |
Output is correct |
2 |
Correct |
143 ms |
142572 KB |
Output is correct |
3 |
Correct |
128 ms |
142572 KB |
Output is correct |
4 |
Correct |
130 ms |
142572 KB |
Output is correct |
5 |
Correct |
71 ms |
142572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
579 ms |
157688 KB |
Output is correct |
2 |
Correct |
657 ms |
157688 KB |
Output is correct |
3 |
Correct |
611 ms |
157688 KB |
Output is correct |
4 |
Correct |
634 ms |
157876 KB |
Output is correct |
5 |
Correct |
461 ms |
157876 KB |
Output is correct |
6 |
Correct |
361 ms |
158084 KB |
Output is correct |
7 |
Correct |
625 ms |
158084 KB |
Output is correct |
8 |
Correct |
393 ms |
158084 KB |
Output is correct |
9 |
Correct |
473 ms |
158084 KB |
Output is correct |
10 |
Correct |
418 ms |
158084 KB |
Output is correct |