QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246929#5137. TowersfjhWA 78ms3520kbC++14873b2023-11-11 12:43:392023-11-11 12:43:40

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 12:43:40]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:3520kb
  • [2023-11-11 12:43:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define fdr(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define endl '\n'
const int N=510;
const int INF=1e18+10;

int n,m;
int a[N];

int get(int x,int y){
	if(x==y) return 0;
	if(x<y) swap(x,y);
	int res=x-y;
	int cnt=0;
	while(x>y){
		x/=2;
		cnt++;
		res=min(abs(x-y)+cnt,res);
	}
	return res;
	
}

void solve(){
	cin>>n>>m;
	fer(i,1,n) cin>>a[i];
	int ans=INF;
	fer(i,1,n){
		int x=a[i];
		while(x){
			vector<int> v;
			int sum=0;
			fer(j,1,n) v.pb(get(a[j],x));
			sort(v.begin(),v.end());
			for(int j=0;j<n-m;j++) sum+=v[j];  
			ans=min(ans,sum);	
			x/=2;
		}
	}
	cout<<ans<<endl;
}

signed main(){
	ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		solve();
	} 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
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: 78ms
memory: 3432kb

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:

427
3
420
96
548
602
940
214
615
46

result:

wrong answer 1st numbers differ - expected: '454', found: '427'