Submission #445962

# Submission time Handle Problem Language Result Execution time Memory
445962 2021-07-20T09:35:03 Z Qw3rTy Mobile (BOI12_mobile) C++11
50 / 100
1000 ms 31544 KB
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
#define db double
#define delta 1e-5
#define INF 1e9+5
#define pi pair<int,int>
#define pb pair<db,db>
#define fi first
#define se second
using namespace std;

const int maxN = 1e6+5;

int N,L;
pi tower[maxN];
pb inter[maxN]; //intersections

bool cmp(pb a, pb b){
	if(abs(a.fi - b.fi) < delta)return a.se < b.se;
	return a.fi < b.fi;
}

bool works(db r){
	//Reset inter array
	for(int i = 1; i <= N; ++i){
		inter[i].fi = 0;
		inter[i].se = -1;
	}
	for(int i = 1; i <= N; ++i) {
		//Can't reach any point on the highway
		if (abs(r) < abs(tower[i].se))continue;
		inter[i].fi = tower[i].fi - sqrt(r*r - tower[i].se*tower[i].se);
		inter[i].se = tower[i].fi + sqrt(r*r - tower[i].se*tower[i].se);
		inter[i].fi = (inter[i].fi < 0)?0:inter[i].fi;
		inter[i].se = (inter[i].se > L)?L:inter[i].se;
	}
	sort(inter+1,inter+N+1,cmp);
	db a = 0; db b = 0;
	if(abs(inter[1].fi) > delta)return false;
	for(int i = 1; i <= N; ++i){
		//Invalid intersections
		if(inter[i].fi > inter[i].se)continue;
		//Merge intervals
		if(inter[i].fi <= b)b = (inter[i].se > b)?inter[i].se:b;
		else return false;
		if(abs(b-L) < delta)return true;
	}
	return false;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("../test.in","r",stdin);
	cin >> N >> L;
	for(int i = 1; i <= N; ++i)cin >> tower[i].fi >> tower[i].se;
	db low = 1; db high = 2e9;
	while(abs(high-low) > delta){
		db mid = (low+high)/2;
		if(works(mid))high = mid;
		else low = mid + delta;
	}
	cout << setprecision(12) << low  << '\n';
	return 0;
}

Compilation message

mobile.cpp: In function 'bool works(double)':
mobile.cpp:41:5: warning: unused variable 'a' [-Wunused-variable]
   41 |  db a = 0; db b = 0;
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 420 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
3 Correct 3 ms 336 KB Output is correct
4 Correct 5 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 492 KB Output is correct
2 Correct 11 ms 628 KB Output is correct
3 Correct 14 ms 460 KB Output is correct
4 Correct 11 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 460 KB Output is correct
2 Correct 11 ms 460 KB Output is correct
3 Correct 12 ms 528 KB Output is correct
4 Correct 11 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 588 KB Output is correct
2 Correct 15 ms 464 KB Output is correct
3 Correct 13 ms 460 KB Output is correct
4 Correct 12 ms 460 KB Output is correct
5 Correct 9 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 2652 KB Output is correct
2 Correct 261 ms 3788 KB Output is correct
3 Correct 182 ms 2612 KB Output is correct
4 Correct 166 ms 3840 KB Output is correct
5 Correct 96 ms 2268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 2764 KB Output is correct
2 Correct 147 ms 3328 KB Output is correct
3 Correct 172 ms 3876 KB Output is correct
4 Correct 167 ms 3992 KB Output is correct
5 Correct 182 ms 4528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 3064 KB Output is correct
2 Correct 284 ms 2872 KB Output is correct
3 Correct 324 ms 3916 KB Output is correct
4 Correct 215 ms 5412 KB Output is correct
5 Correct 189 ms 4036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 3404 KB Output is correct
2 Correct 370 ms 4852 KB Output is correct
3 Correct 372 ms 4548 KB Output is correct
4 Correct 217 ms 5400 KB Output is correct
5 Correct 245 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 3404 KB Output is correct
2 Correct 392 ms 4856 KB Output is correct
3 Correct 404 ms 4476 KB Output is correct
4 Correct 224 ms 5412 KB Output is correct
5 Correct 207 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 15964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 15940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 19012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 19084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 22124 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 22212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 25336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 25276 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 31520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 31544 KB Time limit exceeded
2 Halted 0 ms 0 KB -