QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#836672#9922. Mah-jongucup-team3584#WA 522ms3696kbC++203.9kb2024-12-29 03:35:482024-12-29 03:35:48

Judging History

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

  • [2024-12-29 03:35:48]
  • 评测
  • 测评结果:WA
  • 用时:522ms
  • 内存:3696kb
  • [2024-12-29 03:35:48]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

template <int mod> struct static_modint {
    using mint = static_modint;
    int x;

    static_modint() : x(0) {}
    static_modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    mint &operator+=(const mint &rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint &rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint &rhs) {
        x = (int)(1LL * x * rhs.x % mod);
        return *this;
    }
    mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); }

    mint pow(long long n) const {
        mint _x = *this, r = 1;
        while (n) {
            if (n & 1) r *= _x;
            _x *= _x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const { return pow(mod - 2); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
    friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
    friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
    friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
    friend bool operator==(const mint &lhs, const mint &rhs) { return lhs.x == rhs.x; }
    friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs.x != rhs.x; }

    friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
    friend istream &operator>>(istream &is, mint &a) {
        int64_t t;
        is >> t;
        a = static_modint<mod>(t);
        return (is);
    }
};

const unsigned int mod = 998244353;
using modint = static_modint<mod>;
modint mod_pow(ll n, ll x) { return modint(n).pow(x); }
modint mod_pow(modint n, ll x) { return n.pow(x); }

int dp[6561];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    vector<vector<int>> v;
    vector<int> uo(8);
    auto dfs = [&](auto dfs, int i) -> void {
        if (i + 2 == 8) {
            v.push_back(uo);
            return;
        }
        for (int k = 0; k <= 2; k++) {
            uo[i] += k, uo[i + 1] += k, uo[i + 2] += k;
            dfs(dfs, i + 1);
            uo[i] -= k, uo[i + 1] -= k, uo[i + 2] -= k;
        }
    };
    dfs(dfs, 0);

    int q;
    cin >> q;
    while (q--) {
        memset(dp, 0, sizeof(dp));
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        auto calc = [&](vector<int> &cnt) -> int {
            int res = 0;
            for (int i = 0; i < 8; ++i) {
                res = res * 3 + cnt[i];
            }
            return res;
        };
        ll res = 0;
        vector<int> cnt(8), cnt2(8), tmp(8);
        dp[calc(cnt)] = 1;
        for (int i = 0; i < n; ++i) {
            cnt[a[i] - 1] += 1;
            cnt2[a[i] - 1] += 1;
            if (cnt2[a[i] - 1] == 3) {
                cnt2[a[i] - 1] = 0;
            }
            for (auto &x : v) {
                bool ok = true;
                for (int j = 0; j < 8; ++j) {
                    if (cnt[j] < x[j]) {
                        ok = false;
                        break;
                    } else {
                        tmp[j] = (cnt[j] - x[j]) % 3;
                    }
                }
                if (ok) {
                    res += dp[calc(tmp)];
                }
            }
            dp[calc(cnt2)] += 1;
        }
        cout << res << '\n';
    }
}

详细

Test #1:

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

input:

5
4
1 1 1 1
6
1 2 3 1 2 3
7
6 5 8 7 6 3 2
8
1 2 1 2 1 2 1 3
9
2 2 4 4 1 1 1 3 3

output:

2
5
1
3
2

result:

ok 5 number(s): "2 5 1 3 2"

Test #2:

score: -100
Wrong Answer
time: 522ms
memory: 3660kb

input:

100
992
8 1 8 1 2 3 6 6 1 3 1 8 7 7 4 7 7 1 6 6 4 8 3 7 3 5 1 4 4 7 5 7 5 7 4 3 7 5 2 8 7 1 6 3 6 2 4 3 2 3 1 6 3 1 3 2 6 6 7 4 6 1 1 4 6 4 7 7 8 5 6 4 1 5 4 8 2 4 4 2 1 3 5 7 6 8 3 7 6 6 5 6 4 2 5 4 3 7 3 5 5 3 3 2 7 8 2 7 2 4 4 3 4 1 1 3 5 5 4 6 3 3 3 2 6 1 2 6 4 8 8 6 6 8 7 3 1 1 8 8 7 2 5 6 3 5 ...

output:

54611
65045
5863
2450
248073
7119
12431
48687
443481
1233932
19142
143983
306768
973691
223671
1693
91315
145847
73072
1
82628
0
42058
18421
90267
0
104563
167091
3
521177
61750
202416
28257
64928
31123
12820
2493
5247
78104
919402
178810
26044
870
91985
1320319
1840
13119
161273
12933
25118
27138
1...

result:

wrong answer 1st numbers differ - expected: '51699', found: '54611'