QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#659717#5137. TowerwzxtslWA 339ms5732kbC++231.1kb2024-10-19 21:30:412024-10-19 21:30:43

Judging History

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

  • [2024-10-19 21:30:43]
  • 评测
  • 测评结果:WA
  • 用时:339ms
  • 内存:5732kb
  • [2024-10-19 21:30:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=2e6+7;
int n,m;
int a[N],s[N];
vector<int> v;
void solve(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		int x=a[i];
		while(x){
			v.push_back(x);
			x/=2;
		}
    }
	int ans=1e18;
	for(int ii=0;ii<v.size();ii++){
		int sum=0;
		for(int i=1;i<=n;i++) s[i]=1e18;
		for(int i=1;i<=n;i++){
			int x=a[i];
			if(a[i]<=v[ii]){
				s[i]=(v[ii]-a[i]);
			}else{
				int cnt=0;
				int y=v[ii];
				while(y<=x){
					s[i]=min(s[i],cnt+abs(y-x));
					cnt++;
					x/=2;
				}
			}
		}
		sort(s+1,s+n+1);
		for(int i=1;i<=n-m;i++) sum+=s[i];
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
}
signed main(){
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5732kb

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: 339ms
memory: 5732kb

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:

485
3
483
116
617
663
1057
241
678
55

result:

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