Submission #968610


Source Code Expand

#include<bits/stdc++.h>
#define EPS (1e-10)
#define equals(a,b)(fabs((a)-(b))<EPS)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

struct Point {
	double x, y;
	Point(double x = 0, double y = 0) :x(x), y(y) {}
	Point operator*(double a) { return Point(a*x, a*y); }
	Point operator-(Point p) { return Point(x - p.x, y - p.y); }
	Point operator+(Point p) { return Point(x + p.x, y + p.y); }
	Point operator/(double a) { return Point(x / a, y / a); }
	double norm() { return x*x + y*y; }
};
typedef vector<Point>Polygon;
typedef Point Vector;
struct Segment {
	Point p1, p2;
};
double cross(Point a, Point b) {
	return a.x*b.y - a.y*b.x;
}
double dot(Point a, Point b) {
	return a.x*b.x + a.y*b.y;
}
bool isPrallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool isOrthogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
int contains(Polygon g, Point p) {
	int n = g.size();
	bool x = false;
	rep(i, n) {
		Point a = g[i] - p, b = g[(i + 1) % n] - p;
		if (abs(cross(a, b)) < EPS&&dot(a, b) < EPS)return 1;
		if (a.y > b.y)swap(a, b);
		if (a.y < EPS&&EPS<b.y&&cross(a, b)>EPS)x = !x;
	}
	return x ? 2 : 0;
}
int ccw(Point p0, Point p1, Point p2) {
	Point a = p1 - p0;
	Point b = p2 - p0;
	if (cross(a, b) > EPS)return 1;
	if (cross(a, b) < -EPS)return -1;
	if (dot(a, b) < -EPS)return 2;
	if (a.norm() < b.norm())return -2;
	return 0;
}
bool intersect(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3)*ccw(p1, p2, p4) <= 0 &&
		ccw(p3, p4, p1)*ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point project(Segment s, Point p) {
	Point base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}
Point reflect(Segment s, Point p) {
	return p + (project(s, p) - p)*2.0;
}
bool isconvex(Polygon g) {
	int back = 3;
	rep(i, g.size()) {
		int d = ccw(g[(i + g.size() - 1) % g.size()], g[i], g[(i + 1) % g.size()]);
		if (back != 3 && d != back)
			return false;
		else back = d;
	}
	return true;
}
double area(Polygon g) {
	double cnt = 0;
	rep(i, g.size())
		cnt += g[i].x*g[(i + 1) % g.size()].y - g[(i + 1) % g.size()].x*g[i].y;
	return abs(cnt) / 2;
}
double norm(Vector a) {
	return a.x*a.x + a.y*a.y;
}
double abs(Vector a) {
	return sqrt(norm(a));
}
typedef Segment Line;
class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

pair<Point, Point>getC(Circle c, Line l) {
	Vector pr = project(l, c.c);
	Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
	double base = sqrt(c.r*c.r - norm(pr - c.c));
	return make_pair(pr + e*base, pr - e*base);
}
int main() {
	double r, n, m; cin >> r >> n >> m;
	Circle c({ 0., r }, r);
	double ans = 0;
	for (double j = 1; j <= n + m - 1; j++) {
		double i = ((2. * r) / n)*j, k = ((2.*r) / n)*(j - m);
		if (j - m <= 0) {
			Line l={ { -(1e7), i }, { 1e7, i }};
			auto p1 = getC(c, { { -(1e7),i } ,{ 1e7,i } });
			ans += sqrt(abs(p1.first.x - p1.second.x)*abs(p1.first.x - p1.second.x) + abs(p1.first.y - p1.second.y)*abs(p1.first.y - p1.second.y));
		}
		else if (j >= n - 1) {
			auto p2 = getC(c, { { -(1e7),k }, { 1e7,k }});
			ans += sqrt(abs(p2.first.x - p2.second.x)*abs(p2.first.x - p2.second.x) + abs(p2.first.y - p2.second.y)*abs(p2.first.y - p2.second.y));
		}
		else {
			auto p1 = getC(c, { {-(1e7),i} ,{1e7,i} }), p2 = getC(c, { {-(1e7),k},{1e7,k } });
			ans += max(sqrt(abs(p1.first.x - p1.second.x)*abs(p1.first.x - p1.second.x) + abs(p1.first.y - p1.second.y)*abs(p1.first.y - p1.second.y)),
				sqrt(abs(p2.first.x - p2.second.x)*abs(p2.first.x - p2.second.x) + abs(p2.first.y - p2.second.y)*abs(p2.first.y - p2.second.y)));
		}
	}
	printf("%.15lf\n", ans);
}

Submission Info

Submission Time
Task B - ステップカット
User autumn_eel
Language C++14 (GCC 5.4.1)
Score 200
Code Size 3895 Byte
Status AC
Exec Time 10 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 16
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 10_rand_05.txt, 10_rand_06.txt, 10_rand_07.txt, 10_rand_08.txt, 20_hand_01.txt, 20_hand_02.txt, 20_hand_03.txt, 20_hand_04.txt, 20_hand_05.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 3 ms 256 KB
00_example_02.txt AC 3 ms 256 KB
00_example_03.txt AC 9 ms 256 KB
10_rand_01.txt AC 3 ms 256 KB
10_rand_02.txt AC 3 ms 256 KB
10_rand_03.txt AC 6 ms 256 KB
10_rand_04.txt AC 3 ms 256 KB
10_rand_05.txt AC 3 ms 256 KB
10_rand_06.txt AC 3 ms 256 KB
10_rand_07.txt AC 4 ms 256 KB
10_rand_08.txt AC 3 ms 256 KB
20_hand_01.txt AC 9 ms 256 KB
20_hand_02.txt AC 10 ms 256 KB
20_hand_03.txt AC 9 ms 256 KB
20_hand_04.txt AC 3 ms 256 KB
20_hand_05.txt AC 3 ms 256 KB