Submission #529071

# Submission time Handle Problem Language Result Execution time Memory
529071 2022-02-22T05:21:02 Z yungyao Fences (JOI18_fences) C++17
0 / 100
1 ms 316 KB
using namespace std;
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>

typedef long long LL;
typedef pair<int,int> pii;
#define pb push_back
#define mkp make_pair
#define F first
#define S second
#define iter(x) x.begin(),x.end()
#define REP(n) for (int __=n;__--;)
#define REP0(i, n) for (int i=0;i<n;++i)
#define REP1(i, n) for (int i=1;i<=n;++i)

const int maxn = 105, mod = 0;
const LL inf = 0;

#include <cmath>
typedef pair<double, double> poi;
#define x first
#define y second
poi operator-(poi a, poi b){
	return mkp(a.x - b.x, a.y - b.y);
}
poi operator+(poi a, poi b){
	return mkp(a.x + b.x, a.y + b.y);
}
poi operator*(poi a, double k){
	return mkp(a.x * k, a.y * k);
}
poi operator-(poi a){
	return mkp(-a.x, -a.y);
}
double dot(poi a, poi b){
	return a.x * b.x + a.y * b.y;
}
double cross(poi a, poi b){
	return a.x * b.y - b.x * a.y;
}
double abs2(poi a){
	return dot(a, a);
}
double abs(poi a){
	return sqrt(abs2(a));
}
/*
bool inseg(poi t, poi a, poi b){
	if (cross(a - t, b - t)) return false;
	return dot(a - t, b - t) <= 0;
}
bool intersect(poi a, poi b, poi c, poi d){
	if (inseg(a, c, d) or inseg(b, c, d) or inseg(c, a, b) or inseg(d, a, b)) return false;
	return ((cross(b - a, c - a) < 0) ^ (cross(b - a, d - a) < 0)) and ((cross(a - c, d - c) < 0) ^ (cross(b - c, d - c) < 0));
}*/
#include <iomanip>

void solve(){
	int n, s;
    poi	a, b;

	cin >> n >> s >> a.x >> a.y >> b.x >> b.y;
	if (dot(mkp(1, 1), a - b) < 0) swap(a, b);
	if (cross(mkp(1, 1), a - b) > 0){
		a = mkp(a.y, -a.x);
		b = mkp(b.y, -b.x);
	}
	if (a.x > b.x) swap(a, b);
	poi na = a;
	if (a.x < -s) na = a + (b - a) * ((-s - a.x) / (b.x - a.x));
	if (na.y < 0){a.y = -a.y; b.y = -b.y;}
	double d = 0;
	if (dot(b - a, mkp(-s, s) - a) <= 0) d += abs(a - mkp(-s, s));
	else d += abs((-s - a.x) * (b.y - a.y) + (s - a.y) * (a.x - b.x));
	if (dot(a - b, mkp(s, s) - b) <= 0) d += abs(b - mkp(s, s));
	else d += abs((s - a.x) * (b.y - a.y) + (s - a.y) * (a.x - b.x));
	cout << fixed << setprecision(15) << s * 6 + min(s * 2.0, d);
	//cout << '\n' << a.x << ',' << a.y << ' ' << b.x << ',' << b.y;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Incorrect 0 ms 312 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Incorrect 0 ms 312 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Incorrect 0 ms 312 KB Output isn't correct
6 Halted 0 ms 0 KB -