QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639636 | #5137. Tower | sazhi | WA | 28ms | 3816kb | C++20 | 1.5kb | 2024-10-13 21:01:01 | 2024-10-13 21:01:01 |
Judging History
answer
// author: jieda
// file: cpp
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
# define fi first
# define se second
# define all(x) x.begin(),x.end()
# define stst stringstream
# define pb push_back
# define pf push_front
# define pp push
# define lowbit(x) (x)&(-x)
# define fa(i,op,n) for (int i = op; i <= n; i++)
# define fb(j,op,n) for (ll j = op; j >= n; j--)
# define fg(i,op,n) for (ll i = op; i != n; i = ne[i])
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int N = 2e5+10,INF = 0x3f3f3f3f,mod = 1000000007;
const ll MOD = 212370440130137957ll;//hash(hight)
const int base = 131;
const double eps = 1e-10;
const int seed=10086,mo=1e6+7; //hash(lower)
int prime = 233317;
using namespace std;
void solve(){
int n,m;cin>>n>>m;
vector<int> a(n+1);
vector<int> res;
for(int i = 1;i<=n;i++){
int x;cin>>x;
a[i] = x;
while(x){
// cout<<x<<'\n';
res.pb(x);
x /= 2;
}
}
ll ans = 1e9;
for(auto x:res){
vector<ll> v(n+1,1e9);
for(int i = 1;i<=n;i++){
int y = a[i];
ll sum = 0;
while(y>=1){
v[i] = min(v[i],sum+abs(y-x));
y /= 2,sum++;
}
}
ll sum = 0;
for(int i = 1;i<=n-m;i++){
sum += v[i];
}
ans = min(ans,sum);
}
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t = 1;
cin>>t;
while(t--){
solve();
}
return 0;
}
/**/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 28ms
memory: 3816kb
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:
575 43 543 155 786 655 1051 277 702 124
result:
wrong answer 1st numbers differ - expected: '454', found: '575'