QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#669824#5137. Towerk4sum1WA 3ms3700kbC++17933b2024-10-23 19:46:292024-10-23 19:46:30

Judging History

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

  • [2024-10-23 19:46:30]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3700kb
  • [2024-10-23 19:46:29]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;

int a[510];
map<int,int> mp;
int b[510];

void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int x;
	
	for(int i=1;i<=n;i++)
	{
		x=a[i];
		
		while(x)
		{
			mp[x]=1;
			x=x/2;
		}
	}
	
	int ans=1e9;

	for(auto x:mp)
	{
		for(int i=1;i<=n;i++)
		{
			int cnt=0;
			int y=a[i];
			int minn=abs(y-x.first);
			
			while(y>x.first)
			{
				cnt++;
				minn=min(minn,y-x.first+cnt);
				y=y/2;
			}
			minn=min(minn,x.first-y+cnt);
			b[i]=minn;
		}
		sort(b+1,b+1+n);
		int nowans=0;
		for(int i=1;i<=n-m;i++)
		{
			nowans=nowans+b[i];
		}
		
		ans=min(ans,nowans);
		
		//cout<<x.first<<' '<<ans<<'\n';
	}
	
	cout<<ans<<'\n';
	
	mp.clear();
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

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: 3700kb

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:

484
3
465
114
603
680
1063
239
702
56

result:

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