QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#148858#4897. 音符大师zhouhuanyi15 366ms28540kbC++143.2kb2023-08-23 19:38:582023-08-23 20:31:09

Judging History

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

  • [2023-08-23 20:31:09]
  • 评测
  • 测评结果:15
  • 用时:366ms
  • 内存:28540kb
  • [2023-08-23 19:38:58]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 50003
#define M 5
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
const long long inf=(long long)(1e18);
struct reads
{
	int a,b,data;
	bool operator < (const reads &t)const
	{
		return data<t.data;
	}
};
reads st[N*M+1],st2[N*M+1];
int n,L,p[N+1],length,length2;
long long ans,DP[N+1][M+1],dp[N+1][M+1][M+1],delta[N+1][M+1];
void solve(int l,int r)
{
	if (l==r) return;
	int mid=(l+r)>>1,ps;
	long long minn;
	solve(l,mid),length=length2=0;
	for (int i=l;i<=mid;++i)
		for (int j=0;j<=L;++j)
			st[++length]=(reads){i,j,p[i-1]-j};
	for (int i=mid+1;i<=r;++i)
		for (int j=0;j<=L;++j)
			st2[++length2]=(reads){i,j,p[i]-j};
	sort(st+1,st+length+1),sort(st2+1,st2+length2+1);
	for (int i=0;i<=L;++i)
	{
		for (int j=l;j<=r;++j)
			for (int k=0;k<=L;++k)
				DP[j][k]=inf;
		DP[mid][i]=0;
		for (int j=mid-1;j>=l;--j)
		{
			ps=L+1,minn=inf;
			for (int k=L;k>=0;--k)
			{
				while (ps-1>=0&&p[j+1]-(ps-1)<=p[j]-k) --ps,minn=min(minn,DP[j+1][k]-(p[j+1]-ps));
				DP[j][k]=min(DP[j][k],minn+(p[j]-k));
			}
			ps=-1,minn=inf;
			for (int k=0;k<=L;++k)
			{
				while (ps+1<=L&&p[j+1]-(ps+1)>p[j]-k) ++ps,minn=min(minn,DP[j+1][k]+(p[j+1]-ps));
				DP[j][k]=min(DP[j][k],minn-(p[j]-k));
			}
		}
		for (int j=mid+1;j<=r;++j)
		{
			ps=L+1,minn=inf;
			for (int k=L;k>=0;--k)
			{
				while (ps-1>=0&&p[j-1]-(ps-1)<=p[j]-k) --ps,minn=min(minn,DP[j-1][k]-(p[j-1]-ps));
				DP[j][k]=min(DP[j][k],minn+(p[j]-k));
			}
			ps=-1,minn=inf;
			for (int k=0;k<=L;++k)
			{
				while (ps+1<=L&&p[j-1]-(ps+1)>p[j]-k) ++ps,minn=min(minn,DP[j-1][k]+(p[j-1]-ps));
				DP[j][k]=min(DP[j][k],minn-(p[j]-k));
			}
		}
		ps=0,minn=inf;
		for (int j=1;j<=length2;++j)
		{
			while (ps+1<=length&&st[ps+1].data<=st2[j].data)
			{
				++ps;
				for (int k=0;k<=L;++k) minn=min(minn,dp[st[ps].a][st[ps].b][k]+DP[st[ps].a][k]-st[ps].data);
			}
			for (int k=0;k<=L;++k) dp[st2[j].a][k][st2[j].b]=min(dp[st2[j].a][k][st2[j].b],minn+DP[st2[j].a-1][k]+st2[j].data);
		}
		ps=length+1,minn=inf;
		for (int j=length2;j>=1;--j)
		{
			while (ps-1>=1&&st[ps-1].data>st2[j].data)
			{
				--ps;
				for (int k=0;k<=L;++k) minn=min(minn,dp[st[ps].a][st[ps].b][k]+DP[st[ps].a][k]+st[ps].data);
			}
			for (int k=0;k<=L;++k) dp[st2[j].a][k][st2[j].b]=min(dp[st2[j].a][k][st2[j].b],minn+DP[st2[j].a-1][k]-st2[j].data);
		}
	}
	solve(mid+1,r);
	return;
}
int main()
{
	n=read()+1,L=read(),p[0]=p[1]=0,ans=inf;
	for (int i=1;i<=n;++i)
	{
		for (int j=0;j<=L;++j)
			for (int k=0;k<=L;++k)
				dp[i][j][k]=inf;
		for (int j=0;j<=L;++j) delta[i][j]=inf;
	}
	dp[1][0][0]=0;
	for (int i=2;i<=n;++i) p[i]=read();
	solve(1,n);
	for (int i=1;i<=n;++i)
	{
		for (int j=0;j<=L;++j)
			for (int k=0;k<=L;++k)
				delta[i][k]=min(delta[i][k],dp[i][j][k]);
		if (i!=1)
		{
			for (int j=0;j<=L;++j)
				for (int k=0;k<=L;++k)
					delta[i][j]=min(delta[i][j],delta[i-1][k]+abs((p[i]-j)-(p[i-1]-k)));
		}
	}
	for (int i=0;i<=L;++i) ans=min(ans,delta[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 12152kb

input:

200 20
78 30 163 87 97 53 96 76 81 138 156 200 124 93 173 119 115 93 150 99 22 80 88 131 61 126 47 103 143 142 129 186 89 105 101 143 178 110 13 77 79 178 21 108 200 146 87 105 54 61 136 69 161 195 13 105 18 151 25 191 30 35 90 110 17 98 181 58 120 102 139 71 59 24 72 84 33 12 28 82 23 80 128 96 115...

output:

0

result:

wrong answer 1st lines differ - expected: '3669', found: '0'

Subtask #2:

score: 15
Accepted

Test #19:

score: 15
Accepted
time: 36ms
memory: 26532kb

input:

50000 0
957304147 455870042 888520405 388924006 685268286 213595280 898496267 50362797 310595209 105517171 706682592 663787741 927429771 306122736 1352192 453945549 31881610 943782347 779421515 543589796 209926777 908434673 845417119 374441290 190474943 606994057 30091060 491598457 644246786 4649716...

output:

7861788079227

result:

ok single line: '7861788079227'

Test #20:

score: 0
Accepted
time: 33ms
memory: 25820kb

input:

50000 0
267539818 976941407 232914453 134486565 946077774 327303661 383860856 427463180 82433525 829152030 323047687 114009885 572336732 324540200 312372486 904267355 354174716 897077585 726797234 14815480 56504568 128226636 908533574 690241784 234432089 60842581 4158447 140784062 814696061 27580609...

output:

7502844748010

result:

ok single line: '7502844748010'

Test #21:

score: 0
Accepted
time: 44ms
memory: 25084kb

input:

50000 0
113234313 300322176 223748251 154992665 988783374 705920968 587653430 735106433 339878986 23782050 772071399 43924374 333487655 112104185 388912725 30645653 230657785 50181507 210382459 974636263 84812430 683840330 470879024 352138490 544953829 857016921 83527213 679251552 204113040 48552509...

output:

7819216642612

result:

ok single line: '7819216642612'

Test #22:

score: 0
Accepted
time: 38ms
memory: 27944kb

input:

50000 0
57573834 735491176 585967317 50750966 13561867 538400010 923336660 411978534 229545007 608845964 778611980 433080482 340855878 525841885 436793984 121792438 646117967 157139578 341644163 71379300 980382262 841426801 263042095 570909388 241669384 780525526 306815843 529038526 677693926 272888...

output:

7502087871392

result:

ok single line: '7502087871392'

Test #23:

score: 0
Accepted
time: 40ms
memory: 25632kb

input:

50000 0
150529956 908563845 724316344 71839499 520290302 12371329 763161706 965762834 605485868 377855450 364159073 557572417 13573314 8085996 723464069 322060474 374561435 448408270 121729850 91335553 69989524 231531526 901985946 472906330 960997677 246590568 401537295 540808342 30457662 978645485 ...

output:

7655855679050

result:

ok single line: '7655855679050'

Test #24:

score: 0
Accepted
time: 41ms
memory: 26968kb

input:

50000 0
940144100 18386479 769788658 44738457 90257879 879207970 925016558 964597036 662771443 441833534 638630926 257398005 693370314 852807331 472327316 858562055 874978007 530679568 947674579 7081350 647463115 399061769 81471568 897044511 672282388 395480185 381093973 103836241 52060856 136053749...

output:

7329741440393

result:

ok single line: '7329741440393'

Test #25:

score: 0
Accepted
time: 42ms
memory: 26588kb

input:

50000 0
595877781 416920133 504115297 682623073 942495777 808743152 122852578 564363701 980818902 501483584 374724004 69557753 835258645 860520007 102814074 680949932 29792102 646922045 695269515 161539625 468996996 528287965 284414170 145379630 414176299 532680752 96308272 806611720 849878782 97734...

output:

7372386712114

result:

ok single line: '7372386712114'

Test #26:

score: 0
Accepted
time: 41ms
memory: 25452kb

input:

50000 0
236037002 215233133 41019240 229757515 806834959 849843304 862557844 39545138 297402862 7293515 880125105 285706647 152887583 198537021 740552834 3427605 366976152 641734017 106888137 154277089 259614856 518826105 796155721 132034997 420344028 702041117 117477828 821050418 113096425 2869065 ...

output:

7508382287165

result:

ok single line: '7508382287165'

Test #27:

score: 0
Accepted
time: 39ms
memory: 25404kb

input:

50000 0
428263671 324606118 736973623 961066097 320407929 663897387 328110400 789178775 344241539 34611323 77458169 730418405 89677130 456628708 735813218 665313790 99553725 408359166 161580926 95603740 537817168 587203140 239173276 980655467 73440384 209550435 242679387 923020102 447641965 71570611...

output:

7241590054407

result:

ok single line: '7241590054407'

Test #28:

score: 0
Accepted
time: 37ms
memory: 27152kb

input:

50000 0
848511669 673688847 134042037 382760566 86940474 283461772 923214109 543686174 579545679 713904091 366348707 242716930 5641588 704870794 542778347 296428822 959149832 495183306 649986132 551497587 550623110 591035272 204338017 214181048 891861232 524406707 448388519 594832891 610827442 93698...

output:

7606261035748

result:

ok single line: '7606261035748'

Test #29:

score: 0
Accepted
time: 36ms
memory: 26408kb

input:

50000 0
532965906 613164218 854565797 576587516 227406875 115434558 767691663 854474298 982611179 969491137 234543738 69267955 646968047 897911688 721008706 422527377 387136261 762884658 51918347 448273062 574144173 857719871 888425078 575352222 730868624 568669670 590036983 778842602 259437307 7201...

output:

7641479018806

result:

ok single line: '7641479018806'

Test #30:

score: 0
Accepted
time: 38ms
memory: 25032kb

input:

50000 0
950114012 924063984 78459732 2585137 167568618 422620546 817141675 939136111 912071559 28108367 138440975 401623398 614543476 413859636 583198666 7145092 692094019 896479223 265275914 14852033 553761091 831725889 256534067 178236755 434539705 610839223 807151106 140182765 324816595 576215181...

output:

7740448798710

result:

ok single line: '7740448798710'

Test #31:

score: 0
Accepted
time: 32ms
memory: 26204kb

input:

49983 0
500000001 500000002 500000003 500000004 500000005 499999994 499999993 499999992 500000009 500000010 499999989 500000012 499999987 499999986 499999985 500000016 500000017 500000018 500000019 500000020 500000021 499999978 500000023 500000024 500000025 499999974 499999973 500000028 500000029 50...

output:

1000099953

result:

ok single line: '1000099953'

Test #32:

score: 0
Accepted
time: 33ms
memory: 25264kb

input:

49993 0
499999999 500000002 499999997 500000004 500000005 500000006 500000007 499999992 500000009 500000010 500000011 500000012 500000013 499999986 500000015 499999984 500000017 500000018 500000019 500000020 499999979 499999978 500000023 499999976 500000025 499999974 500000027 500000028 500000029 50...

output:

1000099975

result:

ok single line: '1000099975'

Test #33:

score: 0
Accepted
time: 27ms
memory: 25396kb

input:

49973 0
500049973 499950028 500049971 499950030 500049969 499950032 499950033 500049966 499950035 499950036 499950037 500049962 499950039 499950040 499950041 499950042 499950043 499950044 500049955 500049954 500049953 499950048 500049951 499950050 499950051 500049948 500049947 499950054 499950055 50...

output:

1000099943

result:

ok single line: '1000099943'

Test #34:

score: 0
Accepted
time: 30ms
memory: 26680kb

input:

49915 0
500049915 500049914 500049913 500049912 500049911 500049910 500049909 499950092 499950093 499950094 500049905 499950096 499950097 499950098 500049901 499950100 499950101 500049898 499950103 500049896 500049895 499950106 499950107 500049892 500049891 499950110 499950111 500049888 500049887 50...

output:

1000099826

result:

ok single line: '1000099826'

Test #35:

score: 0
Accepted
time: 40ms
memory: 25996kb

input:

49988 0
498700312 495251235 501399608 499800060 498600448 503198912 504498380 498600532 496801280 503548509 497001320 501749195 500949544 502698650 495852158 497701242 499700168 500449739 495452730 495452821 504547088 502448383 503497620 497451785 500299784 495503330 503597264 501298986 496602720 49...

output:

38221665124

result:

ok single line: '38221665124'

Test #36:

score: 0
Accepted
time: 33ms
memory: 26276kb

input:

49980 0
861023239 819075173 824051456 830302098 868589663 916145572 954591723 979803571 998257840 22234729 68881831 35652996 8950761 967484878 964486638 940432553 916275761 928066101 896502131 848012777 841104435 861529167 903652074 939883118 940734108 981052781 951525008 994619188 22352207 1107682 ...

output:

1157487018739

result:

ok single line: '1157487018739'

Test #37:

score: 0
Accepted
time: 41ms
memory: 25560kb

input:

49966 0
852476251 835825994 822071673 774983009 726653125 713373455 725480626 715895559 671128277 642628571 609231701 621486354 601283796 615038192 639110541 641191588 672075707 707629014 738623890 760026457 798462033 833851537 853325404 870571810 895994097 899272379 889729666 849980053 859731156 88...

output:

1142099399674

result:

ok single line: '1142099399674'

Subtask #3:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #38:

score: 0
Wrong Answer
time: 366ms
memory: 28540kb

input:

50000 4
93134491 89313862 124691008 802991790 331181139 197882475 116544590 671508371 708702108 912388931 987332709 138451461 599145073 190259268 63842545 907913440 267186576 871474853 47940039 883678467 296713066 614786363 619945826 972153052 459383869 892979253 124879587 476608391 630338859 858860...

output:

7833583485415

result:

wrong answer 1st lines differ - expected: '7338303040315', found: '7833583485415'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%