Problem:
魔法陣
Problem Statement
〜魔法陣の描き方〜
十分広くて真っ白な床を用意します．
床の座標
(0,0)
の点を中心にして，半径
1, 2, ..., R
の円を描きます．
半径
1
の円と半径
2
の円の間，半径
3
の円と半径
4
の円の間，
...
を青色で塗ります．なお，半径
R
の円の外には色を塗ってはいけません．
床に頂点数
N
の多角形を一つ描きます．
多角形の内部の白色の領域を青色で，青色の領域を白色で塗りなおします．
魔法陣の力は，魔法陣に青色が多く含まれるほど強くなるという．
そこであなたには，魔法陣に含まれる青い領域の面積を求めてほしい．
次の図はこの手順で描くことのできる魔法陣の一例である．
Input
入力は以下の形式に従う．与えられる数は全て整数である．
N
R
x_1
y_1
...
x_N
y_N
(x_i, y_i)
は多角形の
i
番目の頂点である．
Constraints
3 ≦ N ≦ 100
1 ≦ R ≦ 100
多角形は半径
R
の円の内部または円周上に含まれる．
多角形は自己交差をもたない．
多角形の頂点は反時計回りの順番で与えられる．
Output
青い領域の面積を 1 行に出力せよ．
出力する値は，真の値との絶対誤差または相対誤差が
10^{-8}
未満でなければならない．
Sample Input 1
3 1
0 0
1 0
0 1
Output for the Sample Input 1
0.500000000
Sample Input 2
3 2
0 0
2 0
0 2
Output for the Sample Input 2
8.995574288
Sample Input 3
3 2
1 -1
1 1
-2 0
Output for the Sample Input 3
11.123246567
Sample Input 4
4 3
1 1
-1 1
-1 -1
1 -1
Output for the Sample Input 4
11.707963268

Submitted solutions:

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}

P unit(const P &p){
    return p/abs(p);
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}

P projection(const L& l, const P& p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}
double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}
double distanceSP(const L &s, const P &p) {
    if(dot(s[1]-s[0], p-s[0]) < EPS) return abs(p-s[0]);
    if(dot(s[0]-s[1], p-s[1]) < EPS) return abs(p-s[1]);
    return distanceLP(s, p);
}

VP crosspointCL(const C &c, const L &l){
    VP ret;
    P mid = projection(l, c.p);
    double d = distanceLP(l, c.p);
    if(EQ(d, c.r)){
        ret.push_back(mid);
    }else if(d < c.r){
        double len = sqrt(c.r*c.r -d*d);
        ret.push_back(mid +len*unit(l[1]-l[0]));
        ret.push_back(mid -len*unit(l[1]-l[0]));
    }
    return ret;
}
VP crosspointCS(const C &c, const L &s){
    VP ret;
    VP cp = crosspointCL(c,s);
    for(int i=0; i<(int)cp.size(); i++){
        if(intersectSP(s, cp[i])){
            ret.push_back(cp[i]);
        }
    }
    return ret;
}

int in_poly(const P &p, const VP &poly){
    int n = poly.size();
    int ret = -1;
    for(int i=0; i<n; i++){
        P a = poly[i]-p;
        P b = poly[(i+1)%n]-p;
        if(a.Y > b.Y) swap(a,b);
        if(intersectSP(L(a,b), P(0,0))) return 0;
        if(a.Y<=0 && b.Y>0 && cross(a,b)<0) ret = -ret;
    }
    return ret;
}
double getarea(const VP &poly){
    int n = poly.size();
    double ret = 0;
    for (int i=0; i<n; i++){ 
        ret += cross(poly[i], poly[(i+1)%n]);
    }
    return ret*0.5;
}

VP convex(VP v){
    VP ret;
    int n = v.size();
    sort(v.begin(), v.end());
    for(int i=0; i<n; i++){
        while((int)ret.size()>1 && cross(ret.back()-ret[ret.size()-2], v[i]-ret.back()) < EPS){
            ret.pop_back();
        }
        ret.push_back(v[i]);
    }
    int t = ret.size();
    for(int i=n-2; i>=0; i--){
        while((int)ret.size()>t && cross(ret.back()-ret[ret.size()-2], v[i]-ret.back()) < EPS){
            ret.pop_back();
        }
        ret.push_back(v[i]);
    }
    if((int)ret.size() > 1) ret.pop_back();
    return ret;
}

double commonarea_circle_convex(C c, VP poly){
    int n = poly.size();
    for(int i=0; i<n; i++) poly[i] -= c.p;
    c.p = P(0, 0);

    double mindist = INF;
    VP cp;
    for(int i=0; i<n; i++){
        L edge(poly[i], poly[(i+1)%n]);
        VP ret = crosspointCS(c, edge);
        cp.insert(cp.begin(), ret.begin(), ret.end());
        if(abs(poly[i]) < c.r) cp.push_back(poly[i]);
        mindist = min(mindist, distanceSP(edge, c.p));
    }
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    if(mindist +EPS > c.r && in_poly(c.p, poly) > 0){
        return PI *c.r *c.r;
    }

    double res = 0;
    VP v = convex(cp);
    int m = v.size();
    for(int i=0; i<m; i++){
        P curr = v[i];
        P next = v[(i+1)%m];
        if(EQ(abs(curr), c.r) && EQ(abs(next), c.r)
            && in_poly(c.r *unit(next -curr)*P(0,-1), poly) > 0){
            double theta = arg(next /curr);
            if(theta < 0) theta += 2*PI;
            res += c.r*c.r *theta /2;
        }else{
            res += cross(curr, next) /2;
        }
    }
    return res;
}


vector<VP> triangulate(VP poly){
    vector<VP> ret;
    int i=0;
    while((int)poly.size() >= 3){
        int n = poly.size();
        i = (i+1)%n;
        VP tri{poly[(i-1+n)%n], poly[i], poly[(i+1)%n]};
        if(ccw(tri[0], tri[1], tri[2]) != 1) continue;
        bool isear = true;
        for(int j=0; j<n; j++){
            if(j==(i-1+n)%n || j==i || j==(i+1)%n) continue;
            if(in_poly(poly[j], tri) >= 0){
                isear = false;
                break;
            }
        }
        if(isear){
            ret.push_back(tri);
            poly.erase(poly.begin() +i);
        }
    }
    return ret;
}

