QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#799291#9804. Guess the Polygonkjhhjki#WA 1ms3872kbC++204.3kb2024-12-05 10:06:142024-12-05 10:06:15

Judging History

This is the latest submission verdict.

  • [2024-12-05 10:06:15]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3872kb
  • [2024-12-05 10:06:14]
  • Submitted

answer

#include <bits/stdc++.h>

using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using f64 = long double;

template<typename T, typename U>
void chkmax(T &a, U b) { if(a < b) a = b; }
template<typename T, typename U>
void chkmin(T &a, U b) { if(a > b) a = b; }

constexpr int P = 998244353;

void init() { }

// constexpr i64 MOD = 100055128505716009ll;

template<typename T>
constexpr T qpow(T x, i64 n)
{
    T res(1);
    while(n)
    {
        if(n&1) res *= x;
        x *= x; n >>= 1;
    }
    return res;
}

template<u32 P>
constexpr u32 mul(u32 a, u32 b) {
    return 1llu * a * b % P;
}

template<u64 P>
constexpr u64 mul(u64 a, u64 b) {
    u64 res = a * b - u64(1.l * a * b / P - 0.5l) * P;
    res %= P;
    return res;
}

template<typename U, U P>
requires std::unsigned_integral<U>
struct MIntBase
{
    U x;

    constexpr MIntBase() : x(0) {}
    template<typename T>
    requires std::integral<T>
    constexpr MIntBase(T x_) : x(norm(x_ % P)) {}

    constexpr U norm(U x)
    {
        if ((x >> (8 * sizeof(U) - 1) & 1) == 1) {
            x += P;
        }
        if (x >= P) {
            x -= P;
        }
        return x;
    }
    constexpr int val() const { return x; }
    explicit constexpr operator U() const { return x; }

    constexpr MIntBase operator+=(const MIntBase o) { return x = norm(x+o.x), *this; }
    constexpr MIntBase operator-=(const MIntBase o) { return x = norm(x-o.x), *this; }
    constexpr MIntBase operator*=(const MIntBase o) { return x = mul<P>(x, o.val()), *this; }
    constexpr MIntBase operator/=(const MIntBase o) { return *this *= o.inv(); }
    friend constexpr MIntBase operator+(const MIntBase a, const MIntBase b) { MIntBase res(a); return res += b; }
    friend constexpr MIntBase operator-(const MIntBase a, const MIntBase b) { MIntBase res(a); return res -= b; }
    friend constexpr MIntBase operator*(const MIntBase a, const MIntBase b) { MIntBase res(a); return res *= b; }
    friend constexpr MIntBase operator/(const MIntBase a, const MIntBase b) { MIntBase res(a); return res /= b; }
    friend constexpr MIntBase operator-(const MIntBase a) { MIntBase res(0); return res -= a; }

    friend constexpr bool operator==(const MIntBase &a, const MIntBase &b) { return a.x == b.x; }
    friend constexpr bool operator!=(const MIntBase &a, const MIntBase &b) { return a.x != b.x; }
    friend constexpr auto operator<=>(const MIntBase &a, const MIntBase &b) { return a.x <=> b.x; }
    friend std::istream &operator>>(std::istream &is, MIntBase &a) { is >> a.x, a.x = a.norm(a.x); return is; }
    friend std::ostream &operator<<(std::ostream &os, const MIntBase &a) { return os << a.x; }

    constexpr MIntBase inv() const { return qpow(*this, P-2); }
};

template<u32 P>
using MInt= MIntBase<u32, P>;

template<u64 P>
using MLong = MIntBase<u64, P>;

using Z = MInt<P>;
// template<>
// u32 Z::mod = 0;

void solve()
{
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> a(n);
    std::vector<int> xs;
    for(auto &[x, y]: a) {
        std::cin >> x >> y;
        xs.push_back(x);
    }
    {
        std::ranges::sort(xs);
        auto [l, r] = std::ranges::unique(xs);
        xs.erase(l, r);
    }
    Z ans = 0;
    auto query = [](int p, int q) {
        std::cout << p << ' ' << q << '\n';
        std::string s, t;
        std::cin >> s >> t;
        Z x = 0, y = 0;
        for(auto ch: s) {
            x = x * 10 + ch - '0';
        }
        for(auto ch: t) {
            y = y * 10 + ch - '0';
        }
        return x / y;
    };
    if(n == (int)xs.size()) {
        std::vector<Z> val(n);
        for(int i = 1; i + 1 < n; ++i) {
            val[i] = query(xs[i], 1);
        }
        for(int i = 0; i + 1 < n; ++i) {
            ans += (val[i] + val[i + 1]) * (xs[i + 1] - xs[i]) / 2;
        }
    } else {
        n = xs.size();
        for(int i = 0; i + 1 < n; ++i) {
            Z val = query(xs[i] + xs[i + 1], 2);
            ans += val * (xs[i + 1] - xs[i]);
        }
    }
    if(ans > 1'000'000) {
        ans *= 2;
    }
    std::cout << ans << '\n';
}

int main()
{
    std::ios::sync_with_stdio(false);
    // std::cin.tie(nullptr);
    init();
    int T = 1;
    std::cin >> T;
    while(T --) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3872kb

input:

2
4
3 0
1 3
1 1
0 0

output:

1 2

result:

wrong answer unexpected option: 1 (test case 1)