QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#354196#8309. MountainPlentyOfPenaltyRE 2ms5596kbC++173.1kb2024-03-14 23:08:162024-03-14 23:08:17

Judging History

你现在查看的是最新测评结果

  • [2024-03-14 23:08:17]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:5596kb
  • [2024-03-14 23:08:16]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
const int MAXN = 211,MU = 1<<10;
typedef std::pair<int,int> pii;
void umax(double& a,double b){if(b>a)a=b;}
const double INF = 1e20;
double f[MAXN][MU+10],pre[MAXN][MU+10];
double g[MAXN][MU+10];
int a[MAXN];
std::vector<pii>seq[MAXN];
double eval(int i,int y)
{
    int l=a[i],r=a[i+1];
    if(l>r)std::swap(l,r);
    if(y>=r)return 0.0;
    if(y>=l)
    {
        double low=1.0*(r-y)/(r-l);
        //printf("Eval(%d,%d)=%.3lf\n",i,y,low);
        return low*(r-y)/2;
    }
    double res=1.0*(r-l)/2 + (l-max(y,0));
    
        //printf("Eval(%d,%d)=%.3lf\n",i,y,res);
    return res;
}
int main()
{
    //freopen("E.in","r",stdin);
    cin.tie(0)->ios::sync_with_stdio(0);
    int n,w,h;
    cin>>n>>w>>h;
    for(int i=1;i<=n;++i)cin>>a[i];
    int U=(1<<(2*w))-1;
    for(int i=1;i<=n;++i)
    {
        for(int s=0;s<=U;++s)
        {
            //printf("try i=%d,s=%d\n",i,s);
            for(int j=-w;j<w*2;++j)
                if(i+j>=0&&i+j<=n)seq[i+j].clear();
            bool fail=0;
            for(int j=0;j<w*2;++j)
                if(s&(1<<j))
                {
                    int t=i-j;
                    //printf("j=%d,t=%d,at=%d\n",j,t,a[t]);
                    if(t<=0)fail=1;
                    for(int k=-w;k<w;++k)
                        if(t+k>=0&&t+k<=n)seq[t+k].push_back(pii(a[t]-h,a[t]+h));
                }
            if(fail)g[i][s]=-INF;
            else
            {
                //printf("i=%d,s=%d\n",i,s);
                double sum=0;
                for(int k=-w;k<w;++k)
                {
                    if(i+k<0&&i+k>n)continue;
                    auto& q=seq[i+k];
                    if(q.empty())continue;
                    //printf("Consider %d\n",i+k);
                    std::sort(q.begin(),q.end());
                    int l=-1e9,r=-1e9;
                    for(auto [x,y]:q)
                    {
                        //printf("[%d,%d]\n",x,y);
                        if(r<x)sum+=eval(i+k,l)-eval(i+k,r),l=x,r=y;
                        else r=max(y,r);
                    }
                    sum+=eval(i+k,l)-eval(i+k,r);
                }
                //printf("i=%d,s=%d,g=%.6lf\n",i,s,sum);
                g[i][s]=sum;
            }
        }
    }
    //fill(f,f+MAXN*(MU>>1),-INF);
    int A=U>>1;
    for(int j=0;j<=n;++j)
        for(int s=0;s<=A;++s)
            f[j][s]=-INF;
    f[0][0]=0;
    for(int i=1;i<=n;++i)
    {
        memcpy(pre,f,sizeof f);//,fill(f,f+MAXN*(MU>>1),-INF);
        for(int j=0;j<=n;++j)
            for(int s=0;s<=A;++s)
                f[j][s]=-INF;
        for(int j=0;j<=i;++j)
        {
            for(int s=0;s<=A;++s)
            {
                umax(f[j][(s<<1)&A],pre[j][s]);
                umax(f[j+1][(s<<1|1)&A],pre[j][s]+ g[i][s<<1|1]-g[i][s<<1] );
            }
        }
    }
    for(int j=1;j<=n;++j)
    {
        double ans=-INF;
        for(int s=0;s<=A;++s)umax(ans,f[j][s]);
        printf("%.10lf\n",ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5596kb

input:

3 1 2
2 1 3

output:

3.5000000000
4.5000000000
5.1666666667

result:

ok 3 numbers

Test #2:

score: -100
Runtime Error

input:

2 3 78
55 51

output:


result: