QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751722 | #5137. Tower | hela | WA | 3ms | 5612kb | C++14 | 1.7kb | 2024-11-15 20:18:01 | 2024-11-15 20:18:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define int ll
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=z;x>=y;x--)
typedef pair<ll, ll> PII;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
int a[N],sum[N];
int fun(int x){
int cnt=0;
while(x>1){
x/=2;
cnt++;
}
//cout<<cnt<<endl;
return cnt;
}
int findCnt(int x,int y){
int res=abs(y-x),cnt=0;
while(y>=x){
y/=2;
cnt++;
res=min(res,cnt+abs(y-x));
}
return res;
}
void solve(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
set<int> st;
int ans=0;
for(int i=1;i<=n;i++){
int x = a[i];
while(x>1){
ans++;
x/=2;
}
}
for(int i=1;i<=n;i++){
int x = a[i];
int cnt=fun(x);
while(x){
for(int j=max((int)0,x-cnt);j<=x+cnt;j++) {
int p=upper_bound(a+1,a+n+1,j)-a;
p--;
if(p*j-sum[p]<=ans) st.insert(j);
}
x/=2;
cnt--;
}
}
//for(auto i:st) cout<<i<<" ";
for(auto x:st){
vector<int> vc;
for(int i=1;i<=n;i++){
vc.push_back(findCnt(x,a[i]));
}
sort(vc.begin(),vc.end());
int res=0;
for(int i=0;i<n-m;i++) res+=vc[i];
ans=min(ans,res);
}
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int _ = 1;
cin>>_;
while (_--> 0)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 5612kb
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:
454 3 436 108 570 636 994 227 656 56
result:
wrong answer 10th numbers differ - expected: '50', found: '56'