QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#733779#5978. Runaway Quailjamesharden66623 ✓850ms5196kbC++142.3kb2024-11-10 20:59:432024-11-10 20:59:44

Judging History

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

  • [2024-11-10 20:59:44]
  • 评测
  • 测评结果:23
  • 用时:850ms
  • 内存:5196kb
  • [2024-11-10 20:59:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=500+10;
const double eps=1e-8;
int t,c,n,a[N],tot1=0,tot2=0;
double f[N][N];
struct node
{
    double pos,val;
}a1[N],a2[N];
int read()
{
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
        s=s*10+(ch-'0'),ch=getchar();
    return s*w;
}
bool cmp1(node a,node b)
{
    if(a.val!=b.val)
        return a.val>b.val;
    else
        return a.pos>b.pos;
}
bool cmp2(node a,node b)
{
    if(a.val!=b.val)
        return a.val<b.val;
    else
        return a.pos<b.pos;
}
double Pos1(int i,double t)
{
    return a1[i].pos+a1[i].val*t;
}
double Pos2(int i,double t)
{
    return a2[i].pos+a2[i].val*t;
}
int main()
{
    t=read();
    for(int T=1;T<=t;++T)
    {
        c=read(),n=read();
        tot1=0,tot2=0;
        for(int i=1;i<=n;++i)
            a[i]=read();
        for(int i=1;i<=n;++i)
        {
            if(a[i]<0)
                a1[++tot1]=(node){1.0*a[i],-1.0*read()};
            else
                a2[++tot2]=(node){1.0*a[i],1.0*read()};
        }
        sort(a1+1,a1+tot1+1,cmp1);
        sort(a2+1,a2+tot2+1,cmp2);
        for(int i=0;i<=tot1;++i)
            for(int j=0;j<=tot2;++j)
                f[i][j]=1e12;
        f[tot1][tot2]=0;
        for(int i=tot1;i>=0;--i)
            for(int j=tot2;j>=0;--j)
            {
                double maxn=0;
                for(int k=i;k>=1;--k)
                {
                    double tim=(-Pos1(k,f[i][j]))/(c+a1[k].val);
                    maxn=max(maxn,tim);
                    if(k==1&&j==0)
                        f[k-1][j]=min(f[k-1][j],f[i][j]+maxn);
                    else
                        f[k-1][j]=min(f[k-1][j],f[i][j]+2.0*maxn);
                }
                maxn=0;
                for(int k=j;k>=1;--k)
                {
                    double tim=Pos2(k,f[i][j])/(c-a2[k].val);
                    maxn=max(maxn,tim);
                    if(k==1&&i==0)
                        f[i][k-1]=min(f[i][k-1],f[i][j]+maxn);
                    else
                        f[i][k-1]=min(f[i][k-1],f[i][j]+2*maxn);
                }
            }
        printf("Case #%d: %.9lf\n",T,f[0][0]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 1ms
memory: 3980kb

input:

50
4 3
-3 -6 -9
3 2 1
2 2
1 -1
1 1
1000 25
769234 -5735820 -524288 -5403090 -6429140 1574982 1 -9733628 -1407481 4093041 4117720 -3193501 -9765195 -3069520 1122216 -5799108 131072 -8482066 -256 -8021159 -8958386 -7027036 5370579 -3602534 -6834567
425 102 744 155 339 19 999 19 159 198 51 304 369 601 ...

output:

Case #1: 3.000000000
Case #2: 5.000000000
Case #3: 51133.937500000
Case #4: 429262.396142110
Case #5: 129368.012279597
Case #6: 7801.832031250
Case #7: 66656.812500000
Case #8: 607220.690423515
Case #9: 5725896.876344086
Case #10: 129205.285220126
Case #11: 64298.000000000
Case #12: 610881.705159705...

result:

ok correct! (50 test cases)

Subtask #2:

score: 15
Accepted

Test #2:

score: 15
Accepted
time: 850ms
memory: 5196kb

input:

50
4 3
-3 -6 -9
3 2 1
2 2
1 -1
1 1
1000 500
-9650379 9806301 -6495789 -1283284 5022779 4725553 9364178 -8123302 -9609729 7847458 -142364 6983908 8147008 -3186924 7339254 -8737645 8757174 7887319 3609962 5780915 -1752801 -1657946 -9511339 5113995 -7887160 -6093170 260267 -3837106 -356098 6676924 6210...

output:

Case #1: 3.000000000
Case #2: 5.000000000
Case #3: 205911250.088888913
Case #4: 36298.000000000
Case #5: 186002.250000000
Case #6: 13741948.500000000
Case #7: 109001.125000000
Case #8: 38656.812500000
Case #9: 128881.056148055
Case #10: 8069407.987096774
Case #11: 128881.056148055
Case #12: 124955.3...

result:

ok correct! (50 test cases)

Extra Test:

score: 0
Extra Test Passed