QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#718205 | #5137. Tower | MLK2 | WA | 6ms | 3880kb | C++14 | 1.4kb | 2024-11-06 19:57:51 | 2024-11-06 19:57:56 |
Judging History
answer
#include <bits/stdc++.h>
#define N (200000 + 10) /*------------------ #define ------------------*/
#define M (400000 + 10)
#define MOD (1000000000 + 7)
//#define MOD (998244353)
#define INF (0x3f3f3f3f)
#define LNF (3e18)
#define mod(a,b) (((a)%(b)+(b))%(b))
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<double,double> PDD;
int n,m;
LL a[N];
set<LL> H;
auto solve(){
cin >> n >> m;
for(int i = 1;i <= n;i ++ ) cin >> a[i];
H.clear();
for(int i = 1;i <= n;i ++ ){
LL x = a[i];
while(x > 0){
H.insert(x);
x >>= 1;
}
}
LL ans = 1e18;
for(LL h : H){
vector<LL> cost;
for(int i = 1;i <= n;i ++ ){
LL c = 0;
if(a[i] <= h) c += h - a[i];
else{
LL x = a[i];
while(x / 2 >= h) x /= 2,c ++ ;
c += min(x - h,h - x / 2);
}
cost.push_back(c);
}
sort(cost.begin(),cost.end());
LL res = 0;
for(int i = 0;i < n - m;i ++ )
res += cost[i];
ans = min(ans,res);
}
cout << ans << '\n';
}
signed main(){
IOS
int T = 1;
cin >> T;
while(T -- ) solve();
//while(T -- ) cout << (solve() ? "YES" : "NO") << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 3880kb
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:
399 3 380 90 493 570 886 202 589 45
result:
wrong answer 1st numbers differ - expected: '454', found: '399'