QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#190903#5137. TowerbzwWA 9ms5104kbC++11959b2023-09-29 15:33:232023-09-29 15:33:23

Judging History

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

  • [2023-09-29 15:33:23]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:5104kb
  • [2023-09-29 15:33:23]
  • 提交

answer

// qwq
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll a[4000][555],b[555],c[4000];
ll calc(ll a,ll b){
    ll div=0,ans=abs(a-b);
    while(a>b)
        div++,a>>=1,
        ans=min(ans,abs(a-b)+div);
    ans=min(ans,abs(a-b)+div);
    return ans;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        ll n,m,cc=0;
        cin>>n>>m;m=n-m;
        for(ll i=1;i<=n;i++){
            cin>>b[i]; int t=b[i];
            while(t)c[++cc]=t,t>>=1;
        }
        sort(c+1,c+cc+1);
        cc=unique(c+1,c+cc+1)-c-1;
        for(ll i=1;i<=cc;i++)
            for(ll j=1;j<=n;j++)
                a[i][j]=calc(b[j],c[i]);
        ll ans=1e16;
        for(ll i=1;i<=n;i++){
            sort(a[i]+1,a[i]+n+1);
            for(ll j=1;j<=n;j++)a[i][j]+=a[i][j-1];
            for(ll j=m;j<=n;j++)
                ans=min(ans,a[i][j]-a[i][j-m]);
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3420kb

input:

3
2 0
2 6
5 0
1 2 3 4 5
5 3
1 2 3 4 5

output:

2
4
1

result:

ok 3 number(s): "2 4 1"

Test #2:

score: -100
Wrong Answer
time: 9ms
memory: 5104kb

input:

10
272 118
11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...

output:

0
0
0
108
0
0
0
0
0
0

result:

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