QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#378278#8572. Passing Gameucup-team1004#WA 66ms50932kbC++141.3kb2024-04-06 10:44:002024-04-06 10:44:00

Judging History

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

  • [2024-04-06 10:44:00]
  • 评测
  • 测评结果:WA
  • 用时:66ms
  • 内存:50932kb
  • [2024-04-06 10:44:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
typedef long long ll;
int T,n,k,x[N],a[N],p[N];
ll f[N][60],ans;
void getmin(ll &a,ll b){if(a>b)a=b;}
void work(int u,int v,int w,int m)
{
	for(int i=0;i<=k;i++) f[u][i]=f[v][i]+1ll*a[v]*abs(x[u]-x[v]);
	for(int i=1;i<=k;i++) getmin(f[u][i],f[w][i-1]+1ll*a[w]*abs(x[w]-x[u]));
	for(int i=0;i<=m;i++) getmin(ans,f[u][i]+1ll*a[u]*abs(x[u]-x[n]));
}
vector<int> v1,v2;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&k);
		k=min(50,k);
		for(int i=1;i<=n;i++) scanf("%d",&x[i]),p[i]=i;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		if(n==1) {puts("0");continue;}
		sort(p+1,p+n+1,[](int a,int b){return x[a]<x[b];});
		int w=0;
		for(int i=1;i<=n;i++) if(p[i]==1) w=i;
		v1.clear(),v2.clear();
		v1.push_back(1),v2.push_back(1);
		for(int i=w+1;i<=n;i++)
			if(a[v1.back()]>a[p[i]]) v1.push_back(p[i]);
		for(int i=w-1;i;i--)
			if(a[v2.back()]>a[p[i]]) v2.push_back(p[i]);
		ans=1ll*a[1]*abs(x[1]-x[n]);
		for(int i=0;i<=k;i++) f[1][0]=0;
		int p1=(x[n]>x[1]);
		for(int i=0,j=0,n1=v1.size(),n2=v2.size();!(i==n1-1&&j==n2-1);)
		{
			if(i==n1-1||(j<n2-1&&a[v2[j+1]]<a[v1[i+1]])) work(v2[j+1],v2[j],v1[i],k-p1),j++;
			else work(v1[i+1],v1[i],v2[j],k-(p1^1)),i++;
		}
		printf("%lld\n",ans);
	}
}

详细

Test #1:

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

input:

2
4 2
3 2 1 6
3 1 1 3
2 0
1 2
1 2

output:

7
1

result:

ok 2 number(s): "7 1"

Test #2:

score: 0
Accepted
time: 59ms
memory: 36900kb

input:

1
300000 204334
809492393 304618667 173130445 377106790 364888630 949045125 622060683 557772818 216607577 848817467 862855568 507840723 120816645 639713488 741781998 682531787 685261161 601686403 355792373 162819930 710057718 234560726 998604853 678957602 485413982 855985802 109303681 979706626 4822...

output:

31313390701066

result:

ok 1 number(s): "31313390701066"

Test #3:

score: -100
Wrong Answer
time: 66ms
memory: 50932kb

input:

3
100000 65460
217141764 710454586 789075415 24849107 685675008 839804815 638763480 327755609 43827967 390187172 301370841 622696676 598237196 232099091 211987715 416876077 572665966 73382836 520033984 808399404 752832432 341795744 434460344 535426588 136624537 997406768 297342165 558882675 26863877...

output:

85901114068933
47230361360721
59110547802683

result:

wrong answer 1st numbers differ - expected: '70635841128944', found: '85901114068933'