double commonarea_circle_poly(const C &c, const VP &poly){
    vector<VP> tri = triangulate(poly);
    double ret = 0;
    for(int i=0; i<(int)tri.size(); i++){
        ret += commonarea_circle_convex(c, tri[i]);
    }
    return ret;
}

int main(){
    int n,r;
    cin >> n >> r;
    VP p(n);
    for(int i=0; i<n; i++){
        double x,y;
        cin >> x >> y;
        p[i] = P(x, y);
    }

    vector<double> areacp(r+1, 0);
    for(int i=1; i<=r; i++){
        areacp[i] = commonarea_circle_poly(C(P(0, 0), i), p);
    }
    double ans = 0;
    for(int i=0; i<r; i++){
        if(i%2 == 0){
            ans += areacp[i+1] -areacp[i];
        }else{
            ans += PI*((i+1)*(i+1) -i*i) -(areacp[i+1] -areacp[i]);
        }
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3604
final_rank: 9

code_snippet: #include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

namespace std{
    bool operator < (const P& a, const P& b){
        return !EQ(a.X,b.X) ? a.X<b.X : a.Y+EPS<b.Y;
    }
    bool operator == (const P& a, const P& b){
        return abs(a-b) < EPS;
    }
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}

P unit(const P &p){
    return p/abs(p);
}
P rotate(const P &p, double rad){
    return p *P(cos(rad), sin(rad));
}

bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}

P projection(const L& l, const P& p) {
    double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
    return l[0] + t*(l[0]-l[1]);
}
double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}

VP crosspointCL(const C &c, const L &l){
    VP ret;
    P mid = projection(l, c.p);
    double d = distanceLP(l, c.p);
    if(EQ(d, c.r)){
        ret.push_back(mid);
    }else if(d < c.r){
        double len = sqrt(c.r*c.r -d*d);
        ret.push_back(mid +len*unit(l[1]-l[0]));
        ret.push_back(mid -len*unit(l[1]-l[0]));
    }
    return ret;
}
VP crosspointCS(const C &c, const L &s){
    VP ret;
    VP cp = crosspointCL(c,s);
    for(int i=0; i<(int)cp.size(); i++){
        if(intersectSP(s, cp[i])){
            ret.push_back(cp[i]);
        }
    }
    return ret;
}

int in_poly(const P &p, const VP &poly){
    int n = poly.size();
    int ret = -1;
    for(int i=0; i<n; i++){
        P a = poly[i]-p;
        P b = poly[(i+1)%n]-p;
        if(a.Y > b.Y) swap(a,b);
        if(intersectSP(L(a,b), P(0,0))) return 0;
        if(a.Y<=0 && b.Y>0 && cross(a,b)<0) ret = -ret;
    }
    return ret;
}
double getarea(const VP &poly){
    int n = poly.size();
    double ret = 0;
    for (int i=0; i<n; i++){ 
        ret += cross(poly[i], poly[(i+1)%n]);
    }
    return ret*0.5;
}

VP convex(VP v){
    VP ret;
    int n = v.size();
    sort(v.begin(), v.end());
    for(int i=0; i<n; i++){
        while((int)ret.size()>1 && cross(ret.back()-ret[ret.size()-2], v[i]-ret.back()) < EPS){
            ret.pop_back();
        }
        ret.push_back(v[i]);
    }
    int t = ret.size();
    for(int i=n-2; i>=0; i--){
        while((int)ret.size()>t && cross(ret.back()-ret[ret.size()-2], v[i]-ret.back()) < EPS){
            ret.pop_back();
        }
        ret.push_back(v[i]);
    }
    if((int)ret.size() > 1) ret.pop_back();
    return ret;
}

double commonarea_circle_convex(C c, VP poly){
    int n = poly.size();
    for(int i=0; i<n; i++) poly[i] -= c.p;
    c.p = P(0, 0);

    VP cp;
    for(int i=0; i<n; i++){
        L edge(poly[i], poly[(i+1)%n]);
        VP ret = crosspointCS(c, edge);
        cp.insert(cp.begin(), ret.begin(), ret.end());
        if(abs(poly[i]) < c.r) cp.push_back(poly[i]);
    }
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());

    if(cp.empty() && in_poly(c.p, poly) > 0){
        return PI *c.r *c.r;
    }

    double res = 0;
    VP v = convex(cp);
    int m = v.size();
    for(int i=0; i<m; i++){
        P curr = v[i];
        P next = v[(i+1)%m];
        if(EQ(abs(curr), c.r) && EQ(abs(next), c.r)
            && in_poly(c.r *unit(next -curr)*P(0,-1), poly) > 0){
            double theta = arg(next /curr);
            if(theta < 0) theta += 2*PI;
            res += c.r*c.r *theta /2;
        }else{
            res += cross(curr, next) /2;
        }
    }
    return res;
}


vector<VP> triangulate(VP poly){
    vector<VP> ret;
    int i=0;
    while((int)poly.size() >= 3){
        int n = poly.size();
        i = (i+1)%n;
        VP tri{poly[(i-1+n)%n], poly[i], poly[(i+1)%n]};
        if(ccw(tri[0], tri[1], tri[2]) != 1) continue;
        bool isear = true;
        for(int j=0; j<n; j++){
            if(j==(i-1+n)%n || j==i || j==(i+1)%n) continue;
            if(in_poly(poly[j], tri) >= 0){
                isear = false;
                break;
            }
        }
        if(isear){
            ret.push_back(tri);
            poly.erase(poly.begin() +i);
        }
    }
    return ret;
}

