답안 #131962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131962 2019-07-18T06:58:53 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) - 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;
	if(B < S) a = dis(mp(A, B), mp(S, S)) + 2 * S;
	else {
		pll p1 = mp(A, B), p2 = mp(C, D), x = mp(-S, S);
		pll u = mns(p2, p1), v1 = mns(p1, x), v2 = mns(p2, x);
		//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);
	if(B < S) b = dis(mp(A, B), mp(S, S)) + 2 * S;
	else {
		//printf("!");
		pll p1 = mp(A, B), p2 = mp(C, D), x = mp(-S, S);
		pll u = mns(p2, p1), v1 = mns(p1, x), v2 = mns(p2, x);
		if(dp(u, v1) < 0 && dp(u, v2) > 0) b = perp(u, v1);
		else b = len(v1);
	}
	ans = min(ans, a + b + 4 * S);
	//printf("a = %Lf, b = %Lf\n", a, b);

	printf("%Lf", 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);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 2 ms 376 KB Output isn't correct
8 Halted 0 ms 0 KB -