QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#498759#7674. SkiingMax_s_xaMWA 1ms6768kbC++147.0kb2024-07-30 19:26:272024-07-30 19:26:27

Judging History

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

  • [2024-07-30 19:26:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6768kb
  • [2024-07-30 19:26:27]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 260;
const lf eps = 1e-9;

int n; lf vy, ax;

struct Point
{
    lf x, y; int id;
    bool operator < (const Point &u) const { return (fabs(y - u.y) < eps ? id < u.id : y < u.y); }
}a[MAXN];

struct Line
{
    lf x, y;
    bool operator < (const Line &u) const { return x == u.x ? y > u.y : x < u.x; }
};
struct Answer
{
    // vector <int> res;
    vector <Line> d;
}f[MAXN][MAXN];
vector <Line> mg;

inline lf Calc(lf v1, lf v2, lf t)
{
    return (v1 + v2) * t / 2;
}

inline pair <lf, lf> Solve(lf mn, lf mx, lf t, lf dist)
{
    if (fabs(t) < eps) return {mn, mx};
    lf l = dist / t - ax * t / 2, r = dist / t + ax * t / 2, b, c, delta;
    if (Calc(mx + ax * t, mx, t) < dist) return {1e20, -1e20};
    if (Calc(mx - ax * t, mx, t) < dist)
    {
        b = -2 * (ax * t + mx), c = -ax * ax * t * t - 2 * ax * t * mx + mx * mx + 4 * ax * dist;
        delta = b * b - 4 * c;
        l = max(l, (-b - sqrt(delta)) / 2);
    }
    if (Calc(mn - ax * t, mn, t) > dist) return {1e20, -1e20};
    if (Calc(mn + ax * t, mn, t) > dist)
    {
        b = 2 * (ax * t - mn), c = -ax * ax * t * t + 2 * ax * t * mn + mn * mn - 4 * ax * dist;
        delta = b * b - 4 * c;
        r = min(r, (-b + sqrt(delta)) / 2);
    }
    return make_pair(l, r);
}

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n), Read(vy), Read(ax);
    for (int i = 1, j = 1; i <= n; i++, j++)
    {
        Read(a[i].x), Read(a[i].y);
        if (a[i].y < 0) { i--, n--; continue; }
        a[i].y /= vy, a[i].id = j;
    }
    a[++n] = Point{0, 0, 0};
    sort(a + 1, a + n + 1);
    if (ax == 0)
    {
        bool flag = 0;
        for (int i = 2; i <= n; i++)
            if (a[i].x == 0) { cout << a[i].id << ' '; flag = 1; }
        if (!flag) cout << "Cannot visit any targets\n";
        return 0;
    }
    // for (int i = 1; i <= n; i++) cout << a[i].x << ' ' << a[i].y << '\n';
    for (int i = 1; i <= n; i++)
    {
        // f[i][1].res.push_back(a[i].id);
        f[i][1].d.push_back(Line{-1e50, 1e50});
    }
    for (int i = n; i >= 1; i--)
        for (int k = 1; k <= n - i + 1; k++)
        {
            if (!f[i][k].d.size()) continue;
            sort(f[i][k].d.begin(), f[i][k].d.end());
            lf pl = -1e51, pr = -1e51;
            mg.clear();
            for (auto [x, y] : f[i][k].d)
            {
                if (x > pr)
                {
                    if (pl != -1e51) mg.push_back(Line{pl, pr});
                    pl = x, pr = y;
                }
                else pr = max(pr, y);
            }
            if (pl != -1e51) mg.push_back(Line{pl, pr});
            f[i][k].d = mg;
            // cout << "Solve " << a[i].id << ' ' << k << ' ' << a[i].x << ' ' << a[i].y << "\n";
            // for (auto [x, y] : f[i][k].d) cout << x << ' ' << y << "\n";
            // cout << "\n";
            for (int j = i - 1; j >= 1; j--)
            {
                // if (f[j].res.size() > f[i].res.size() + 1 || (f[j].res.size() == f[i].res.size() + 1 && f[j].res[1] < a[i].id)) continue;
                lf len = a[i].y - a[j].y, dist = a[i].x - a[j].x;
                mg.clear();
                for (auto [x, y] : f[i][k].d)
                {
                    auto cur = Solve(x, y, len, dist);
                    if (cur.first > cur.second) continue;
                    mg.push_back(Line{cur.first, cur.second});
                }
                if (mg.size())
                {
                    if (j == 1)
                    {
                        bool flag = 0;
                        for (auto [x, y] : mg)
                            if ((x < 0 || fabs(x) < eps) && (y > 0 || fabs(y) < eps)) { flag = 1; break; }
                        if (!flag) continue;
                    }
                    // f[j].res = {a[j].id};
                    // for (auto x : f[i].res) f[j].res.push_back(x);
                    for (auto x : mg) f[j][k + 1].d.push_back(x);
                    // cout << "Trans " << a[i].id << ' ' << k << ' ' << a[j].id << '\n';
                }
            }
        }
    int x = 1, y = 1;
    while (f[1][y].d.size()) y++; y--;
    if (y == 1) return cout << "Cannot visit any targets\n", 0;
    // cout << "-----------\n";
    // cout << x << ' ' << y << "\n";
    lf l = 0, r = 0; a[n + 1].id = 2e9;
    for (int i = y - 1; i >= 1; i--)
    {
        int p = n + 1; lf pl = 0, pr = 0;
        // cout << "srch " << x << ' ' << y << '\n';
        for (int j = x + 1; j <= n; j++)
        {
            if (a[j].id > a[p].id || !f[j][i].d.size()) continue;
            lf len = a[j].y - a[x].y, dist = a[j].x - a[x].x;
            auto cur = Solve(l, r, len, dist);
            if (cur.first > cur.second) continue;
            for (auto [xx, yy] : f[j][i].d)
                if (xx <= cur.second && cur.first <= yy) { pl = cur.first, pr = cur.second, p = j; break; }
        }
        x = p, l = pl, r = pr;
        cout << a[x].id << ' ';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6540kb

input:

4 100 400
-100 100
50 200
-100 300
150 300

output:

1 2 4 

result:

ok single line: '1 2 4 '

Test #2:

score: 0
Accepted
time: 1ms
memory: 6768kb

input:

1 100 100
1000 10

output:

Cannot visit any targets

result:

ok single line: 'Cannot visit any targets'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5928kb

input:

0 100 100

output:

Cannot visit any targets

result:

ok single line: 'Cannot visit any targets'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5192kb

input:

2 100 100
100 100
-100 100

output:

Cannot visit any targets

result:

ok single line: 'Cannot visit any targets'

Test #5:

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

input:

2 1000 2001
1000 1000
-1000 1000

output:

1 2 

result:

wrong answer 1st lines differ - expected: '1', found: '1 2 '