Submission #133186

# Submission time Handle Problem Language Result Execution time Memory
133186 2019-07-20T08:52:40 Z sealnot123 Mobile (BOI12_mobile) C++14
100 / 100
362 ms 40608 KB
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef double D;
typedef long double LD;
const int N = 1000007;
vector<PLL> tower;

bool cmp(PLL a, PLL b){
	if(a.x != b.x) return a.x > b.x;
	return a.y < b.y;
}

PLL intersect(PLL a, PLL b){
	LL A, B;
	A = a.y - b.y;
	B = b.x - a.x;
	if(B < 0) A = -A, B = -B;
	return {A, B};
}

vector<PLL> line;

void add(PLL nw){
	while(SZ(line)>1){
		int a = SZ(line);
		if(line[a-1].x == nw.x) return;
		PLL tmp1 = intersect(line[a-2], line[a-1]);
		PLL tmp2 = intersect(line[a-1], nw);
		if((__int128)tmp2.x*(__int128)tmp1.y <= (__int128)tmp1.x*(__int128)tmp2.y) line.pop_back();
		else break;
	}
	line.pb(nw);
}

LD calc(LD a, int b){
	return a*line[b].x + line[b].y;
}

LL L;
int n;

int main(){
	int i,j;
	LL a,b, dist0 = 2e18+2, distL = 2e18+2;
 	LD ans;
	scanf("%d %lld",&n,&L);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&a,&b);
		dist0 = min(dist0, a*a + b*b);
		distL = min(distL, (L-a)*(L-a) + b*b);
		if(tower.empty() || tower.back().x != -a*2) tower.pb({-a*2, a*a + b*b});
		else tower.back().y = min(tower.back().y, a*a + b*b);
	}
	ans = (LD)max(dist0, distL);
	n = SZ(tower);
    for(i=0;i<n;i++) add(tower[i]);
    for(i = 0; i < SZ(line)-1; i++){
    	PLL tmp = intersect(line[i], line[i+1]);
    	LD tmp2 = (LD)tmp.x/tmp.y;
    	if(tmp2 < 0 || tmp2 > L) continue;
    	ans = max(ans, calc(tmp2, i) + tmp2*tmp2);
    }
    printf("%Lf",sqrt(ans));
    return 0;
}
/*
2 10
0 0
11 1

3 10
1 0
5 0
10 0

2 10
-5 3
12 2
*/

Compilation message

mobile.cpp: In function 'int main()':
mobile.cpp:52:8: warning: unused variable 'j' [-Wunused-variable]
  int i,j;
        ^
mobile.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %lld",&n,&L);
  ~~~~~^~~~~~~~~~~~~~~~~
mobile.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&a,&b);
   ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 252 KB Output is correct
4 Correct 4 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 676 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2540 KB Output is correct
2 Correct 23 ms 1748 KB Output is correct
3 Correct 15 ms 1776 KB Output is correct
4 Correct 27 ms 2796 KB Output is correct
5 Correct 12 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 504 KB Output is correct
2 Correct 20 ms 1904 KB Output is correct
3 Correct 26 ms 3052 KB Output is correct
4 Correct 28 ms 3308 KB Output is correct
5 Correct 32 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 4836 KB Output is correct
2 Correct 23 ms 1516 KB Output is correct
3 Correct 25 ms 4936 KB Output is correct
4 Correct 40 ms 2924 KB Output is correct
5 Correct 22 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1484 KB Output is correct
2 Correct 28 ms 1776 KB Output is correct
3 Correct 22 ms 1368 KB Output is correct
4 Correct 39 ms 2924 KB Output is correct
5 Correct 30 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3852 KB Output is correct
2 Correct 28 ms 1836 KB Output is correct
3 Correct 22 ms 1368 KB Output is correct
4 Correct 40 ms 2920 KB Output is correct
5 Correct 31 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 20472 KB Output is correct
2 Correct 117 ms 640 KB Output is correct
3 Correct 115 ms 1236 KB Output is correct
4 Correct 184 ms 8924 KB Output is correct
5 Correct 146 ms 9032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 764 KB Output is correct
2 Correct 142 ms 10456 KB Output is correct
3 Correct 105 ms 5336 KB Output is correct
4 Correct 180 ms 9132 KB Output is correct
5 Correct 151 ms 9016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 34340 KB Output is correct
2 Correct 138 ms 604 KB Output is correct
3 Correct 137 ms 1020 KB Output is correct
4 Correct 225 ms 17304 KB Output is correct
5 Correct 166 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 712 KB Output is correct
2 Correct 174 ms 17416 KB Output is correct
3 Correct 122 ms 4788 KB Output is correct
4 Correct 227 ms 17264 KB Output is correct
5 Correct 188 ms 17180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 188 ms 35948 KB Output is correct
2 Correct 162 ms 484 KB Output is correct
3 Correct 158 ms 1008 KB Output is correct
4 Correct 259 ms 17256 KB Output is correct
5 Correct 183 ms 9068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 712 KB Output is correct
2 Correct 198 ms 17348 KB Output is correct
3 Correct 147 ms 5808 KB Output is correct
4 Correct 257 ms 17224 KB Output is correct
5 Correct 214 ms 17360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 37408 KB Output is correct
2 Correct 186 ms 504 KB Output is correct
3 Correct 182 ms 1024 KB Output is correct
4 Correct 297 ms 17276 KB Output is correct
5 Correct 229 ms 9092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 188 ms 472 KB Output is correct
2 Correct 224 ms 17316 KB Output is correct
3 Correct 166 ms 5604 KB Output is correct
4 Correct 294 ms 17324 KB Output is correct
5 Correct 242 ms 17248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 253 ms 40608 KB Output is correct
2 Correct 228 ms 512 KB Output is correct
3 Correct 222 ms 1004 KB Output is correct
4 Correct 361 ms 16948 KB Output is correct
5 Correct 269 ms 9040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 233 ms 544 KB Output is correct
2 Correct 273 ms 19172 KB Output is correct
3 Correct 211 ms 9180 KB Output is correct
4 Correct 362 ms 16940 KB Output is correct
5 Correct 306 ms 17308 KB Output is correct