QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728339#5978. Runaway Quailtx34423 ✓2512ms7928kbC++142.0kb2024-11-09 15:00:072024-11-09 15:00:11

Judging History

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

  • [2024-11-09 15:00:11]
  • 评测
  • 测评结果:23
  • 用时:2512ms
  • 内存:7928kb
  • [2024-11-09 15:00:07]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ld double
#define PII pair<int,int>
#define fi first
#define se second
using namespace std;
int Read()
{
    int x=0;char ch=getchar();
    while(ch<'0'||ch>'9')ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    return x;
}
const int N=505;
int Q,n,m;
ld f[2][N][N],ans;
struct Node{int x,y;}a[N];
bool cmp(Node x,Node y){return x.x<y.x;}
inline void GetMin(ld &x,ld y){x=x<y?x:y;}
inline ld G(int x,ld y){return a[x].x+(a[x].x<0?-1:1)*y*a[x].y;}
void Solve()
{
    scanf("%d%d",&m,&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].x);
    for(int i=1;i<=n;i++)scanf("%d",&a[i].y);
    a[++n]={0,0};
    sort(a+1,a+n+1,cmp);
    int p=1;
    while(p<=n&&a[p].x<0)++p;
    ans=1e18;
    for(int i=1;i<=n;i++)for(int k=i;k<=n;k++)f[0][i][k]=1e18;
    f[0][p][p]=0;
    // for(int i=1;i<=n;i++)printf("(%d,%d)\n",a[i].x,a[i].y);
    for(int len=0,o=0;len<n;len++,o^=1)
    {
        for(int i=1;i<=n;i++)for(int k=i;k<=n;k++)f[!o][i][k]=1e18;
        for(int i=max(1,p-len),j=i+len;i<=min(p,n-len);i++,j++)for(int k=i;k<=i+len;k++)if(f[o][i][k]<1e18)
        {
            ld t=f[o][i][k],pl1=G(k,t);
            // printf("f:%d %d %d %.3lf\n",i,j,k,t);
            if(j<n)
            {
                ld pl2=G(j+1,t);
                // printf("%d %.3lf %.3lf\n",j+1,t,pl2);
                if(pl2<=pl1)GetMin(f[!o][i][k],t);
                else GetMin(f[!o][i][j+1],t+(pl2-pl1)/(m-a[j+1].y));
            }
            if(i>1)
            {
                ld pl2=G(i-1,t);
                if(pl2>=pl1)GetMin(f[!o][i-1][k],t);
                else GetMin(f[!o][i-1][i-1],t+(pl1-pl2)/(m-a[i-1].y));
            }
        }
    }
    for(int i=1;i<=n;i++)GetMin(ans,f[!(n&1)][1][i]);
    printf("%.9lf\n",ans);
}
int main()
{
    scanf("%d",&Q);
    for(int QQ=1;QQ<=Q;QQ++)printf("Case #%d: ",QQ),Solve();
}
// g++ C2.cpp -std=c++14 -O2 -o C2 ; ./C2
/*
2
4 3
3 6 9
3 2 1
2 2
1 -1
1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 2ms
memory: 6048kb

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.876344087
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: 2512ms
memory: 7928kb

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.088889658
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.987096787
Case #11: 128881.056148055
Case #12: 124955.3...

result:

ok correct! (50 test cases)

Extra Test:

score: 0
Extra Test Passed