QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#773993#5137. Towerszy10010WA 6ms3616kbC++231.6kb2024-11-23 11:10:452024-11-23 11:10:46

Judging History

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

  • [2024-11-23 11:10:46]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3616kb
  • [2024-11-23 11:10:45]
  • 提交

answer

#include <map>
#include <set>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define u1 (u<<1)
#define u2 (u<<1|1)
#define pb push_back
#define pp pop_back()
#define int long long
#define laile cout<<"laile"<<endl
#define lowbit(x) ((x)&(-x))
#define double long double
#define sf(x) scanf("%lld",&x)
#define sff(x,y) scanf("%lld %lld",&x,&y)
#define sd(x) scanf("%Lf",&x)
#define sdd(x,y) scanf("%Lf %Lf",&x,&y)
#define _for(i,n) for(int i=0;i<(n);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define _pre(i,a,b) for(int i=(a);i>=(b);--i)
#define all(x) (x).begin(), (x).end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const int N=1e6+10,INF=4e18;
int n,m;
int q[N];
vector<int>v;
int cal(int x)
{
	vector<int>res;
	_rep(i,1,n)
	{
		int now=q[i],ma=INF,op=0;
		ma=min(ma,abs(now-x));
		while(1)
		{
			now/=2;
			op++;
			ma=min(ma,op+abs(now-x));
			if(now<q[i])break;
		}
		res.pb(ma);
	}
	sort(all(res));
	int ans=0;
	for(int i=0;i<n-m;i++)
		ans+=res[i];
	return ans;
}
void solve()
{
	cin>>n>>m;
	v.clear();
	_rep(i,1,n)
	{
		cin>>q[i];
		int x=q[i];
		while(x)
		{
			v.pb(x);
			x/=2;
		}
	}
	sort(all(v));
	int res=INF;
	v.erase(unique(all(v)),v.end());
	for(auto i:v)
		res=min(res,cal(i));
	cout<<res<<'\n';
	return ;
}
signed main()
{
	IOS;
	int T=1;
	cin>>T;
	while(T--)
		solve();
	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: 3612kb

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:

737
3
723
160
848
1720
2287
437
1395
50

result:

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