double commonarea_circle_poly(const C &c, const VP &poly){
    vector<VP> tri = triangulate(poly);
    double ret = 0;
    for(int i=0; i<(int)tri.size(); i++){
        ret += commonarea_circle_convex(c, tri[i]);
    }
    return ret;
}

int main(){
    int n,r;
    cin >> n >> r;
    VP p(n);
    for(int i=0; i<n; i++){
        double x,y;
        cin >> x >> y;
        p[i] = P(x, y);
    }

    vector<VP> tri = triangulate(p);

    vector<double> areacp(r+1, 0);
    for(int i=1; i<=r; i++){
        areacp[i] = commonarea_circle_poly(C(P(0, 0), i), p);
    }
    double ans = 0;
    for(int i=0; i<r; i++){
        if(i%2 == 0){
            ans += areacp[i+1] -areacp[i];
        }else{
            ans += PI*((i+1)*(i+1) -i*i) -(areacp[i+1] -areacp[i]);
        }
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}
accuracy: 0.9772727272727273
time_ms: 20
memory_kb: 3624
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef complex<double> P;
typedef vector<P> G;

const double eps = 1e-8;
const double inf = 1e8;

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

bool equals(P a, P b) {
  return equals(a.real(), b.real()) && equals(a.imag(), b.imag());
}

struct C {
  P p;
  double r;
  C() {}
  C(P p, double r) : p(p), r(r) {}
};

double dot  (P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }
double cross(P a, P b) { return a.real()*b.imag() - a.imag()*b.real(); }

int ccw(P p0, P a, P b) {
  a -= p0;
  b -= p0;
  if(cross(a, b) > eps) return 1;
  if(cross(a, b) < -eps) return -1;
  if(dot(a, b) < -eps) return 2;
  if(norm(b)-norm(a) > eps) return -2;
  return 0;
}

P project(P s1, P s2, P p) {
  P base = s2 - s1;
  double t = dot(p - s1, base)/norm(base);
  return s1 + base*t;
}

double getAngleDist(P a, P b) { // 0 ~ 2PI
  double A = arg(a);
  double B = arg(b);
  double rad = B-A;
  rad = fmod(rad, M_PI*2.0);
  if(rad < 0.0) rad += M_PI*2.0;
  return rad;
}

double getDistanceLP(P s1, P s2, P p) {
  return abs(cross(s2 - s1, p - s1)/abs(s2 - s1));
}
double getDistanceSP(P s1, P s2, P p) {
  if(dot(s2 - s1, p - s1) < 0.0) return abs(p - s1);
  if(dot(s1 - s2, p - s2) < 0.0) return abs(p - s2);
  return getDistanceLP(s1, s2, p);
}

vector<P> getCrossPLC(P s1, P s2, C c) { // line, circle
  vector<P> v;
  P p = project(s1, s2, c.p);
  double dist = getDistanceLP(s1, s2, c.p);
  if(equals(dist, c.r)) {
    v.push_back(p);
  } else if(dist < c.r) {
    double h = abs(p - c.p);
    double d = sqrt(c.r*c.r - h*h);
    P base = s2 - s1;
    v.push_back(p - d*base/abs(base));
    v.push_back(p + d*base/abs(base));
  }
  return v;
}

int inCircle(P p, C c) {
  if(abs(c.p - p) - c.r <  -eps) return 2;
  if(abs(c.p - p) - c.r >  eps) return 0;
  return 1;
}

double getTriArea(P a, P b, P c) {
  return cross(b-a, c-a) / 2.0;
}

double getSectorArea(P a, P b, C c) {
  return getAngleDist(a-c.p, b-c.p) * c.r * c.r / 2.0;
}

double getBowArea(P a, P b, C c) { // a,b is a chord of c.
  return getSectorArea(a, b, c) - getTriArea(a, b, c.p);
}

double getArea(P a, P b, C c) {
  int d = 1;
  if(cross(a,b) < 0.0) {
    d = -1;
    swap(a, b);
  }
  if(cross(a, b) < eps) return 0;

  G t(3);
  t[0] = P(0, 0), t[1] = a, t[2] = b;

  if(inCircle(t[0], c) && inCircle(t[1], c) && inCircle(t[2], c)) {
    return d * getTriArea(t[0], t[1], t[2]);
  }
  if(getDistanceSP(t[0], t[1], c.p) - c.r > -eps &&
     getDistanceSP(t[1], t[2], c.p) - c.r > -eps &&
     getDistanceSP(t[2], t[0], c.p) - c.r > -eps) {
    if(cross(t[1] - t[0], c.p - t[0]) > -eps &&
       cross(t[2] - t[1], c.p - t[1]) > -eps &&
       cross(t[0] - t[2], c.p - t[2]) > -eps) {
      return d * (c.r * c.r * M_PI);
    } else {
      return 0;
    }
  }

  double S = c.r * c.r * M_PI;
  vector<P> cp(6);
  vector<int> exist(6);
  for(int i = 0; i < 3; ++i) {
    P p = t[i], q = t[(i+1)%3];
    if(getDistanceLP(p, q, c.p) - c.r > -eps) {
      if(cross(q - p, c.p - p) < 0) return 0;
      continue;
    }
    if(getDistanceSP(p, q, c.p) - c.r > -eps) continue;
    vector<P> v = getCrossPLC(t[i], t[(i+1)%3], c);
    if(v.size() == 2 && !equals(v[0], v[1])) {
      S -= getBowArea(v[0], v[1], c);
      for(int j = 0; j < v.size(); ++j) {
	int k = (i*2 + j*3) % 6;
	cp[k] = v[j];
	exist[k] = true;
      }
    }
  }
  for(int i = 0; i < 3; ++i) {
    int a = i*2, b = i*2+1;
    if(!exist[a] || !exist[b]) continue;
    if(inCircle(t[i], c) == 2 && !equals(cp[a], cp[b])) {
      S += getBowArea(cp[a], cp[b], c) + getTriArea(t[i], cp[a], cp[b]);
    }
  }
  return S * d;
}

double getArea(G g, C c) {
  int n = g.size();
  double res = 0;
  for(int i = 0; i < n; ++i) {
    res += getArea(g[i], g[(i+1)%n], c);
  }
  return res;
}

double getArea(G g) {
  int n = g.size();
  double res = 0;
  for(int i = 0; i < n; ++i) {
    res += cross(g[i], g[(i+1)%n]);
  }
  return res / 2.0;
}

int main() {
  int N, R;
  vector<P> ps;
  for(; cin >> N >> R; ) {
    G ps(N);
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }
    double res = 0;
    for(int r = 1; r <= R; ++r) {
      double a = getArea(ps, C(P(0,0), r));
      if(r-1 != 0) a -= getArea(ps, C(P(0,0), r-1));
      double b = r*r*M_PI - (r-1)*(r-1)*M_PI - a;
      if((int)r % 2 == 1) {
	res += a;
      } else {
	res += b;
      }
    }
    printf("%.10f\n", res);
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1360
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SZ(a) ((int)(a.size()))

typedef long long ll;
typedef pair<int, int> PI;

typedef complex<double> P;
typedef pair<P, double> C;
typedef vector<P> poly;
const double EPS = 1e-9;

#define EQ(a, b) (abs((a)-(b)) < EPS)

double dot(P a, P b){
  return real(conj(a) * b);
};

double cross(P a, P b){
  return imag(conj(a) * b);
};


vector<double> roots(double a, double b, double c){
  double scale = abs(a) + abs(b) + abs(c);
  auto D = b * b - 4 * a *c;
  vector<double> x;
  if(D < -EPS*scale) return x;
  if(D<EPS*scale) return vector<double>(1,-b/2/a);
  if(b<0){
    x.pb((-b+sqrt(D))/2/a);
  }else{
    x.pb((-b-sqrt(D))/2/a);
  }
  
  x.pb(c/a/x.front());
  return x;
}



double area_of_intersection(const C c , const poly v){
  double r = c.second;
  P z = c.first;
  double res = 0;
  rep(i, SZ(v)){
    P p = v[i] - z, q = v[(i +1)%SZ(v)] - z;
    P v = q - p;
    auto t = roots(norm(v), 2*dot(p, v), norm(p)-r*r);
    sort(ALL(t));
    if(!t.empty() && (t.back()<0||t.front()>1)) t.clear();
    t.insert(t.begin(),0);
    t.pb(1);
    rep(i,SZ(t)-1){
      P a = p + t[i] * v, b = p + t[i+1]*v;
      if(EQ(a, 0.) || EQ(b, 0.)) continue;
      P m = (a + b) * .5;
      res += abs(m) <= r + EPS ? cross(a, b) : r * r * arg(b/ a);
    }
  }
  return abs(res) * .5;
}

int n, r;
double x[100], y[100];

void solve(){
  rep(i, n) cin >> x[i] >> y[i];

  poly po;
  rep(i, n) po.pb(P(x[i], y[i]));
  double ans = 0;
  for(int i = 0; i < r; ++i){
    double small = area_of_intersection(C(P(0, 0), i), po);
    double big = area_of_intersection(C(P(0, 0), (i + 1)), po);
    if(i & 1){
      const double pi = acos(-1);
      ans += pi * (2 * i + 1);
      ans -= big - small;
    }else{
      ans += big - small;
    }
  }

  printf("%.18f\n", ans);
}

int main(int argc, char *argv[])
{
  while(cin >> n >> r && n) solve();
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1364
final_rank: 4

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}
namespace std {
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 円
struct C{P c; D r;};

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と多角形の共通部分面積
D aCTnc(D r, P p1, P p2) {return sig(abs((p1 + p2) / (D)2), r) < 0 ? det(p1, p2) / 2 : r * r * arg(0, p1, p2) / 2;}
D aCT(D r, P p1, P p2) {
  if (near(0, p1) || near(0, p2) || near(p1, p2)) return 0;
  pair<P, P> pp = pCL((C){0, r}, (L){p1, p2});
  if ((p1 < pp.first) != (pp.first < p2) && (p1 < pp.second) != (pp.second < p2)) return aCTnc(r, p1, p2);
  return aCTnc(r, p1, pp.first) + aCTnc(r, pp.first, pp.second) + aCTnc(r, pp.second, p2);
}
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c.r, pol[i] - c.c, at(pol, i + 1) - c.c); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 0.5681818181818182
time_ms: 20
memory_kb: 1292
final_rank: 15

code_snippet: #include<iostream>
#include<complex>
#include<cstdio>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;
struct C{P c; D r;};

const D EPS = 1e-8;
const D PI = acos(-1);

int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}
namespace std{
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
}

D sr(D a) {return sqrt(max(a, (D)0));}

D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

P vec(L a) {return a.b - a.a;}

D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

D aCTnc(D r, P p1, P p2) {return sig(abs((p1 + p2) / (D)2), r) <= 0 ? det(p1, p2) / 2 : r * r * arg(0, p1, p2) / 2;}
D aCT(D r, P p1, P p2) {
  if (!sig(r) || near(0, p1) || near(0, p2) || near(p1, p2)) return 0;
  pair<P, P> pp = pCL((C){0, r}, (L){p1, p2});
  if ((p1 < pp.first) != (pp.first < p2) && (p1 < pp.second) != (pp.second < p2)) return aCTnc(r, p1, p2);
  return aCTnc(r, p1, pp.first) + aCTnc(r, pp.first, pp.second) + aCTnc(r, pp.second, p2);
}
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c.r, pol[i] - c.c, pol[(i + 1) % pol.size()] - c.c); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  rep (i, r) {
    if (i % 2) res += (i * 2 + 1) * PI - aCPol((C){0, (D)(i + 1)}, pol) + aCPol((C){0, (D)i}, pol);
    else res += aCPol((C){0, (D)(i + 1)}, pol) - aCPol((C){0, (D)i}, pol);
  }
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1288
final_rank: 6

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}

