QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#528077#2528. Mobile RobotTahmid76AC ✓412ms23064kbC++202.3kb2024-08-23 06:46:462024-08-23 06:46:46

Judging History

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

  • [2024-08-23 06:46:46]
  • 评测
  • 测评结果:AC
  • 用时:412ms
  • 内存:23064kb
  • [2024-08-23 06:46:46]
  • 提交

answer

//And He found you lost and guided [you] [93:07]

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef map<int,int> mpi;
typedef map<ll,ll> mpl;
typedef unordered_map<int,int> umpi;
typedef unordered_map<ll,ll> umpl;

#define modu 998244353 
#define mod 1000000007
#define eps 1e-7
#define inf 1000000000000000006
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define pi acos(-1.0)
#define dec(n) fixed << setprecision(n)
#define N 3000005
#define int long long

int n,d,a[N];
int c[N];
int f(int sft){
	
	c[1]=a[1];
	int f1=1,del1=0;
	c[1]-=sft;
	for(int i=2;i<=n;i++){
		c[i]=c[i-1]+d;
		if(c[i]>a[i]+sft) f1=0;
		int gap=max(0LL,a[i]-sft-c[i]);
		c[i]=c[i]+gap;
		del1+=gap; 
		if(del1>2*sft) f1=0;
		// cout << gap << " ";

	}
	if(del1>2*sft) f1=0;
	c[1]=a[1];
	c[1]-=sft;
	for(int i=2;i<=n;i++) c[i]=c[i-1]+d;
	for(int i=1;i<=n;i++){
		if(del1+c[i]>a[i]+sft) f1=0;
	}

	c[1]=a[1];
	int f2=1,del2=0;
	c[1]+=sft;
	for(int i=2;i<=n;i++){
		c[i]=c[i-1]-d;
		if(c[i]<a[i]-sft) f2=0;
		int gap=max(0LL,c[i]-a[i]-sft);
		c[i]=c[i]-gap;
		del2+=gap; 
		if(del2>2*sft) f2=0;

	}
	c[1]=a[1];
	c[1]+=sft;
	for(int i=2;i<=n;i++) c[i]=c[i-1]-d;

	for(int i=1;i<=n;i++){
		if(c[i]-del2<a[i]-sft) f2=0;
	}

	if(del2>2*sft) f2=0;


	return (f1 || f2);

}



void solve(){
	cin >> n >> d;
	for(int i=1;i<=n;i++) cin >> a[i],a[i]*=2;

	d*=2;

	// cout << f(21) << endl;
	

	int lo=0,hi=2e18+5,ans=-1;
	while(lo<=hi){
		int mid=(lo+hi)/2;
		if(f(mid)){
			ans=mid;
			hi=mid-1;
		}
		else lo=mid+1;
	}

	// cout << ans << endl;

	cout << ans/2 << ".";
	if(ans%2) cout << 5 << endl;
	else cout << 0 << endl;

	
}


