QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124013#6678. Gem Island 2batrr#WA 1232ms476692kbC++173.2kb2023-07-14 03:50:182023-07-14 03:50:21

Judging History

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

  • [2024-04-23 17:43:38]
  • hack成功,自动添加数据
  • (/hack/600)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-14 03:50:21]
  • 评测
  • 测评结果:WA
  • 用时:1232ms
  • 内存:476692kb
  • [2023-07-14 03:50:18]
  • 提交

answer

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;

int sum(int a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0)
        a += mod;
    return a;
}

int mult(int a, int b) {
    return 1ll * a * b % mod;
}

int bp(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

//int inv(int x) {
//    return bp(x, mod - 2);
//}

const int maxN = 3e7 + 10;
int fact[maxN], invfact[maxN], inv[maxN];
int n, d, r;
int cnk(int n, int k) {
    if (n < k || k < 0) return 0;
    return mult(fact[n], mult(invfact[k], invfact[n - k]));
}
int prep[maxN];
int lp[maxN];
void solve() {
    cin >> n >> d >> r;
    fact[0] = invfact[0] = fact[1] = invfact[1]  = inv[1] = 1;
    for (int i = 2; i < maxN; i++) {
        fact[i] = mult(fact[i - 1], i);
        inv[i] = mult(inv[mod % i], sub(0, mod / i));
        invfact[i] = mult(invfact[i - 1], inv[i]);
    }
    int S = 0;
    for (int x = 0; x <= d; x++) {
        prep[x] = cnk(d + n - 1 - x, n - 1);
    }
    for (int i = 2; i <= d; i++) {
        if (lp[i] == 0) {
            for (int j = i; j <= d; j += i) {
                lp[j] = 1;
                prep[j / i] = sum(prep[j / i], prep[j]);
            }
        }
    }
    for (int B = 1; B <= n; B++) {
        int T = sub(mult(r, cnk(B - 1, r)), mult(B, cnk(B - 2, r - 1)));
        if ((B + r - 1) & 1) {
            T = sub(0, T);
        }
        /*int TTT = 0;
        for (int A = 0; A <= r - 1; A++) {
            int gg = cnk(B - 1, A);
            if ((B - A) & 1) gg = sub(0, gg);
            TTT = mult(A, gg);
        }
        TTT =
        T = TTT;*/
        T = mult(T, invfact[B]);
        T = mult(T, invfact[n - B]);
//        ll CC = 0;
//        for (int x = B; x <= d; x += B) {
//            CC += prep[x];
//            CC = sum(CC, cnk(d + n - 1 - x, n - 1));
//        }
        S = sum(S, mult(prep[B], T));
    }
    /*for (int A = 1; A <= n; A++) {
        for (int i = 1; i <= d && A * i <= d; i++) {
            for (int k = 0; k + A <= n; k++) {
                int coef = mult(cnk(d + n - 1 - (k + A) * i, n - 1), mult(invfact[A], mult(invfact[k], mult(invfact[n - A - k], min(A, r)))));
                coef = mult(coef, fact[n]);
                if (k & 1) coef = sub(0, coef);
                S = sum(S, coef);
            }
        }
    }*/
    //A >= i
    S = mult(S, fact[n]);
    S = mult(S, bp(cnk(d + n - 1, n - 1), mod - 2));
    S = sum(S, r);
    S = sum(S, d);
    cout << S << endl;

}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
//        cout << "Case #" << i << endl;
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 386ms
memory: 357248kb

input:

2 3 1

output:

499122180

result:

ok 1 number(s): "499122180"

Test #2:

score: 0
Accepted
time: 404ms
memory: 358732kb

input:

3 3 2

output:

698771052

result:

ok 1 number(s): "698771052"

Test #3:

score: 0
Accepted
time: 347ms
memory: 357024kb

input:

5 10 3

output:

176512750

result:

ok 1 number(s): "176512750"

Test #4:

score: 0
Accepted
time: 368ms
memory: 357604kb

input:

5 4 3

output:

71303175

result:

ok 1 number(s): "71303175"

Test #5:

score: 0
Accepted
time: 327ms
memory: 358328kb

input:

37 47 12

output:

962577218

result:

ok 1 number(s): "962577218"

Test #6:

score: 0
Accepted
time: 366ms
memory: 358772kb

input:

29 50 26

output:

175627840

result:

ok 1 number(s): "175627840"

Test #7:

score: 0
Accepted
time: 383ms
memory: 358288kb

input:

298 498 221

output:

765832019

result:

ok 1 number(s): "765832019"

Test #8:

score: 0
Accepted
time: 412ms
memory: 358284kb

input:

497 456 243

output:

414028615

result:

ok 1 number(s): "414028615"

Test #9:

score: 0
Accepted
time: 366ms
memory: 357772kb

input:

114514 1926 817

output:

691374994

result:

ok 1 number(s): "691374994"

Test #10:

score: 0
Accepted
time: 365ms
memory: 358520kb

input:

1919810 1554 1999

output:

3553

result:

ok 1 number(s): "3553"

Test #11:

score: 0
Accepted
time: 403ms
memory: 357500kb

input:

1926817 1514 1001

output:

685086550

result:

ok 1 number(s): "685086550"

Test #12:

score: 0
Accepted
time: 367ms
memory: 358048kb

input:

1432132 1425 1425

output:

2850

result:

ok 1 number(s): "2850"

Test #13:

score: 0
Accepted
time: 1232ms
memory: 476692kb

input:

14999999 15000000 14999999

output:

29999999

result:

ok 1 number(s): "29999999"

Test #14:

score: 0
Accepted
time: 357ms
memory: 359032kb

input:

98765 99654 85647

output:

815183913

result:

ok 1 number(s): "815183913"

Test #15:

score: 0
Accepted
time: 346ms
memory: 358552kb

input:

99999 100000 99998

output:

832290200

result:

ok 1 number(s): "832290200"

Test #16:

score: -100
Wrong Answer
time: 361ms
memory: 359384kb

input:

1541 99998 725

output:

104535801

result:

wrong answer 1st numbers differ - expected: '463021366', found: '104535801'