Submission #132030

# Submission time Handle Problem Language Result Execution time Memory
132030 2019-07-18T08:24:45 Z 임유진(#3191) Fences (JOI18_fences) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair

typedef long double ld;
typedef long long lint;
typedef pair<lint, lint> pll;

lint dp(pll a, pll b) { return a.fi * b.fi + a.se * b.se; }
ld len(pll a) { return sqrt((ld) dp(a, a)); } 
pll mns(pll a, pll b) { return mp(a.fi - b.fi, a.se - b.se); }
ld dis(pll a, pll b) { return len(mns(a, b)); }
ld perp(pll u, pll v) { return sqrt(dp(v, v) - (ld) dp(u, v) * dp(u, v) / dp(u, u)); }
void print(pll a) { printf("(%lld, %lld)\n", a.fi, a.se);}

int main() {
	int N, S, A, B, C, D;

	scanf("%d%d", &N, &S);
	if(N != 1) return 0;
	scanf("%d%d%d%d", &A, &B, &C, &D);
	
	if(A + C < 0) {
		A *= -1;
		C *= -1;
	}
	if(B + D < 0) {
		B *= -1;
		D *= -1;
	}
	if(A - B > C - D) {
		swap(A, C);
		swap(B, D);
	}
	//printf("(%d, %d), (%d, %d)\n", A, B, C, D);

	ld ans = 8.0L * S;
	ld a, b;
	pll p1, p2, x, u, v1, v2;
	p1 = mp(A, B), p2 = mp(C, D), u = mns(p2, p1);
	if(A < -S) {
		a = dis(p1, mp(-S, -S));
	}
	else {
		if(B < S || (D < S && u.fi * u.se > 0)) {
			x = mp(S, S);
			a = 4 * S;
		}
		else {
			x = mp(-S, S);
			a = 2 * S;
		}
		//print(x);
		v1 = mns(p1, x), v2 = mns(p2, x);
		//print(u);
		//print(v1);
		if(dp(u, v1) < 0 && dp(u, v2) > 0) {/*printf("*");*/a += perp(u, v1);}
		else a += len(v1);
	}
	swap(A, D);
	swap(B, C);
	//printf("(%d, %d), (%d, %d)\n", A, B, C, D);
	p1 = mp(A, B), p2 = mp(C, D), u = mns(p2, p1);
	if(A < -S) b = dis(p1, mp(-S, -S));
	else {
		if(B < S || (D < S && u.fi * u.se > 0)) {
			x = mp(S, S);
			b = 4 * S;
		}
		else {
			x = mp(-S, S);
			b = 2 * S;
		}
		v1 = mns(p1, x), v2 = mns(p2, x);
		//print(v1);
		if(dp(u, v1) < 0 && dp(u, v2) > 0) {/*printf("*");*/b += perp(u, v1);}
		else b += len(v1);
	}
	ans = min(ans, a + b);
	//printf("a = %Lf, b = %Lf\n", a, b);

	printf("%.20Lf", ans);
	return 0;
}

Compilation message

fences.cpp: In function 'int main()':
fences.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &S);
  ~~~~~^~~~~~~~~~~~~~~~
fences.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &A, &B, &C, &D);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Incorrect 2 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Incorrect 2 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Incorrect 2 ms 376 KB Output isn't correct
14 Halted 0 ms 0 KB -