signed main(){
    fastio;
    //srand(chrono::steady_clqk::now().time_since_epqh().count());
    // fflush(stdout);
    int T=1,cs=0;
    // cin >> T;
    while(T--){
        //cout << "Case " << ++cs << ": " ; 
        solve();
    } 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 1
-1 1

output:

0.5

result:

ok single line: '0.5'

Test #2:

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

input:

2 1
0 1

output:

0.0

result:

ok single line: '0.0'

Test #3:

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

input:

2 1
0 0

output:

0.5

result:

ok single line: '0.5'

Test #4:

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

input:

2 1
-10000000000000000 10000000000000000

output:

9999999999999999.5

result:

ok single line: '9999999999999999.5'

Test #5:

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

input:

2 10000000000
0 0

output:

5000000000.0

result:

ok single line: '5000000000.0'

Test #6:

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

input:

2 10000000000
-10000000000000000 10000000000000000

output:

9999995000000000.0

result:

ok single line: '9999995000000000.0'

Test #7:

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

input:

10 1
0 1 2 3 4 5 6 7 8 9

output:

0.0

result:

ok single line: '0.0'

Test #8:

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

input:

10 1
9 8 7 6 5 4 3 2 1 0

output:

0.0

result:

ok single line: '0.0'

Test #9:

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

input:

10 3
0 1 2 3 4 5 6 7 8 9

output:

9.0

result:

ok single line: '9.0'

Test #10:

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

input:

5 1
1 3 5 7 9

output:

2.0

result:

ok single line: '2.0'

Test #11:

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

input:

10 3
9 8 7 6 5 4 3 2 1 0

output:

9.0

result:

ok single line: '9.0'

Test #12:

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

input:

3 1
1 3 2

output:

1.0

result:

ok single line: '1.0'

Test #13:

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

input:

6 1
3 1 2 5 6 4

output:

2.0

result:

ok single line: '2.0'

Test #14:

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

input:

6 1
4 6 5 2 1 3

output:

2.0

result:

ok single line: '2.0'

Test #15:

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

input:

10 1
6 7 8 9 10 1 2 3 4 5

output:

4.0

result:

ok single line: '4.0'

Test #16:

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

input:

10 10
6 7 8 9 10 1 2 3 4 5

output:

44.5

result:

ok single line: '44.5'

Test #17:

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

input:

6 2
6 3 5 2 4 1

output:

3.5

result:

ok single line: '3.5'

Test #18:

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

input:

10 10000000000
60000000000 70000000000 80000000000 90000000000 100000000000 10000000000 20000000000 30000000000 40000000000 50000000000

output:

40000000000.0

result:

ok single line: '40000000000.0'

Test #19:

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

input:

10 10000000000
6000000000 7000000000 8000000000 9000000000 10000000000 1000000000 2000000000 3000000000 4000000000 5000000000

output:

44500000000.0

result:

ok single line: '44500000000.0'

Test #20:

score: 0
Accepted
time: 338ms
memory: 23064kb

input:

1000000 10000000000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

4999995000000000.0

result:

ok single line: '4999995000000000.0'

Test #21:

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

input:

5 1
-10 -1 0 1 2

output:

4.0

result:

ok single line: '4.0'

Test #22:

score: 0
Accepted
time: 357ms
memory: 20576kb

input:

1000000 10000000000
0 1 1 0 0 0 0 -1 -1 1 -1 1 1 0 0 1 -1 1 -1 0 -1 0 -1 1 0 -1 0 -1 -1 -1 1 -1 0 0 1 -1 -1 1 0 0 1 -1 0 1 -1 0 -1 -1 1 -1 1 1 1 -1 0 1 0 0 1 0 1 -1 -1 -1 1 -1 1 0 -1 0 -1 0 0 1 0 1 0 -1 1 -1 0 1 1 0 -1 -1 -1 -1 -1 0 0 0 -1 0 1 1 0 0 0 -1 0 0 -1 -1 0 0 0 0 0 1 -1 1 -1 -1 -1 0 1 1 -1 ...

output:

4999994999999999.5

result:

ok single line: '4999994999999999.5'

Test #23:

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

input:

100000 1
-583 -8612 9722 -7985 6287 -671 9562 1102 8059 2711 -3166 3225 -8812 -3552 4408 2427 -5229 -9081 -6166 -39 8916 6657 8360 4473 3772 -2598 -1926 -9411 -4413 -5907 -3789 8189 -6980 -592 -3938 7243 -532 234 -5638 9313 4463 9685 -9131 -4109 7652 6911 1949 8427 2683 9987 1179 -8673 2855 -7231 -5...

output:

59762.5

result:

ok single line: '59762.5'

Test #24:

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

input:

100000 1
-99999198 -99999108 -99998834 -99996290 -99991027 -99989962 -99989632 -99988683 -99988479 -99985044 -99982846 -99980801 -99979883 -99977995 -99977143 -99976759 -99976173 -99974386 -99972813 -99972100 -99972092 -99970648 -99968555 -99965699 -99956729 -99955536 -99955208 -99954776 -99953136 -...

output:

99945970.0

result:

ok single line: '99945970.0'

Test #25:

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

input:

100000 1
99996546 99994746 99993446 99991809 99991807 99989710 99987260 99985166 99984943 99982711 99982670 99981566 99981536 99980278 99978158 99977455 99976140 99974738 99973887 99973549 99972752 99972441 99971965 99970660 99966851 99965071 99962198 99958006 99957716 99956710 99956550 99954040 999...

output:

99946766.5

result:

ok single line: '99946766.5'

Test #26:

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

input:

100000 1
-63599340 12134713 14751569 60639761 -90502770 75549834 -25390776 -61747336 18399163 96473627 -72006887 -51730439 -58472860 46064147 -21090910 93175920 35584787 -47336139 15585442 -27004203 28050022 -96893447 -95486116 49304408 72597016 51420075 45158032 48934563 80465443 -67840657 64977536...

output:

100030041.5

result:

ok single line: '100030041.5'

Test #27:

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

input:

100000 1000
-99998653 -99997283 -99997207 -99993344 -99993221 -99989301 -99988498 -99987235 -99985616 -99984333 -99984030 -99983971 -99983517 -99978650 -99978615 -99975625 -99972542 -99971852 -99970274 -99969420 -99968654 -99968616 -99965684 -99964794 -99963302 -99962056 -99960461 -99959474 -9995164...

output:

49998365.5

result:

ok single line: '49998365.5'

Test #28:

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

input:

100000 1000
99999570 99997740 99993133 99991390 99990818 99987647 99987194 99985627 99985192 99982035 99980198 99979859 99978140 99977104 99976435 99975789 99971892 99971515 99970655 99970146 99969234 99969014 99964893 99962544 99961272 99960786 99960433 99955264 99954950 99954902 99953919 99953852 ...

output:

50000439.5

result:

ok single line: '50000439.5'

Test #29:

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

input:

100000 1000
60856084 58148277 -4078235 62006072 -46939709 -98974060 -90491178 65748897 -57667627 36358869 -69476135 31710701 10175494 27319898 51657888 -3333605 -54246412 -91277680 -52546893 32456378 -47098095 18480664 1125344 13552648 -66061096 59906349 -57901943 29702663 -12300872 -67549268 -46802...

output:

149231358.0

result:

ok single line: '149231358.0'

Test #30:

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

input:

100000 10000000000
-9999913514792555 -9999128892345250 -9999006091972906 -9998876100702433 -9998738918995215 -9998497323420770 -9998320530856243 -9998038070684528 -9997971825613071 -9997877023005087 -9997870875964035 -9997562514859003 -9997552544847586 -9997531406772320 -9997449292594299 -9997387525...

output:

9499951420165972.5

result:

ok single line: '9499951420165972.5'

Test #31:

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

input:

100000 10000000000
9999957541295902 9999632341124299 9999392393744950 9999381693997579 9999338275167607 9999302055371418 9999235051177623 9999199187793994 9999183323685659 9999040344648342 9998536329432919 9998446773732239 9998380374074851 9998267316342805 9998215699538013 9998166995278016 999814080...

output:

9499976469102441.0

result:

ok single line: '9499976469102441.0'

Test #32:

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

input:

5 1
1 3 5 9 7

output:

2.5

result:

ok single line: '2.5'

Test #33:

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

input:

100000 10000000000
527679965270656 4910624838155323 3360731978533770 -116923838921508 8957268581890059 8780184453949832 555462578045670 -1514351557304302 -8008533364424397 1020835987517356 4682713484421501 -7503788766591770 7721715657910399 -8096545589847009 7319936981859888 -9938672293049364 873686...

output:

10480796877067284.5

result:

ok single line: '10480796877067284.5'

Test #34:

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

input:

100000 10000000000
-8459079513468224 4374521065795150 5263873516806124 -3824771801533216 9703621014180336 -4756270229411288 -8389013308864992 -3799247487813073 8253907285461284 2844946003788844 3736384833747798 5619288358174746 -7917373545902608 6413580173533839 -4624243785223537 7063534276004728 73...

output:

10465286562786960.5

result:

ok single line: '10465286562786960.5'

Test #35:

score: 0
Accepted
time: 412ms
memory: 22308kb

input:

1000000 10000000000
-4318654196863554 -275219619888671 5562193313500056 4178195030673104 4629750747293997 570434976128040 3653712382065689 -4732093332522913 -5688219122038859 9735702724899422 -1152617053491218 -5720356980411951 -986092999891608 -1552612161361996 -1519536678995098 -2581715135338536 4...

output:

14975895551334817.0

result:

ok single line: '14975895551334817.0'

Test #36:

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

input:

5 1
1 1 1 1 1

output:

2.0

result:

ok single line: '2.0'