QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#216359 | #5137. Tower | Simple_QAQ | WA | 3ms | 3452kb | C++14 | 1.1kb | 2023-10-15 17:43:24 | 2023-10-15 17:43:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 510;;
int n,m;
int a[N],ans[N],cha[N];
void solve()
{
cin>>n>>m;
int geshu=0;
for(int i=1;i<=n;i++){
cin>>a[i];
int x=a[i];
while(x){
ans[++geshu]=x; //记录最终答案可能的值
x/=2;
}
}
int minn=1e17;
for(int i=1;i<=geshu;i++){ //枚举所有最终答案
int x=ans[i];
int cnt=0;
for(int j=1;j<=n;j++){
cha[j]=1e10;
if(a[j]<x)cha[j]=x-a[j]; //小于最终答案的值只能通过+1来操作
else if(a[j]==x){
cha[j]=0;
continue;
}
else { //大于最终答案的值先不断/2再加减
int num=a[j],shu=0;
while(num>x){
if(num>x&&(num/2)<=x){
cha[j]=min(shu+num-x,shu+1+(x-num/2));
break;
}
num/=2;shu++;
}
}
}
sort(cha+1,cha+1+n);
for(int j=1;j<=n-m;j++)cnt+=cha[j];
minn=min(minn,cnt);
}
cout<<minn<<endl;
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3436kb
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: 3ms
memory: 3452kb
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 11 0 0 0 60 0 34
result:
wrong answer 1st numbers differ - expected: '454', found: '0'