QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#528073#2528. Mobile RobotTahmid76WA 9ms7300kbC++202.3kb2024-08-23 06:42:392024-08-23 06:42:39

Judging History

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

  • [2024-08-23 06:42:39]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:7300kb
  • [2024-08-23 06:42:39]
  • 提交

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 300005
#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=2e16+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: 5748kb

input:

2 1
-1 1

output:

0.5

result:

ok single line: '0.5'

Test #2:

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

input:

2 1
0 1

output:

0.0

result:

ok single line: '0.0'

Test #3:

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

input:

2 1
0 0

output:

0.5

result:

ok single line: '0.5'

Test #4:

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

input:

2 1
-10000000000000000 10000000000000000

output:

9999999999999999.5

result:

ok single line: '9999999999999999.5'

Test #5:

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

input:

2 10000000000
0 0

output:

5000000000.0

result:

ok single line: '5000000000.0'

Test #6:

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

input:

2 10000000000
-10000000000000000 10000000000000000

output:

9999995000000000.0

result:

ok single line: '9999995000000000.0'

Test #7:

score: 0
Accepted
time: 0ms
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: 5704kb

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: 5748kb

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: 0ms
memory: 5692kb

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: 5700kb

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: 5628kb

input:

3 1
1 3 2

output:

1.0

result:

ok single line: '1.0'

Test #13:

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

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: 5688kb

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: 5752kb

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: 5636kb

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: 0ms
memory: 5624kb

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: 5616kb

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: 5640kb

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: -100
Wrong Answer
time: 9ms
memory: 7300kb

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:

0.0

result:

wrong answer 1st lines differ - expected: '4999995000000000.0', found: '0.0'