QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796683#9115. Contour MultiplicationrgnerdplayerWA 0ms3844kbC++233.4kb2024-12-01 23:40:482024-12-01 23:40:49

Judging History

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

  • [2024-12-01 23:40:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-12-01 23:40:48]
  • 提交

answer

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

using i64 = long long;

template <int &MOD>
struct Modint {
    static constexpr int &P = MOD;

private:
    int v;

    static int minv(int a, int m) {
        a %= m;
        assert(a);
        return a == 1 ? 1 : m - 1LL * minv(m, a) * m / a;
    }

public:
    Modint() : v(0) {}
    Modint(i64 v_) : v(v_ % P) {
        if (v < 0) v += P;
    }
    explicit operator int() const { return v; }
    friend ostream& operator<<(ostream &out, const Modint &n) {
        return out << int(n);
    }
    friend istream& operator>>(istream &in, Modint &n) {
        i64 v;
        in >> v;
        n = Modint(v);
        return in;
    }
    friend string to_string(Modint a) {
        return to_string(int(a));
    }

    friend bool operator==(const Modint &a, const Modint &b) {
        return a.v == b.v;
    }
    friend bool operator!=(const Modint &a, const Modint &b) {
        return a.v != b.v;
    }

    Modint inv() const {
        Modint res;
        res.v = minv(v, P);
        return res;
    }

    Modint operator-() const {
        Modint res;
        res.v = v ? P - v : 0;
        return res;
    }

    Modint& operator++() {
        v++;
        if (v == P) v = 0;
        return *this;
    }
    Modint& operator--() {
        if (v == 0) v = P;
        v--;
        return *this;
    }
    Modint& operator+=(const Modint &o) {
        v -= P - o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    Modint& operator-=(const Modint &o) {
        v -= o.v;
        v = (v < 0) ? v + P : v;
        return *this;
    }
    Modint& operator*=(const Modint &o) {
        v = 1LL * v * o.v % P;
        return *this;
    }
    Modint& operator/=(const Modint &o) { return *this *= o.inv(); }

    friend Modint operator++(Modint &a, int) {
        Modint r = a;
        ++a;
        return r;
    }
    friend Modint operator--(Modint &a, int) {
        Modint r = a;
        --a;
        return r;
    }

    friend Modint operator+(const Modint &a, const Modint &b) {
        return Modint(a) += b;
    }
    friend Modint operator-(const Modint &a, const Modint &b) {
        return Modint(a) -= b;
    }
    friend Modint operator*(const Modint &a, const Modint &b) {
        return Modint(a) *= b;
    }
    friend Modint operator/(const Modint &a, const Modint &b) {
        return Modint(a) /= b;
    }
    
    Modint qpow(i64 p) {
        Modint res = 1, x = v;
        while (p > 0) {
            if (p & 1) res *= x;
            x *= x;
            p >>= 1;
        }
        return res;
    }
};

int P;
using Mint = Modint<P>;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    auto solve = [&]() {
        int n, q;
        cin >> n >> P >> q;

        vector dp(1 << n, vector<Mint>(n + 1, 1));
        for (int i = 0; i < q; i++) {
            int c, d, x;
            cin >> c >> d >> x;
            dp[c][d] *= x;
        }

        for (int bit = 0; bit < n; bit++) {
            for (int j = n; j > 0; j--) {
                for (int i = 0; i < 1 << n; i++) {
                    dp[i][j - 1] *= dp[i ^ 1 << bit][j];
                }
            }
        }

        for (int i = 0; i < 1 << n; i++) {
            cout << dp[i][0] << " \n"[i + 1 == 1 << n];
        }
    };
    
    solve();
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3844kb

input:

3 100 2
0 2 4
3 0 25

output:

64 1 1 0 1 4 4 1

result:

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