#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}
namespace std {
  bool operator<(P a, P b) {return sig(a.X, b.X) ? a.X < b.X : a.Y < b.Y;}
}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 円
struct C{P c; D r;};

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と多角形の共通部分面積
D aCTnc(D r, P p1, P p2) {return sig(abs((p1 + p2) / (D)2), r) <= 0 ? det(p1, p2) / 2 : r * r * arg(0, p1, p2) / 2;}
D aCT(D r, P p1, P p2) {
  if (!sig(r) || near(0, p1) || near(0, p2) || near(p1, p2)) return 0;
  pair<P, P> pp = pCL((C){0, r}, (L){p1, p2});
  if ((p1 < pp.first) != (pp.first < p2) && (p1 < pp.second) != (pp.second < p2)) return aCTnc(r, p1, p2);
  return aCTnc(r, p1, pp.first) + aCTnc(r, pp.first, pp.second) + aCTnc(r, pp.second, p2);
}
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c.r, pol[i] - c.c, at(pol, i + 1) - c.c); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1292
final_rank: 2

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}


#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 距離
D dLP(L l, P p) {return abs(det(vec(l), p - l.a) / vec(l));}
D dSP(L s, P p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}

// 円
struct C{P c; D r;};

// 交差判定
bool iCS(C c, L s) {return sig(c.r, dSP(s, c.c)) >= 0;}

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と多角形の共通部分面積
D aCTnc(D r, P p1, P p2) {return sig(abs((p1 + p2) / (D)2), r) <= 0 ? det(p1, p2) / 2 : r * r * arg(0, p1, p2) / 2;}
D aCT(D r, P p1, P p2) {
  if (!sig(r) || near(0, p1) || near(0, p2) || near(p1, p2)) return 0;
  if (!iCS((C){0, r}, (L){p1, p2})) return r * r * arg(0, p1, p2) / 2;
  pair<P, P> pp = pCL((C){0, r}, (L){p1, p2});
  return aCTnc(r, p1, pp.first) + aCTnc(r, pp.first, pp.second) + aCTnc(r, pp.second, p2);
}
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c.r, pol[i] - c.c, at(pol, i + 1) - c.c); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1288
final_rank: 1

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}


