QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#759225 | #5137. Tower | frankly6 | WA | 6ms | 3724kb | C++17 | 1.4kb | 2024-11-17 23:21:03 | 2024-11-17 23:21:05 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
const int MX=505;
const int inf=0x3fffffff;
int T, N, M;
int ar[MX];
map<int,int> mp;
int read()
{
int r=0, f=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
return r*f;
}
int main()
{
// freopen("testdata.in","r",stdin);
T=read();
while(T--)
{
mp.clear();
N=read(); M=read();
for(int i=1;i<=N;i++)
{
ar[i]=read();
int tmp=ar[i];
while(tmp) mp[tmp]=1, tmp/=2;
}
int ans=inf;
for(auto [tar,tag]:mp)
{
int br[MX]={}, cr[MX]={}, ta=0;
memcpy(cr,ar,sizeof(ar));
for(int i=1;i<=N;i++)
{
if(cr[i]<tar) br[i]=tar-cr[i];
else
{
while(cr[i]/2>=tar) cr[i]/=2, br[i]++;
br[i]+=cr[i]-tar;
}
// cout << " br[i]=" << br[i] << '\n';
}
sort(br+1,br+1+N);
for(int i=1;i<=N-M;i++)
ta+=br[i];
// cout << "tar=" << tar << ", ta=" << ta << '\n';
ans=min(ans,ta);
}
cout << ans << '\n';
}
return (0-0);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
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: 6ms
memory: 3724kb
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:
485 3 483 116 617 663 1057 241 678 55
result:
wrong answer 1st numbers differ - expected: '454', found: '485'