QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#762343#9627. 算术superguymj#WA 0ms3856kbC++204.2kb2024-11-19 14:42:222024-11-19 14:42:27

Judging History

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

  • [2024-11-19 14:42:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-11-19 14:42:22]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,x,y) for (int i = x; i <= y; i++)
#define repd(i,x,y) for (int i = x; i >= y; i--)
#define mid ((l + r) >> 1)
#define lch (rt << 1)
#define rch (rt << 1 | 1)

using namespace std;

using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
 
// TODO: Dynamic ModInt
 
template<typename T>
constexpr T power(T a, u64 b) {
    T res {1};
    for (; b != 0; b /= 2, a *= a) {
        if (b % 2 == 1) {
            res *= a;
        }
    }
    return res;
}
 
template<u32 P>
constexpr u32 mulMod(u32 a, u32 b) {
    return 1ULL * a * b % P;
}
 
template<u64 P>
constexpr u64 mulMod(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>
struct ModIntBase {
public:
    constexpr ModIntBase() : x {0} {}
    
    template<typename T>
    constexpr ModIntBase(T x_) : x {norm(x_ % T {P})} {}
    
    constexpr static U norm(U x) {
        if ((x >> (8 * sizeof(U) - 1) & 1) == 1) {
            x += P;
        }
        if (x >= P) {
            x -= P;
        }
        return x;
    }
    
    constexpr U val() const {
        return x;
    }
    
    constexpr ModIntBase operator-() const {
        ModIntBase res;
        res.x = norm(P - x);
        return res;
    }
    
    constexpr ModIntBase inv() const {
        return power(*this, P - 2);
    }
    
    constexpr ModIntBase &operator*=(const ModIntBase &rhs) & {
        x = mulMod<P>(x, rhs.val());
        return *this;
    }
    
    constexpr ModIntBase &operator+=(const ModIntBase &rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    
    constexpr ModIntBase &operator-=(const ModIntBase &rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    
    constexpr ModIntBase &operator/=(const ModIntBase &rhs) & {
        return *this *= rhs.inv();
    }
    
    friend constexpr ModIntBase operator*(ModIntBase lhs, const ModIntBase &rhs) {
        lhs *= rhs;
        return lhs;
    }
    
    friend constexpr ModIntBase operator+(ModIntBase lhs, const ModIntBase &rhs) {
        lhs += rhs;
        return lhs;
    }
    
    friend constexpr ModIntBase operator-(ModIntBase lhs, const ModIntBase &rhs) {
        lhs -= rhs;
        return lhs;
    }
    
    friend constexpr ModIntBase operator/(ModIntBase lhs, const ModIntBase &rhs) {
        lhs /= rhs;
        return lhs;
    }

    friend constexpr std::ostream &operator<<(std::ostream &os, const ModIntBase &a) {
        return os << a.val();
    }
    
    friend constexpr bool operator==(ModIntBase lhs, ModIntBase rhs) {
        return lhs.val() == rhs.val();
    }
    
    friend constexpr bool operator!=(ModIntBase lhs, ModIntBase rhs) {
        return lhs.val() != rhs.val();
    }
    
    friend constexpr bool operator<(ModIntBase lhs, ModIntBase rhs) {
        return lhs.val() < rhs.val();
    }
    
private:
    U x;
};
 
template<u32 P>
using ModInt = ModIntBase<u32, P>;
 
template<u64 P>
using ModInt64 = ModIntBase<u64, P>;
 
constexpr u32 P = 998244353;
using Z = ModInt<P>;

void solve() {
    vector<int> a(10);
    rep(i,1,9) cin >> a[i];

    if (a[1] == 1) {
        if (accumulate(a.begin(), a.end(), 0) == 1) {
            cout << 1 << '\n';
            return;
        }
        Z ans = 1;
        rep(i,2,9) {
            ans *= power(Z(i), a[i]);
        }
        rep(i,2,9) {
            if (a[i]) {
                ans /= i;
                ans *= (i + 1);
                break;
            }
        }
        cout << ans << '\n';
        return;
    }

    Z ans = 1;
    rep(i,3,9) {
        ans *= power(Z(i), a[i]);
    }

    if (a[2] >= a[1]) {
        ans *= power(Z(2), a[2] - a[1]) * power(Z(3), a[1]);
    } else {
        ans *= power(Z(3), a[2]);
        a[1] -= a[2];
        i64 mx = 0;
        rep(i,0,a[1]/3) {
            mx = max(mx, power(3LL, i) * power(2LL, (a[1] - 3 * i) / 2));
        }
        ans *= mx;
    }

    cout << ans << '\n';   
}

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

    int T;
    cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3856kb

input:

7
5 3 0 0 0 0 0 0 0
4 1 1 1 0 0 0 0 0
1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 2
99 88 77 66 55 44 33 22 11
100 90 80 70 60 50 40 30 20

output:

54
108
1
10
90
90553232
143532368

result:

ok 7 lines

Test #2:

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

input:

1000
22 80 50 23 35 71 81 70 96
40 33 36 2 51 52 96 5 32
56 35 85 13 58 80 26 14 31
60 21 8 19 79 5 94 44 33
85 55 10 59 76 98 28 22 69
14 72 40 14 100 68 5 18 69
95 42 51 0 32 97 37 34 85
54 33 18 40 34 10 72 72 68
81 47 80 23 23 68 40 3 71
58 7 36 79 89 83 5 68 16
30 3 82 79 35 28 30 55 88
17 86 2...

output:

376701872
321820208
765709043
819408880
639261805
521201354
7172464
780360907
240853384
151457742
298466126
416189734
124742738
161566750
493291429
481038778
409158325
951979430
783007793
438976523
440485591
163247072
78098984
275527515
308024444
168349368
423889166
168234582
827159852
914298923
465...

result:

wrong answer 39th lines differ - expected: '183198908', found: '137399181'