#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 距離
D dLP(L l, P p) {return abs(det(vec(l), p - l.a) / vec(l));}
D dSP(L s, P p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}

// 円
struct C{P c; D r;};

// 交差判定
bool iCS(C c, L s) {return sig(c.r, dSP(s, c.c)) >= 0;}

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と円の中心,p1,p2からなる三角形の共通部分面積
D aCT(C c, P p1, P p2) {
  if (!sig(c.r)) return 0;
  p1 -= c.c; p2 -= c.c; c.c = 0;
  if (near(0, p1) || near(0, p2) || near(p1, p2)) return 0;
  if (!iCS(c, (L){p1, p2})) return c.r * c.r * arg(0, p1, p2) / 2;
  bool b1 = sig(abs(p1), c.r) > 0, b2 = sig(abs(p2), c.r) > 0;
  pair<P, P> pp = pCL(c, (L){p1, p2});
  if (b1 && b2) return (c.r * c.r * (arg(0, p1, pp.first) + arg(0, pp.second, p2)) + det(pp.first, pp.second)) / 2;
  if (b1) return (c.r * c.r * arg(0, p1, pp.first) + det(pp.first, p2)) / 2;
  if (b2) return (c.r * c.r * arg(0, pp.second, p2) + det(p1, pp.second)) / 2;
  return det(p1, p2) / 2;
}

// 円と多角形の共通部分面積
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c, pol[i], at(pol, i + 1)); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1292
final_rank: 2

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>
#include<cassert>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}


#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {assert(!isnan(arg((b - base) / (a - base))));return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 距離
D dLP(L l, P p) {return abs(det(vec(l), p - l.a) / vec(l));}
D dSP(L s, P p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}

// 円
struct C{P c; D r;};

// 交差判定
bool iCS(C c, L s) {return sig(c.r, dSP(s, c.c)) >= 0;}

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と円の中心,p1,p2からなる三角形の共通部分面積
D aCT(C c, P p1, P p2) {
  p1 -= c.c; p2 -= c.c; c.c = 0;
  if (near(0, p1) || near(0, p2) || near(p1, p2)) return 0;
  if (!iCS(c, (L){p1, p2})) return c.r * c.r * arg(0, p1, p2) / 2;
  bool b1 = sig(abs(p1), c.r) > 0, b2 = sig(abs(p2), c.r) > 0;
  pair<P, P> pp = pCL(c, (L){p1, p2});
  if (b1 && b2) return (c.r * c.r * (arg(0, p1, pp.first) + arg(0, pp.second, p2)) + det(pp.first, pp.second)) / 2;
  if (b1) return (c.r * c.r * arg(0, p1, pp.first) + det(pp.first, p2)) / 2;
  if (b2) return (c.r * c.r * arg(0, pp.second, p2) + det(p1, pp.second)) / 2;
  return det(p1, p2) / 2;
}

// 円と多角形の共通部分面積
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c, pol[i], at(pol, i + 1)); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  //assert(!isnan(res));
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 0.5681818181818182
time_ms: 10
memory_kb: 1292
final_rank: 11

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>
#include<cassert>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}


#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 距離
D dLP(L l, P p) {return abs(det(vec(l), p - l.a) / vec(l));}
D dSP(L s, P p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}

// 円
struct C{P c; D r;};

// 交差判定
bool iCS(C c, L s) {return sig(c.r, dSP(s, c.c)) >= 0;}

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と円の中心,p1,p2からなる三角形の共通部分面積
D aCT(C c, P p1, P p2) {
  p1 -= c.c; p2 -= c.c; c.c = 0;
  if (near(0, p1) || near(0, p2) || near(p1, p2)) return 0;
  if (!iCS(c, (L){p1, p2})) return c.r * c.r * arg(0, p1, p2) / 2;
  bool b1 = sig(abs(p1), c.r) > 0, b2 = sig(abs(p2), c.r) > 0;
  pair<P, P> pp = pCL(c, (L){p1, p2});
  if (b1 && b2) return (c.r * c.r * (arg(0, p1, pp.first) + arg(0, pp.second, p2)) + det(pp.first, pp.second)) / 2;
  if (b1) return (c.r * c.r * arg(0, p1, pp.first) + det(pp.first, p2)) / 2;
  if (b2) return (c.r * c.r * arg(0, pp.second, p2) + det(p1, pp.second)) / 2;
  return det(p1, p2) / 2;
}

