QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#601405#975. GamefractalWA 45ms25136kbC++173.2kb2024-09-29 23:03:182024-09-29 23:03:19

Judging History

This is the latest submission verdict.

  • [2024-09-29 23:03:19]
  • Judged
  • Verdict: WA
  • Time: 45ms
  • Memory: 25136kb
  • [2024-09-29 23:03:18]
  • Submitted

answer

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

#define F first
#define S second
#define sz(x) (int)x.size()

const int N = 1e6;

struct point {


    long long x, y;

    point (long long x = 0, long long y = 0) : x(x), y(y) {}

    point norm() {
        return point(-y, x);
    }

    long double l() {
        return sqrt(x * x + y * y);
    }

    point unit() {
        return point(x / this->l(), y / this->l());
    }

    point operator*(const long double c) {
        return point(x * c, y * c);
    }

    point operator/(const long double c) {
        return point(x / c, y / c);
    }

    point operator+(const point a) {
        return point(x + a.x, y + a.y);
    }

    point operator-(const point a) {
        return point(x - a.x, y - a.y);
    }

    long long operator*(const point a) {
        return x * a.y - y * a.x;
    }

    long long operator%(const point a) {
        return x * a.x + y * a.y;
    }

    bool operator<(const point a) {
        if (x == a.x)
            return y < a.y;
        return x < a.x;
    }

    bool operator==(const point a) {
        return x == a.x && y == a.y;
    }

    int pos() {
        return !(y > 0 || (y == 0 && x > 0));
    }
};

long double dist(point a, point b) {
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

ostream& operator<<(ostream &out, const point &a) {
    return out << "(" << a.x << ", " << a.y << ")";
}

istream& operator>>(istream &in, point &a) {
    return in >> a.x >> a.y;
}

bool operator<(const point &a, const point &b) {
    if (a.x == b.x)
        return a.y < b.y;
    return a.x < b.x;
}

bool operator==(const point &a, const point &b) {
    return a.x == b.x && a.y == b.y;
}

using pt=point;
using pts=vector<pt>;

void add(pts &h, pt &p) {
    if (h.size() <= 1) {
        h.push_back(p);
        return;
    }
    if (h.back() == p) {
        return;
    }
    while (h.size() > 1 && (h.end()[-1] - h.end()[-2]) * (p - h.end()[-1]) >= 0) {
        h.pop_back();
    }
    h.push_back(p);
    return;
}

pts hull(pts s) {
    if (s.size() == 0) return s;
    sort(s.begin(), s.end());
    pts upper;
    for (auto p : s) {
        add(upper, p);
    }
    return upper;
}

long long n;
long long a[N];
long long dp[N];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] *= 2;
    }
    pts s;
    for (int i = 1; i <= n; ++i)
        s.push_back(pt(i, a[i]));
    s = hull(s);
    vector<int> used(n + 1, 0);
    for (auto [i, x] : s) {
        used[i] = 1;
    }
    int last = 0;
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (used[i] == 1) {
            last = a[i];
        }
        ans += last / 2;
    }
    last = 0;
    for (int i = n; i >= 1; --i) {
        if (used[i] == 1) {
            last = a[i];
        }
        ans += last / 2;
    }
    long long r = 1;
    n *= 2;
    const int mod = 998244353;
    long long pw = mod - 2;
    while (pw) {
        if (pw & 1) r = (r * n) % mod;
        n = (n * n) % mod;
        pw /= 2;
    }
    ans = (ans * r) % mod;
    cout << ans << '\n';
}

詳細信息

Test #1:

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

input:

3
3 1 2

output:

499122179

result:

ok "499122179"

Test #2:

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

input:

6
6 1 2 5 3 4

output:

582309211

result:

ok "582309211"

Test #3:

score: -100
Wrong Answer
time: 45ms
memory: 25136kb

input:

500000
131592496991 614154464278 882215024371 954828734583 997777248498 677111110098 927405745589 218490006270 743425189504 391435077446 972647376673 630405853326 714899101544 90679613430 530369364312 763893201576 838136940841 261795310871 187042095193 941416320169 688136558810 554872601435 54089147...

output:

-783531193

result:

wrong answer 1st words differ - expected: '131032905', found: '-783531193'