답안 #742206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742206 2023-05-15T19:03:11 Z rainboy 생물 실험 (IZhO13_expgorl) C++17
100 / 100
2 ms 340 KB
#include <math.h>
#include <stdio.h>
#include <string.h>

#define N	10000
#define INF	1e12

double min(double a, double b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }

long long dot2(int x1, int y1, int x2, int y2) {
	return (long long) x1 * x2 + (long long) y1 * y2;
}

long long dot(int x0, int y0, int x1, int y1, int x2, int y2) {
	return dot2(x1 - x0, y1 - y0, x2 - x0, y2 - y0);
}

int main() {
	static char cc[N + 1];
	static int xx[N + 1], yy[N + 1];
	int n, k, k_, i, x1, y1, x2, y2, x, y, x_, y_;
	double d, mn, mx;

	scanf("%d%s%d%d%d%d", &k, cc, &x1, &y1, &x2, &y2), n = strlen(cc), x_ = x2 - x1, y_ = y2 - y1;
	x = y = 0;
	for (i = 0; i <= n; i++) {
		if (cc[i] == 'L')
			x--;
		if (cc[i] == 'R')
			x++;
		if (cc[i] == 'B')
			y--;
		if (cc[i] == 'F')
			y++;
		xx[i + 1] = x, yy[i + 1] = y;
	}
	mn = INF, mx = 0;
	for (i = 0; i <= n; i++) {
		x1 = x_ + xx[i], y1 = y_ + yy[i], x2 = x_ + xx[i] + xx[n] * (k - 1), y2 = y_ + yy[i] + yy[n] * (k - 1);
		d = hypot(x1, y1);
		mn = min(mn, d), mx = max(mx, d);
		d = hypot(x2, y2);
		mn = min(mn, d), mx = max(mx, d);
		if (dot(x1, y1, x2, y2, 0, 0) > 0 && dot(x2, y2, x1, y1, 0, 0) > 0) {
			k_ = dot2(0 - x1, 0 - y1, xx[n], yy[n]) / dot2(xx[n], yy[n], xx[n], yy[n]);
			d = hypot(x1 + xx[n] * k_, y1 + yy[n] * k_);
			mn = min(mn, d);
			d = hypot(x1 + xx[n] * (k_ + 1), y1 + yy[n] * (k_ + 1));
			mn = min(mn, d);
		}
	}
	printf("%.12f %.12f\n", mn, mx);
	return 0;
}

Compilation message

expgorl.cpp: In function 'int main()':
expgorl.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%d%s%d%d%d%d", &k, cc, &x1, &y1, &x2, &y2), n = strlen(cc), x_ = x2 - x1, y_ = y2 - y1;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 296 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct