QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#824932#172. Optimal TournamentpeimudaWA 4ms5640kbC++111.1kb2024-12-21 16:36:162024-12-21 16:36:16

Judging History

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

  • [2024-12-21 16:36:16]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:5640kb
  • [2024-12-21 16:36:16]
  • 提交

answer

#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#define pr pair
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pll pr<ll,ll>
#define pii pr<int,int>
#define piii pr<int,pii>
using namespace std;
int a[1003];
int dp[1003][1024];
int ppc[1024];
int main()
{
	ios_base::sync_with_stdio(0);
	int n,k;
	cin>>n>>k;
	for(int i=0;i<1024;i++) for(int j=0;j<10;j++) if(i&1<<j) ppc[i]++;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n+1);
	int fm=min(k,10),re=k-fm;
	for(int i=1;i<n;i++) for(int j=0;j<1024;j++) dp[i][j]=1e9;
	for(int i=0;i<n-1;i++) for(int j=0;j<k&&i+j+1<n;j++)
	{
		int g=max(0,j-re);
		int h=a[i+j+1]-a[i],ex=a[i+j+1]-a[i+1];
		int l=1<<g;
		int ci=1e9;
		for(int o=0;o<1<<fm;o++)
		{
			if(o>=l) ci=min(ci,ppc[o-l]*h+dp[i][o-l]+ex);
			dp[i+j+1][o]=min(dp[i+j+1][o],ci);
		}
	}
//	for(int i=0;i<n;i++)
//	{
//		for(int j=0;j<1<<fm;j++) cout<<dp[i][j]<<' ';
//		cout<<endl;
//	}
	int ans=1e9;
	for(int i=0;i<1<<fm;i++) ans=min(ans,dp[n-1][i]+(a[n]-a[n-1])*ppc[i]);
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
1 3 4 7

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

5 3
1 3 4 7 9

output:

10

result:

ok single line: '10'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5640kb

input:

18 7
67 64 52 18 39 92 84 66 19 64 1 66 35 34 45 2 79 34

output:

114

result:

ok single line: '114'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3744kb

input:

9 6
367 964 752 918 139 592 384 166 319

output:

888

result:

ok single line: '888'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3656kb

input:

10 4
166 835 734 145 702 279 334 304 1000 696

output:

1285

result:

ok single line: '1285'

Test #6:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

10 4
110 261 155 560 163 588 766 120 574 886

output:

1230

result:

ok single line: '1230'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

10 4
490 764 478 723 627 138 383 681 666 641

output:

748

result:

ok single line: '748'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

9 6
697 281 465 951 451 369 388 335 332

output:

703

result:

ok single line: '703'

Test #9:

score: -100
Wrong Answer
time: 4ms
memory: 3972kb

input:

96 23
457 244 700 209 664 829 54 27 949 977 221 221 652 920 742 664 540 416 183 456 111 855 348 326 521 731 470 863 139 129 404 475 404 377 534 970 484 303 283 265 662 759 906 849 302 68 470 34 340 710 912 981 461 317 764 155 963 642 870 802 643 636 718 775 197 694 407 814 958 567 921 918 149 918 48...

output:

1505

result:

wrong answer 1st lines differ - expected: '1423', found: '1505'