Submission #18100

# Submission time Handle Problem Language Result Execution time Memory
18100 2016-01-20T07:53:20 Z atomzeno 매트 (KOI15_mat) C++
100 / 100
56 ms 106740 KB
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define MX 3001
int n,w,cnt[2],b[MX],c[MX],ans=0,D[MX][MX],DA[MX][MX],DB[MX][MX];
struct DT{
    int x1,x2,w,val;
    bool operator<(const DT&r)const{
        return r.x2>x2;
    }
}up[MX],down[MX];
int pos(int x,int y){
    if((up[x].w+down[y].w)>w){
        if(up[x].x2<=down[y].x1||up[x].x1>=down[y].x2){return 1;}
        return 0;
    }
    else{
        return 1;
    }
}
void RDA(int x,int y){
    if(up[x].x1>=down[y].x2){
        DA[x][y]=up[x].val+D[b[x]][y];//
    }
    else if(up[x].x2<=down[y].x1){
        DA[x][y]=max(DA[x][y-1],DA[x][c[y]]+down[y].val);//
    }
    else if(up[x].x1<=down[y].x1&&down[y].x1<=up[x].x2){
        DA[x][y]=max(DA[x][y-1],DA[x][c[y]]+down[y].val);//
    }
    else{
        DA[x][y]=max(DB[b[x]][y]+up[x].val,DA[x][y-1]);//
    }
}
void RDB(int x,int y){
    if(up[x].x1>=down[y].x2){
        DB[x][y]=max(DB[x-1][y],DB[b[x]][y]+up[x].val);//
    }
    else if(up[x].x2<=down[y].x1){
        DB[x][y]=D[x][c[y]]+down[y].val;//
    }
    else if(up[x].x1<=down[y].x1&&down[y].x1<=up[x].x2){
        DB[x][y]=max(DB[x-1][y],DA[x][c[y]]+down[y].val);
    }
    else{
        DB[x][y]=max(DB[x-1][y],DB[b[x]][y]+up[x].val);
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int type,i,j;
    scanf("%d%d",&n,&w);
    for(i=0;i<n;i++){
        scanf("%d",&type);
        if(type==0){
            ++cnt[0];
            scanf("%d%d%d%d",&up[cnt[0]].x1,&up[cnt[0]].x2,&up[cnt[0]].w,&up[cnt[0]].val);
  
        }
        else{
            ++cnt[1];
            scanf("%d%d%d%d",&down[cnt[1]].x1,&down[cnt[1]].x2,&down[cnt[1]].w,&down[cnt[1]].val);
        }
    }
    sort(up+1,up+cnt[0]+1);
    sort(down+1,down+cnt[1]+1);
    j=0;
    for(i=1;i<=cnt[0];i++){
        for(j=1;j<=i;j++){
            if(up[j].x2>up[i].x1){break;}
        }
        b[i]=j-1;
    }
    j=0;
    for(i=1;i<=cnt[1];i++){
        for(j=1;j<=i;j++){
            if(down[j].x2>down[i].x1){break;}
        }
        c[i]=j-1;
    }
    for(i=1;i<=cnt[0];i++){
        D[i][0]=max(D[i-1][0],up[i].val+D[b[i]][0]);
    }
    for(i=1;i<=cnt[1];i++){
        D[0][i]=max(D[0][i-1],down[i].val+D[0][c[i]]);
    }
    for(i=1;i<=cnt[0];i++){DA[i][0]=up[i].val+D[b[i]][0];}//아닐수도!
    for(i=1;i<=cnt[1];i++){DA[0][i]=0;}//아닐수도!
    for(i=1;i<=cnt[0];i++){DB[i][0]=0;}//아닐수도!
    for(i=1;i<=cnt[1];i++){DB[0][i]=down[i].val+D[0][c[i]];}//아닐수도!
    for(i=1;i<=cnt[0];i++){
        for(j=1;j<=cnt[1];j++){
            if(pos(i,j)==1){
                RDA(i,j);
                RDB(i,j);
                D[i][j]=max(max(D[i-1][j],D[i][j-1]),max(DA[i][j],DB[i][j]));
            }
            else{
                DA[i][j]=DA[i][j-1];
                DB[i][j]=DB[i-1][j];
                D[i][j]=max(max(D[i-1][j],D[i][j-1]),max(DA[i][j],DB[i][j]));
            }
  
        }
    }
    for(i=0;i<=cnt[0];i++){
        for(j=0;j<=cnt[1];j++){
            ans=ans>D[i][j]?ans:D[i][j];
        }
    }
    printf("%d",ans);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 106740 KB Output is correct
2 Correct 0 ms 106740 KB Output is correct
3 Correct 0 ms 106740 KB Output is correct
4 Correct 0 ms 106740 KB Output is correct
5 Correct 0 ms 106740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 106740 KB Output is correct
2 Correct 0 ms 106740 KB Output is correct
3 Correct 0 ms 106740 KB Output is correct
4 Correct 0 ms 106740 KB Output is correct
5 Correct 0 ms 106740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 106740 KB Output is correct
2 Correct 0 ms 106740 KB Output is correct
3 Correct 0 ms 106740 KB Output is correct
4 Correct 0 ms 106740 KB Output is correct
5 Correct 0 ms 106740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 106740 KB Output is correct
2 Correct 3 ms 106740 KB Output is correct
3 Correct 4 ms 106740 KB Output is correct
4 Correct 8 ms 106740 KB Output is correct
5 Correct 4 ms 106740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 106740 KB Output is correct
2 Correct 54 ms 106740 KB Output is correct
3 Correct 54 ms 106740 KB Output is correct
4 Correct 50 ms 106740 KB Output is correct
5 Correct 51 ms 106740 KB Output is correct
6 Correct 52 ms 106740 KB Output is correct
7 Correct 53 ms 106740 KB Output is correct
8 Correct 56 ms 106740 KB Output is correct
9 Correct 42 ms 106740 KB Output is correct
10 Correct 52 ms 106740 KB Output is correct