QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#755648#5137. TowerQFshengxiuCompile Error//C++231.1kb2024-11-16 17:49:412024-11-16 17:49:41

Judging History

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

  • [2024-11-16 17:49:41]
  • 评测
  • [2024-11-16 17:49:41]
  • 提交

answer

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

const int N = 505;
int a[N];
int n, m;
set<int> kn;
vector<int> v;
void solve()
{
	kn.clear();
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		kn.insert(a[i]);
		int qf = a[i];
		while (qf > 1)
		{
			kn.insert(qf / 2);
			qf /= 2;
		}
	}
	for (auto c : kn)
	{
		v.push_back(c);
	}
	int len = v.size();
	int minn = 1e9;
	for (int i = 0; i < len; i++)
	{
		vector<int> da;
		int pos = v[i], scnt = 0;
		for (int j = 1; j <= n; j++)
		{
			int x = a[j], pre = a[j], cnt = 0;
			while (x >= pos)
				pre = x, x /= 2, cnt++;
			if (pre == x)
			{
				cnt += min(abs(pos - x), abs(pos - pre));
			}
			else
			{
				cnt += min(abs(pos - x), abs(pos - pre) - 1);
			}
			da.push_back(cnt);
		}
		sort(da.begin(), da.end());
		int dan = 0;
		for (int j = 0; j < n - m; j++)
		{
			dan += da[j];
		}
		minn = min(minn, dan);
	}
	cout << minn << endl;
	v.clear();
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
}

详细

cc1plus: error: ‘::main’ must return ‘int’