// 円と多角形の共通部分面積
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c, pol[i], at(pol, i + 1)); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  assert(!isnan(res));
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 0.5681818181818182
time_ms: 10
memory_kb: 1292
final_rank: 11

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>
#include<cassert>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}


#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 距離
D dLP(L l, P p) {return abs(det(vec(l), p - l.a) / vec(l));}
D dSP(L s, P p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}

// 円
struct C{P c; D r;};

// 交差判定
bool iCS(C c, L s) {return sig(c.r, dSP(s, c.c)) >= 0;}

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と円の中心,p1,p2からなる三角形の共通部分面積
D aCT(C c, P p1, P p2) {
  p1 -= c.c; p2 -= c.c; c.c = 0;
  if (near(0, p1) || near(0, p2)) return 0;
  if (!iCS(c, (L){p1, p2})) return c.r * c.r * arg(0, p1, p2) / 2;
  bool b1 = sig(abs(p1), c.r) > 0, b2 = sig(abs(p2), c.r) > 0;
  pair<P, P> pp = pCL(c, (L){p1, p2});
  if (b1 && b2) return (c.r * c.r * (arg(0, p1, pp.first) + arg(0, pp.second, p2)) + det(pp.first, pp.second)) / 2;
  if (b1) return (c.r * c.r * arg(0, p1, pp.first) + det(pp.first, p2)) / 2;
  if (b2) return (c.r * c.r * arg(0, pp.second, p2) + det(p1, pp.second)) / 2;
  return det(p1, p2) / 2;
}

// 円と多角形の共通部分面積
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c, pol[i], at(pol, i + 1)); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  assert(!isnan(res));
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 0.5681818181818182
time_ms: 10
memory_kb: 1292
final_rank: 11

code_snippet: #include<complex>
#include<cstdio>
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
template<class T> T at(vector<T> v, int i) {return v[i % v.size()];}


#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};
typedef vector<P> Pol;

const D EPS = 1e-8;
const D PI = acos(-1);

// 比較関数
int sig(D a, D b = 0) {return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;}
bool near(P a, P b) {return !sig(norm(a - b));}

// 平方根
D sr(D a) {return sqrt(max(a, (D)0));}

// 内積
D dot(P a, P b) {return a.X * b.X + a.Y * b.Y;}
// 外積
D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}

// 線分のベクトル
P vec(L a) {return a.b - a.a;}

// 有向角度
D arg(P base, P a, P b) {return arg((b - base) / (a - base));}

// 射影
P proj(P a, P b) {return a * dot(a, b) / norm(a);}
P perp(L l, P p) {return l.a + proj(vec(l), p - l.a);}

// 距離
D dLP(L l, P p) {return abs(det(vec(l), p - l.a) / vec(l));}
D dSP(L s, P p) {
  if (dot(vec(s), p - s.a) < 0) return abs(p - s.a);
  if (dot(vec(s), p - s.b) > 0) return abs(p - s.b);
  return dLP(s, p);
}

// 円
struct C{P c; D r;};

// 交差判定
bool iCS(C c, L s) {return sig(c.r, dSP(s, c.c)) >= 0;}

// 交点
pair<P, P> pCL(C c, L l) {
  P x = perp(l, c.c);
  P y = vec(l) / abs(vec(l)) * sr(c.r * c.r - norm(x - c.c));
  return make_pair(x - y, x + y);
}

// 円と円の中心,p1,p2からなる三角形の共通部分面積
D aCT(C c, P p1, P p2) {
  p1 -= c.c; p2 -= c.c; c.c = 0;
  if (near(0, p1) || near(0, p2)) return 0;
  if (!iCS(c, (L){p1, p2})) return c.r * c.r * arg(0, p1, p2) / 2;
  bool b1 = sig(abs(p1), c.r) > 0, b2 = sig(abs(p2), c.r) > 0;
  pair<P, P> pp = pCL(c, (L){p1, p2});
  if (b1 && b2) return (c.r * c.r * (arg(0, p1, pp.first) + arg(0, pp.second, p2)) + det(pp.first, pp.second)) / 2;
  if (b1) return (c.r * c.r * arg(0, p1, pp.first) + det(pp.first, p2)) / 2;
  if (b2) return (c.r * c.r * arg(0, pp.second, p2) + det(p1, pp.second)) / 2;
  return det(p1, p2) / 2;
}

// 円と多角形の共通部分面積
D aCPol(C c, Pol pol) {D res = 0; rep (i, pol.size()) res += aCT(c, pol[i], at(pol, i + 1)); return res;}

int main() {
  int n, r;
  cin >> n >> r;
  Pol pol(n);
  rep (i, n) cin >> pol[i].X >> pol[i].Y;
  D res = 0;
  for (int i = 1; i < r; i += 2) res += (2 * i + 1) * PI - (aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol));
  for (int i = 0; i < r; i += 2) res += aCPol((C){0, (D)i + 1}, pol) - aCPol((C){0, (D)i}, pol);
  printf("%.12Lf\n", res);
  return 0;
}
accuracy: 0.5681818181818182
time_ms: 10
memory_kb: 1292
final_rank: 11

code_snippet: #include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-8;
const double PI=acos(-1);

