QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#506842#9105. Zayin and CampWorldFinalEscapedML 0ms0kbC++201.4kb2024-08-05 23:13:032024-08-05 23:13:03

Judging History

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

  • [2024-08-05 23:13:03]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-08-05 23:13:03]
  • 提交

answer

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

const int N = 30000005;
const int P = 998244353;

#define LL long long
// https://www.cnblogs.com/kyeecccccc/p/16926104.html
struct Mod
{
    LL m, p;
    void init(int pp) { m = ((__int128)1 << 64) / pp; p = pp; }
    LL operator ()(LL x)
    {
        return x - ((__int128(x) * m) >> 64) * p;
    }
} mod;

int fac[N], ifac[N], inv[N];
inline int qpow(int a, int b = P - 2) {
    int res = 1;
    while (b) {
        if (b & 1) res = mod(1ll * res * a);
        a = mod(1ll * a * a);
        b >>= 1;
    }
    return res;
}
inline void init(int n) {
    fac[0] = 1;
    for (int i = 1; i <= n; i++) fac[i] = mod(1ll * fac[i - 1] * i);
    ifac[n] = qpow(fac[n]);
    for (int i = n - 1; i >= 0; i--) ifac[i] = mod(1ll * ifac[i + 1] * (i + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = mod(1ll * (P - P / i) * inv[P % i]);
}
inline int binom(int n, int m) {
    return mod(1ll * mod(1ll * fac[n] * ifac[m]) * ifac[n - m]);
}

int main() {
    mod.init(998244353);
    init(3e7);
    int T; scanf("%d", &T);
    while (T--) {
        int n, m, r, s;
        scanf("%d%d%d%d", &n, &m, &r, &s);
        int ans = binom(n * m + s + r + n, n);
        ans = mod(1ll * (r + s) * mod(1ll * ans * inv[n * m + s + r + n]));
        printf("%d\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

11
1 10000000 5000000 5000000
10000000 1 5000000 4999999
1 1 1 1
2 3 4 5
6 7 8 9
10 11 12 13
1 2 1 1
2 1 1 1
1 1 2 1
1 1 1 2
65536 128 262144 262144

output:

10000000
918302048
2
72
21602784
953026004
2
5
3
3
592004372

result: