QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#185193#5137. TowerPhantomThreshold#WA 16ms5248kbC++20894b2023-09-21 18:38:002023-09-21 18:38:00

Judging History

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

  • [2023-09-21 18:38:00]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:5248kb
  • [2023-09-21 18:38:00]
  • 提交

answer

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

const int maxn = 505;

int n,m;
int a[maxn];
int cost[maxn][maxn];
int b[maxn];

signed main()
{
	ios_base::sync_with_stdio(false); ////////////////////////////////////////
	cin.tie(0);
	
	int Tcase; cin>>Tcase;
	while(Tcase--)
	{
		cin>>n>>m;
		for(int i=1;i<=n;i++) cin>>a[i];
		
		for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)
		{
			if(a[i]<=a[j]) cost[i][j]=a[j]-a[i];
			else
			{
				int temp=0;
				
				int c=a[i];
				while((c>>1)>=a[j]) c>>=1, temp++;
				
				temp+= c-a[j];
				cost[i][j]=temp;
			}
		}
		
		int ans=LLONG_MAX;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++) b[j]= cost[j][i];
			sort(b+1,b+n+1);
			
			int temp=0;
			for(int j=1;j<=n-m;j++) temp+=b[j];
			ans=min(ans,temp);
		}
		cout<<ans<<'\n';
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 16ms
memory: 5248kb

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
494
119
617
663
1057
241
678
55

result:

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