比赛 EYOI与SBOI开学欢乐赛2nd 评测结果 AAAAWW
题目名称 免费馅饼 最终得分 66
用户昵称 op_组撒头屯 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2022-09-02 20:17:03
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=10000+5;
int w,h,n=0;
struct sdf{
    int t,x,p;
}m[N];
int f[N]={0},pre[N]={0};
bool cmp(sdf a,sdf b){
    return a.t<b.t;
}
int dist(int x){
    if (x<0)x=-x;
    if (x&1)return x/2+1;
    return x/2;
}
void write(int x){
    if (x==0)return ;
    int pos=pre[x];
    write(pos);
    
    if (m[pos].x<m[x].x){
        int k=m[x].x-m[pos].x;
        for (int i=m[pos].t+1;i+dist(k)<=m[x].t;i++)printf("0\n");
        (k%2==1)?printf("1\n"):printf("2\n");
        for (int i=1;i<=dist(k)-1;i++)printf("2\n");
    }
    if (m[pos].x==m[x].x){
        for (int i=m[pos].t+1;i<=m[x].t;i++)printf("0\n");
    }
    if (m[pos].x>m[x].x){
        int k=m[pos].x-m[x].x;
        for (int i=1;i<=dist(k)-1;i++)printf("-2\n");
        (k%2==1)?printf("-1\n"):printf("-2\n");
        for (int i=m[pos].t+1;i+dist(k)<=m[x].t;i++)printf("0\n");
    }
}
int main(){
    freopen ("freepizza.in","r",stdin);
    freopen ("freepizza.out","w",stdout);
    scanf("%d%d",&w,&h);
    int t,x,v,p;
    while(scanf("%d%d%d%d",&t,&x,&v,&p)!=EOF){
        if ((h-1)%v!=0)continue;
        m[++n]={t+(h-1)/v,x,p};
    }
    sort(m+1,m+n+1,cmp);
    m[0].x=(w+1)/2;m[0].t=0;
    memset(f,-1,sizeof(f));f[0]=0;
    for (int i=1;i<=n;i++){
        int mx=-1,mxi=-1;
        for (int j=0;j<i;j++){
            if (f[j]>mx&&dist(m[i].x-m[j].x)<=m[i].t-m[j].t){
                mx=f[j],mxi=j;
            }
        }
        if (mxi==-1)continue;
        f[i]=mx+m[i].p;pre[i]=mxi;
    }
    int mx=-1,mxi=-1;
    for (int i=1;i<=n;i++){
        if (f[i]>mx){
            mx=f[i];mxi=i;
        }
    } 
    if (mxi==-1){
        printf("0\n");return 0;
    }
    printf("%d\n",f[mxi]);
    write(mxi);
    return 0;
}