struct point{
	double x,y;
	point():x(0),y(0){}
	point(double x,double y):x(x),y(y){}
	point &operator+=(const point &a){ x+=a.x; y+=a.y; return *this; }
	point &operator-=(const point &a){ x-=a.x; y-=a.y; return *this; }
	point &operator*=(double c){ x*=c; y*=c; return *this; }
	point &operator/=(double c){ x/=c; y/=c; return *this; }
	point operator+(const point &a)const{ return point(x+a.x,y+a.y); }
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
	point operator/(double c)const{ return point(x/c,y/c); }
	point operator-()const{ return point(-x,-y); }
	bool operator< (const point &a)const{ return x+EPS<a.x || abs(x-a.x)<EPS && y+EPS<a.y; }
	bool operator==(const point &a)const{ return abs(x-a.x)<EPS && abs(y-a.y)<EPS; }
	bool operator!=(const point &a)const{ return abs(x-a.x)>EPS || abs(y-a.y)>EPS; }
};

point operator*(double c,const point &a){ return point(c*a.x,c*a.y); }

double dot(const point &a,const point &b){ return a.x*b.x+a.y*b.y; }

double cross(const point &a,const point &b){ return a.x*b.y-a.y*b.x; }

double abs(const point &a){ return sqrt(a.x*a.x+a.y*a.y); }

double abs2(const point &a){ return a.x*a.x+a.y*a.y; }

point rot(const point &a,double theta){ return point(a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta)); }

double arg(const point &a){ double t=atan2(a.y,a.x); return t<0?t+2*PI:t; }

struct line{
	point a,b;
	line(){}
	line(const point &a,const point &b):a(a),b(b){}
};

struct segment{
	point a,b;
	segment(){}
	segment(const point &a,const point &b):a(a),b(b){}
	operator line()const{ return line(a,b); }
};

typedef vector<point> polygon;

struct circle{
	point c;
	double r;
	circle():c(point(0,0)),r(0){}
	circle(const point &c,double r):c(c),r(r){}
};

point proj(const point &p,const line &L){ return L.a+dot(p-L.a,L.b-L.a)/abs2(L.b-L.a)*(L.b-L.a); }

enum{CCW=1,CW=-1,ON=0};
int ccw(const point &a,const point &b,const point &c){
	double rdir=cross(b-a,c-a);
	if(rdir> EPS) return CCW;
	if(rdir<-EPS) return CW;
	return ON;
}

double area(const point &a,const point &b,const point &c){
	return abs(cross(b-a,c-a))/2;
}

bool cover(const segment &S,const point &p){
	return abs(cross(S.a-p,S.b-p))<EPS && dot(S.a-p,S.b-p)<EPS;
}

bool cover(const polygon &F,const point &p){
	int n=F.size();
	bool res=false;
	rep(i,n){
		point v1=F[i]-p,v2=F[(i+1)%n]-p;
		if(v1.y>v2.y) swap(v1,v2);
		if(v1.y<EPS && EPS<v2.y && cross(v1,v2)>EPS) res=!res;
		if(abs(cross(v1,v2))<EPS && dot(v1,v2)<EPS) return true;
	}
	return res;
}

bool intersect(const segment &S1,const segment &S2){
	if(max(S1.a.x,S1.b.x)+EPS<min(S2.a.x,S2.b.x)
	|| max(S1.a.y,S1.b.y)+EPS<min(S2.a.y,S2.b.y)
	|| max(S2.a.x,S2.b.x)+EPS<min(S1.a.x,S1.b.x)
	|| max(S2.a.y,S2.b.y)+EPS<min(S1.a.y,S1.b.y)) return false;
	return ccw(S1.a,S1.b,S2.a)*ccw(S1.a,S1.b,S2.b)<=0
		&& ccw(S2.a,S2.b,S1.a)*ccw(S2.a,S2.b,S1.b)<=0;
}

point get_intersect(const segment &S1,const segment &S2){
	double a1=cross(S1.b-S1.a,S2.b-S2.a);
	double a2=cross(S1.b-S1.a,S1.b-S2.a);
	if(abs(a1)<EPS){
		if(cover(S1,S2.a)) return S2.a;
		if(cover(S1,S2.b)) return S2.b;
		if(cover(S2,S1.a)) return S1.a;
		return S1.b;
	}
	return S2.a+a2/a1*(S2.b-S2.a);
}

int get_intersect(const circle &C,const segment &S,vector<point> &res){
	point h=proj(C.c,S);
	double d=abs(C.c-h);
	if(d>C.r+EPS) return 0;
	if(d>C.r-EPS){
		int cnt=0;
		if(cover(S,h)) res.push_back(h), cnt++;
		return cnt;
	}
	else{
		point v=S.b-S.a;
		v*=sqrt(C.r*C.r-d*d)/abs(v);
		int cnt=0;
		if(cover(S,h+v)) res.push_back(h+v), cnt++;
		if(cover(S,h-v)) res.push_back(h-v), cnt++;
		return cnt;
	}
}

bool eq(const double &a,const double &b){ return abs(a-b)<EPS; }

