QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729639#9576. Ordainer of Inexorable Judgmentucup-team5243#WA 0ms4384kbC++1714.8kb2024-11-09 17:32:342024-11-09 17:32:35

Judging History

你现在查看的是最新测评结果

  • [2024-12-23 14:23:26]
  • hack成功,自动添加数据
  • (/hack/1303)
  • [2024-12-06 11:32:56]
  • hack成功,自动添加数据
  • (/hack/1271)
  • [2024-11-14 21:58:28]
  • hack成功,自动添加数据
  • (/hack/1181)
  • [2024-11-09 17:32:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4384kb
  • [2024-11-09 17:32:34]
  • 提交

answer

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
using namespace std;

#include <iterator>
#include <functional>
#include <utility>
#include <type_traits>

template<class Elem> struct vec;

template<class Iter>
struct seq_view{
    using Ref = typename std::iterator_traits<Iter>::reference;
    using Elem = typename std::iterator_traits<Iter>::value_type;
    Iter a, b;
    Iter begin() const { return a; }
    Iter end() const { return b; }
    int size() const { return (int)(b-a); }
    seq_view(Iter first, Iter last) : a(first), b(last) {}
    seq_view sort() const { std::sort(a, b); return *this; }
    Ref& operator[](int x) const { return *(a+x); }
    template<class F = std::less<Elem>, class ret = vec<int>> ret sorti(F f = F()) const {
        ret x(size()); for(int i=0; i<size(); i++) x[i] = i;
        x().sort([&](int l, int r){ return f(a[l],a[r]); });
        return x;
    }
    template<class ret = vec<Elem>> ret col() const { return ret(begin(), end()); }
    template<class ret = vec<Elem>> ret cumsum() const {
        auto res = ret(size() + 1, Elem(0));
        for(int i=0; i<size(); i++) res[i+1] = res[i] + operator[](i);
        return res;
    }
    template<class F = std::equal_to<Elem>, class ret = vec<std::pair<Elem, int>>>
    ret rle(F eq = F()) const {
        auto x = ret();
        for(auto& a : (*this)){
            if(x.size() == 0 || !eq(x[x.size()-1].first, a)) x.emp(a, 1); else x[x.size()-1].second++;
        } return x;
    }
    template<class F> seq_view sort(F f) const { std::sort(a, b, f); return *this; }
    Iter uni() const { return std::unique(a, b); }
    Iter lb(const Elem& x) const { return std::lower_bound(a, b, x); }
    Iter ub(const Elem& x) const { return std::upper_bound(a, b, x); }
    int lbi(const Elem& x) const { return lb(x) - a; }
    int ubi(const Elem& x) const { return ub(x) - a; }
    seq_view bound(const Elem& l, const Elem& r) const { return { lb(l), lb(r) }; }
    template<class F> Iter lb(const Elem& x, F f) const { return std::lower_bound(a, b, x, f); }
    template<class F> Iter ub(const Elem& x, F f) const { return std::upper_bound(a, b, x, f); }
    template<class F> Iter when_true_to_false(F f) const {
        if(a == b) return a;
        return std::lower_bound(a, b, *a,
            [&](const Elem& x, const Elem&){ return f(x); });
    }
    seq_view same(Elem x) const { return { lb(x), ub(x) }; }
    template<class F> auto map(F f) const {
        vec<decltype(f(std::declval<const typename Iter::value_type&>()))> r;
        for(auto& x : *this) r.emp(f(x));
        return r;
    }
    Iter max() const { return std::max_element(a, b); }
    Iter min() const { return std::min_element(a, b); }
    template<class F = std::less<Elem>>
    Iter min(F f) const { return std::min_element(a, b, f); }
    seq_view rev() const { std::reverse(a, b); return *this; }
};

template<class Elem>
struct vec {
public:
    using Base = typename std::vector<Elem>;
    using Iter = typename Base::iterator;
    using CIter = typename Base::const_iterator;
    using View = seq_view<Iter>;
    using CView = seq_view<CIter>;

    vec(){}
    explicit vec(int n, const Elem& value = Elem()) : a(0<n?n:0, value) {}
    template <class I2> vec(I2 first, I2 last) : a(first, last) {}
    vec(std::initializer_list<Elem> il) : a(std::move(il)) {}
    vec(Base b) : a(std::move(b)) {}
    operator Base() const { return a; }

    Iter begin(){ return a.begin(); }
    CIter begin() const { return a.begin(); }
    Iter end(){ return a.end(); }
    CIter end() const { return a.end(); }
    int size() const { return a.size(); }
    bool empty() const { return a.empty(); }
    Elem& back(){ return a.back(); }
    const Elem& back() const { return a.back(); }
    vec& sortuni(){ (*this)().sort(); a.erase((*this)().uni(), end()); return *this; }
    vec sortunied(){ vec x = *this; x.sortuni(); return x; }
    Iter operator()(int x){ return a.begin() + x; }
    CIter operator()(int x) const { return a.begin() + x; }
    View operator()(int l, int r){ return { (*this)(l), (*this)(r) }; }
    CView operator()(int l, int r) const { return { (*this)(l), (*this)(r) }; }
    View operator()(){ return (*this)(0,size()); }
    CView operator()() const { return (*this)(0,size()); }
    Elem& operator[](int x){ return a[x]; }
    const Elem& operator[](int x) const { return a[x]; }
    Base& operator*(){ return a; }
    const Base& operator*() const { return a; }
    vec& push(Elem args){
        a.push_back(std::move(args));
        return *this;
    }
    template<class... Args>
    vec& emp(Args &&... args){
        a.emplace_back(std::forward<Args>(args) ...);
        return *this;
    }
    template<class Range>
    vec& app(Range& x){ for(auto& v : x){ emp(v); } return *this; }
    Elem pop(){ Elem x = std::move(a.back()); a.pop_back(); return x; }
    void resize(int sz){ a.resize(sz); }
    void reserve(int sz){ a.reserve(sz); }
    bool operator==(const vec& r) const { return a == r.a; }
    bool operator!=(const vec& r) const { return a != r.a; }
    bool operator<(const vec& r) const { return a < r.a; }
    bool operator<=(const vec& r) const { return a <= r.a; }
    bool operator>(const vec& r) const { return a > r.a; }
    bool operator>=(const vec& r) const { return a >= r.a; }
    vec<vec<Elem>> pile(int n) const { return vec<vec<Elem>>(n, *this); }
    template<class F> vec& filter(F f){
        int p = 0;
        for(auto& x : a) if(f(x)) std::swap(a[p++],x);
        resize(p); return *this;
    }
    vec& operator+=(const vec& r){ return app(r); }
    vec operator+(const vec& r) const { vec x = *this; x += r; return x; }
    vec operator*(int t) const { vec res; while(t--){ res += *this; } return res; }
private: Base a;
};

template<class IStr, class U, class T>
IStr& operator>>(IStr& is, vec<std::pair<U,T>>& v){ for(auto& x:v){ is >> x.first >> x.second; } return is; }
template<class IStr, class T>
IStr& operator>>(IStr& is, vec<T>& v){ for(auto& x:v){ is >> x; } return is; }
template<class OStr, class T>
OStr& operator<<(OStr& os, const vec<T>& v){
    for(int i=0; i<v.size(); i++){
        if(i){ os << ' '; } os << v[i];
    } return os;
}
template<class OStr, class U, class T>
OStr& operator<<(OStr& os, const vec<std::pair<U,T>>& v){
    for(int i=0; i<v.size(); i++){
        if(i){ os << ' '; } os << '(' << v[i].first << ',' << v[i].second << ')';
    } return os;
}

namespace nachia{

template<class Int = long long, class Int2 = long long>
struct VecI2 {
    Int x, y;
    VecI2() : x(0), y(0) {}
    VecI2(std::pair<Int, Int> _p) : x(std::move(_p.first)), y(std::move(_p.second)) {}
    VecI2(Int _x, Int _y) : x(std::move(_x)), y(std::move(_y)) {}
    VecI2& operator+=(VecI2 r){ x+=r.x; y+=r.y; return *this; }
    VecI2& operator-=(VecI2 r){ x-=r.x; y-=r.y; return *this; }
    VecI2& operator*=(Int r){ x*=r; y*=r; return *this; }
    VecI2 operator+(VecI2 r) const { return VecI2(x+r.x, y+r.y); }
    VecI2 operator-(VecI2 r) const { return VecI2(x-r.x, y-r.y); }
    VecI2 operator*(Int r) const { return VecI2(x*r, y*r); }
    VecI2 operator-() const { return VecI2(-x, -y); }
    Int2 operator*(VecI2 r) const { return Int2(x) * Int2(r.x) + Int2(y) * Int2(r.y); }
    Int2 operator^(VecI2 r) const { return Int2(x) * Int2(r.y) - Int2(y) * Int2(r.x); }
    bool operator<(VecI2 r) const { return x < r.x || (!(r.x < x) && y < r.y); }
    Int2 norm() const { return Int2(x) * Int2(x) + Int2(y) * Int2(y); }
    Int2 manhattan() const { return std::abs(x) + std::abs(y); }
    static bool compareYX(VecI2 a, VecI2 b){ return a.y < b.y || (!(b.y < a.y) && a.x < b.x); }
    static bool compareXY(VecI2 a, VecI2 b){ return a.x < b.x || (!(b.x < a.x) && a.y < b.y); }
    bool operator==(VecI2 r) const { return x == r.x && y == r.y; }
    bool operator!=(VecI2 r) const { return x != r.x || y != r.y; }
};

} // namespace nachia

namespace nachia{

template<class Int, class Int2>
std::vector<int> SortPointsByArgument(
    const std::vector<VecI2<Int, Int2>>& points
){
    int n = points.size();
    auto p = points.begin();
    std::vector<int> sp[9];
    for(int i=0; i<n; i++){
        int id = 0;
        if(p[i].x == 0) id += 1;
        if(p[i].x > 0) id += 2;
        if(p[i].y == 0) id += 3;
        if(p[i].y > 0) id += 6;
        sp[id].push_back(i);
    }
    auto cmp = [p](int l, int r) -> bool {
        return (p[l] ^ p[r]) > 0;
    };
    for(int t=0; t<9; t++){
        std::sort(sp[t].begin(), sp[t].end(), cmp);
    }
    std::vector<int> res(n);
    auto itr = res.begin();
    for(int id : { 0, 1, 2, 4, 5, 8, 7, 6, 3 }){
        itr = std::copy(sp[id].begin(), sp[id].end(), itr);
    }
    return res;
}

} // namespace nachia

namespace nachia{

template<class Float = double>
struct VecF2 {
    Float x, y;
    VecF2() : x(0), y(0) {}
    VecF2(std::pair<Float, Float> _p) : x(std::move(_p.first)), y(std::move(_p.second)) {}
    VecF2(Float _x, Float _y) : x(std::move(_x)), y(std::move(_y)) {}
    VecF2& operator+=(VecF2 r){ x+=r.x; y+=r.y; return *this; }
    VecF2& operator-=(VecF2 r){ x-=r.x; y-=r.y; return *this; }
    VecF2& operator*=(Float r){ x*=r; y*=r; return *this; }
    VecF2& operator/=(Float r){ x/=r; y/=r; return *this; }
    VecF2 operator+(VecF2 r) const { return VecF2(x+r.x, y+r.y); }
    VecF2 operator-(VecF2 r) const { return VecF2(x-r.x, y-r.y); }
    VecF2 operator*(Float r) const { return VecF2(x*r, y*r); }
    VecF2 operator/(Float r) const { return VecF2(x/r, y/r); }
    VecF2 operator-() const { return VecF2(-x, -y); }
    Float operator*(VecF2 r) const { return x * r.x + y * r.y; }
    Float operator^(VecF2 r) const { return x * r.y - y * r.x; }
    bool operator<(VecF2 r) const { return x < r.x || (!(r.x < x) && y < r.y); }
    Float norm() const { return x * x + y * y; }
    Float manhattan() const { return std::abs(x) + std::abs(y); }
    static bool compareYX(VecF2 a, VecF2 b){ return a.y < b.y || (!(b.y < a.y) && a.x < b.x); }
    static bool compareXY(VecF2 a, VecF2 b){ return a.x < b.x || (!(b.x < a.x) && a.y < b.y); }
    bool operator==(VecF2 r) const { return x == r.x && y == r.y; }
    bool operator!=(VecF2 r) const { return x != r.x || y != r.y; }
};

} // namespace nachia
template<typename Int>
Int CeilDiv(Int a, Int b){
    if(b < Int(0)){ a = -a; b = -b; }
    if(a < Int(0) || a % b == Int(0)) return a / b;
    return a / b + Int(1);
}


void testcase(){
    using Vec2 = nachia::VecF2<double>;
    using VecI2 = nachia::VecI2<i64,i64>;
    auto SegIntersect = [](VecI2 a, VecI2 b, VecI2 c, VecI2 d) -> bool {
        i64 det1 = (b - a) ^ (c - a);
        i64 det2 = (b - a) ^ (d - a);
        i64 det3 = (d - c) ^ (a - c);
        i64 det4 = (d - c) ^ (b - c);
        if(det1 < 0 && det2 < 0) return false;
        if(det1 > 0 && det2 > 0) return false;
        if(det3 < 0 && det4 < 0) return false;
        if(det3 > 0 && det4 > 0) return false;
        return true;
    };
    auto SegIntersect2 = [](Vec2 a, Vec2 b, Vec2 c, Vec2 d) -> bool {
        double det1 = (b - a) ^ (c - a);
        double det2 = (b - a) ^ (d - a);
        double det3 = (d - c) ^ (a - c);
        double det4 = (d - c) ^ (b - c);
        if(det1 < 0 && det2 < 0) return false;
        if(det1 > 0 && det2 > 0) return false;
        if(det3 < 0 && det4 < 0) return false;
        if(det3 > 0 && det4 > 0) return false;
        return true;
    };
    auto PointLineDist = [](Vec2 v, Vec2 w, Vec2 p) -> double {
        double a = v.y - w.y;
        double b = w.x - v.x;
        double c = -(a * v.x + b * v.y);
        return abs(a * p.x + b * p.y + c) / sqrt(a*a + b*b);
    };
    i64 N; cin >> N;
    Vec2 s; cin >> s.x >> s.y;
    i64 dint; cin >> dint;
    double d, t; d = dint; cin >> t;
    cout.precision(10);
    cout << fixed;
    vec<VecI2> Aint(N);
    rep(i,N) cin >> Aint[i].x >> Aint[i].y;

    auto judgeZero = [&](VecI2 a, VecI2 b) -> bool {
        if(a.norm() <= dint * dint) return true;
        if(b.norm() <= dint * dint) return true;
        if(a * (a - b) < 0) return false;
        if(b * (b - a) < 0) return false;
        i64 area = abs(a ^ b); area *= area;
        i64 h = CeilDiv(area, (b - a).norm());
        return h <= d * d;
    };
    rep(i,N){
        if(judgeZero(Aint[i], Aint[(i+1)%N])){
            cout << t << endl;
            return;
        }
    }

    vec<Vec2> A(N);

    auto argi = nachia::SortPointsByArgument<i64,i64>(Aint);
    rep(i,N-1) if((Aint[argi[i]] ^ Aint[argi[i+1]]) < 0){
        rotate(argi.begin(), argi.begin() + (i+1), argi.end());
        break;
    }

    double PI = acos(-1.0);

    rep(i,N) A[i] = { Aint[argi[i]].x, Aint[argi[i]].y };
    double larg = atan2(A[0].y, A[0].x);
    double rarg = atan2(A.back().y, A.back().x);
    if(larg > rarg) larg -= PI;

    //cout << "larg = " << larg << endl;
    //cout << "rarg = " << rarg << endl;

    {
        double ok = larg;
        double ng = larg - PI * 0.5;
        rep(loopcnt,50){
            double th = (ok + ng) / 2.0;
            auto vec = Vec2(cos(th), sin(th));
            bool ins = false;
            rep(i,N) if(vec * A[i] >= 0.0 && PointLineDist(Vec2(0.0, 0.0), vec, A[i]) <= d) ins = true;
            (ins ? ok : ng) = th;
        }
        larg = ok;
    }
    {
        double ok = rarg;
        double ng = rarg + PI * 0.5;
        rep(loopcnt,50){
            double th = (ok + ng) / 2.0;
            auto vec = Vec2(cos(th), sin(th));
            bool ins = false;
            rep(i,N) if(vec * A[i] >= 0.0 && PointLineDist(Vec2(0.0, 0.0), vec, A[i]) <= d) ins = true;
            (ins ? ok : ng) = th;
        }
        rarg = ok;
    }

    //cout << "larg = " << larg << endl;
    //cout << "rarg = " << rarg << endl;

    double startarg = atan2(s.y, s.x);
    larg -= startarg;
    rarg -= startarg;

    while(PI * 2.0 <= rarg){ larg -= PI * 2.0; rarg -= PI * 2.0; }
    while(rarg < 0.0){ larg += PI * 2.0; rarg += PI * 2.0; }

    double ans = 0.0;
    if(larg < 0.0){
        ans -= -larg; t += -larg;
        rarg += -larg;
        larg = 0.0;
    }

    i64 divfloor = floor(t / (PI * 2.0));
    ans += (rarg - larg) * divfloor;
    t -= (PI * 2.0) * divfloor;
    ans += min(rarg, t);
    ans -= min(larg, t);
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4308kb

input:

3 1 0 1 1
1 2
2 1
2 2

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4320kb

input:

3 1 0 1 2
1 2
2 1
2 2

output:

1.5707963268

result:

ok found '1.5707963', expected '1.5707963', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 4324kb

input:

3 1 0 1 10000
1 2
2 1
2 2

output:

2500.7077522575

result:

ok found '2500.7077523', expected '2500.7077523', error '0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 4384kb

input:

3 10000 10000 1 10000
10000 9999
10000 10000
9999 10000

output:

0.3842413003

result:

ok found '0.3842413', expected '0.3842413', error '0.0000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 4236kb

input:

3 -10000 -10000 10000 10000
-10000 -9999
-10000 -10000
-9999 -10000

output:

2500.2406700096

result:

ok found '2500.2406700', expected '2500.2406700', error '0.0000000'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 4336kb

input:

4 1 0 1 10000
-2 3400
-4 10000
-4 -10000
-2 -3400

output:

0.9358822045

result:

wrong answer 1st numbers differ - expected: '4999.2191154', found: '0.9358822', error = '0.9998128'