QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#209834#6134. Soldier Gamerqoi031WA 0ms3800kbC++201.7kb2023-10-10 18:08:382023-10-10 18:08:39

Judging History

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

  • [2023-10-10 18:08:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3800kb
  • [2023-10-10 18:08:38]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#include<map>
#define INF 4000000000
typedef long long ll;
int n;
int a[100005];
std::map<ll,ll> val;
ll calc(const ll m)
{
    if(val.count(m))
    {
        return val[m];
    }
    ll f0(0),f1(__builtin_llabs(m-a[0]));
    for(int j=1;j<n;j++)
    {
        const ll f2(std::min(std::max(f0,__builtin_llabs(m-a[j-1]-a[j])),
                             std::max(f1,__builtin_llabs(m-a[j]))));
        f0=f1,f1=f2;
    }
    return val[m]=f1;
}
void solve()
{
    val.clear();
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i),a[i]<<=1;
    }
    for(int i=-50;i<=0;i++)
    {
        printf("%lld ",calc(i));
    }
    printf("\n");
    ll s(calc(-INF)),p(-INF);
    for(int t=0;p<INF&&t<30;t++)
    {
        const ll v(calc(p)),d(calc(p+1)-calc(p));
        ll l(p),r(INF);
        while(l<=r)
        {
            const ll m(l+r>>1);
            if(calc(m)==v+d*(m-p))
            {
                l=m+1;
            }
            else
            {
                r=m-1;
            }
        }
        s=std::min(s,calc(r));
        p=r+calc(r)-s;
    }
    ll q(INF);
    for(int t=0;q>p&&t<30;t++)
    {
        const ll v(calc(q)),d(calc(q-1)-calc(q));
        ll l(-INF),r(q);
        while(l<=r)
        {
            const ll m(l+r>>1);
            if(calc(m)==v+d*(q-m))
            {
                r=m-1;
            }
            else
            {
                l=m+1;
            }
        }
        s=std::min(s,calc(l));
        q=l-calc(l)+s;
    }
    printf("%lld\n",s);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3800kb

input:

3
5
-1 4 2 1 1
4
1 3 2 4
1
7

output:

56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 
1
58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9...

result:

wrong answer 1st numbers differ - expected: '1', found: '56'