int main(){
	const point o(0,0);

	point cen;
	do{
		cen=point(rand()%1000/1000.0,rand()%1000/1000.0);
	}while(abs(cen)<0.1 || 0.9<abs(cen));

	int n,R; scanf("%d%d",&n,&R);
	polygon F(n);
	rep(i,n) scanf("%lf%lf",&F[i].x,&F[i].y);

	vector<double> theta;
	rep(i,n){
		theta.push_back(arg(F[i]-cen));
		vector<point> Q;
		for(int r=1;r<=R;r++){
			get_intersect(circle(o,r),segment(F[i],F[(i+1)%n]),Q);
		}
		rep(j,Q.size()) theta.push_back(arg(Q[j]-cen));
	}
	theta.push_back(0);
	theta.push_back(PI/2);
	theta.push_back(PI);
	theta.push_back(3*PI/2);

	sort(theta.begin(),theta.end());
	theta.erase(unique(theta.begin(),theta.end(),eq),theta.end());

	double ans=0;
	rep(i,theta.size()){
		double t1=theta[i],t2=theta[(i+1)%theta.size()];
		if(t2<t1) t2+=2*PI;

		segment H1(cen,cen+rot(point(R+1,0),t1));
		segment H2(cen,cen+rot(point(R+1,0),t2));

		vector<double> A;
		for(int r=1;r<=R;r++){
			vector<point> tmp;
			get_intersect(circle(o,r),H1,tmp);
			get_intersect(circle(o,r),H2,tmp);
			double s1=arg(tmp[0]),s2=arg(tmp[1]);
			if(s2<s1) s2+=2*PI;
			A.push_back(r*r*(s2-s1)/2-area(o,tmp[0],tmp[1])+area(cen,tmp[0],tmp[1]));
		}
		rep(j,F.size()){
			segment S(F[j],F[(j+1)%n]);
			if(abs(cross(S.b-S.a,S.b-cen))>EPS && intersect(S,H1) && intersect(S,H2)){
				point a=get_intersect(S,H1);
				point b=get_intersect(S,H2);
				A.push_back(area(cen,a,b));
			}
		}
		sort(A.begin(),A.end());

		if(cover(F,cen)){
			A.insert(A.begin(),0);
		}
		for(int j=1;j<A.size();j+=2) ans+=A[j]-A[j-1];
	}

	printf("%.9f\n",ans);

	return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 1260
final_rank: 8

code_snippet: #include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <complex>
#include <cmath>
using namespace std;

typedef pair<double,double> pdd;
typedef complex<double> P;
typedef const P &rP;

#define EPS 1e-8

double dot(rP a, rP b){
	return real(a) * real(b) + imag(a) * imag(b);
}

double cross(rP a, rP b){
	return real(a) * imag(b) - imag(a) * real(b);
}

bool contains(const vector<P> &plg, rP p){
	int c = 0;
	double y = imag(p);
	
	for(int i = 1; i < plg.size(); ++i){
		double dy1 = imag(plg[i]) - y;
		double dy2 = y - imag(plg[i-1]);
		double tx = (dy1 * real(plg[i-1]) + dy2 * real(plg[i])) / (dy1 + dy2);

		if(imag(plg[i]) >= y && imag(plg[i-1]) < y){
			if(tx < real(p)){ ++c; }
		}
		else if(imag(plg[i]) < y && imag(plg[i-1]) >= y){
			if(tx < real(p)){ ++c; }
		}
	}
	
	return c % 2 != 0;
}

vector<P> intrlc(rP p1, rP p2, rP pc, double r){
	P v12 = p2 - p1, v1c = pc - p1;
	vector<P> ret;
	double a = norm(v12);
	double b = dot(v12, v1c);
	double c = norm(v1c) - r * r;
	double D = b * b - a * c;
	if(D >= 0.0){
		D = sqrt(D);
		double t1 = (b + D) / a, t2 = (b - D) / a;
		if(-EPS < t1 && t1 < 1.0 + EPS){
			ret.push_back(p1 + v12 * t1);
		}
		if(-EPS < t2 && t2 < 1.0 + EPS){
			ret.push_back(p1 + v12 * t2);
		}
	}
	return ret;
}

pdd intrll(rP pa1, rP pa2, rP pb1, rP pb2){
	P da12 = pa2 - pa1;
	P db21 = pb1 - pb2;
	P dab1 = pb1 - pa1;
	double D = cross(da12, db21);
	if(abs(D) < EPS){ return pdd(-1e300, -1e300); }
	return pdd(cross(dab1, db21) / D, cross(da12, dab1) / D);
}

int main(){
	double pi = acos(-1.0);

	int n, x, y;
	double r;
	scanf("%d%lf", &n, &r);
	
	vector<P> plg(n + 1);
	vector<double> args(1, 0.0);
	for(int i = 0; i < n; ++i){
		scanf("%d%d", &x, &y);
		plg[i] = P(x, y);
		if(x != 0 || y != 0){
			args.push_back(arg(plg[i]));
		}
	}
	plg[n] = plg[0];

	for(int i = 1; i < plg.size(); ++i){
		for(double j = 1.0; j <= r + EPS; j += 1.0){
			vector<P> res = intrlc(plg[i-1], plg[i], P(), j);
			for(int k = 0; k < res.size(); ++k){
				args.push_back(arg(res[k]));
			}
		}
	}

	sort(args.begin(), args.end());
	args.erase(unique(args.begin(), args.end()), args.end());
	args.push_back(args[0] + 2.0 * pi);

	double ans = 0.0;
	for(int i = 1; i < args.size(); ++i){
		double mid = 0.5 * (args[i-1] + args[i]);
		P d1 = polar(1.0, args[i-1]);
		P d2 = polar(1.0, mid);
		P d3 = polar(1.0, args[i]);

		vector<pdd> ev;
		for(double j = 1.0; j <= r + EPS; j += 1.0){
			ev.push_back(pdd(j, 0.5 * j * j * (args[i] - args[i-1])));
		}
		for(int j = 1; j < plg.size(); ++j){
			pdd t = intrll(P(), d2, plg[j-1], plg[j]);
			if(t.first > EPS && t.first < r){
				if(t.second > -EPS && t.second < 1.0 + EPS){
					P dif = plg[j-1] - plg[j];
					
					double u1 = intrll(plg[j], plg[j-1], P(), d1).first;
					double u2 = intrll(plg[j], plg[j-1], P(), d3).first;
					
					P a = plg[j] + u1 * dif;
					P b = plg[j] + u2 * dif;
					ev.push_back(pdd(t.first, 0.5 * abs(cross(a, b))));
				}
			}
		}
		
		if(contains(plg, polar(EPS, mid))){
			ev.push_back(pdd(0.0, 0.0));
		}
		
		sort(ev.begin(), ev.end());

		double S = 0.0;
		bool add = false;
		for(int j = 0; j < ev.size(); ++j){
			if(add){
				S += ev[j].second;
			}
			else if(j + 1 < ev.size()){
				S -= ev[j].second;
			}
			add = !add;
		}

		ans += S;
	}
	
	printf("%.15f\n", ans);
}
accuracy: 1
time_ms: 10
memory_kb: 1400
final_rank: 5