QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124004#6678. Gem Island 2batrr#AC ✓1352ms416984kbC++172.9kb2023-07-14 03:27:292023-07-14 03:27:32

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:27:32]
  • 评测
  • 测评结果:AC
  • 用时:1352ms
  • 内存:416984kb
  • [2023-07-14 03:27:29]
  • 提交

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];
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 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(CC % mod, 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();
    }
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 356ms
memory: 356860kb

input:

2 3 1

output:

499122180

result:

ok 1 number(s): "499122180"

Test #2:

score: 0
Accepted
time: 353ms
memory: 355672kb

input:

3 3 2

output:

698771052

result:

ok 1 number(s): "698771052"

Test #3:

score: 0
Accepted
time: 356ms
memory: 356932kb

input:

5 10 3

output:

176512750

result:

ok 1 number(s): "176512750"

Test #4:

score: 0
Accepted
time: 363ms
memory: 356832kb

input:

5 4 3

output:

71303175

result:

ok 1 number(s): "71303175"

Test #5:

score: 0
Accepted
time: 372ms
memory: 355312kb

input:

37 47 12

output:

962577218

result:

ok 1 number(s): "962577218"

Test #6:

score: 0
Accepted
time: 322ms
memory: 356584kb

input:

29 50 26

output:

175627840

result:

ok 1 number(s): "175627840"

Test #7:

score: 0
Accepted
time: 399ms
memory: 355484kb

input:

298 498 221

output:

765832019

result:

ok 1 number(s): "765832019"

Test #8:

score: 0
Accepted
time: 376ms
memory: 356508kb

input:

497 456 243

output:

414028615

result:

ok 1 number(s): "414028615"

Test #9:

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

input:

114514 1926 817

output:

691374994

result:

ok 1 number(s): "691374994"

Test #10:

score: 0
Accepted
time: 378ms
memory: 356284kb

input:

1919810 1554 1999

output:

3553

result:

ok 1 number(s): "3553"

Test #11:

score: 0
Accepted
time: 390ms
memory: 355636kb

input:

1926817 1514 1001

output:

685086550

result:

ok 1 number(s): "685086550"

Test #12:

score: 0
Accepted
time: 358ms
memory: 356116kb

input:

1432132 1425 1425

output:

2850

result:

ok 1 number(s): "2850"

Test #13:

score: 0
Accepted
time: 1309ms
memory: 416784kb

input:

14999999 15000000 14999999

output:

29999999

result:

ok 1 number(s): "29999999"

Test #14:

score: 0
Accepted
time: 448ms
memory: 357392kb

input:

98765 99654 85647

output:

815183913

result:

ok 1 number(s): "815183913"

Test #15:

score: 0
Accepted
time: 384ms
memory: 357000kb

input:

99999 100000 99998

output:

832290200

result:

ok 1 number(s): "832290200"

Test #16:

score: 0
Accepted
time: 421ms
memory: 357228kb

input:

1541 99998 725

output:

463021366

result:

ok 1 number(s): "463021366"

Test #17:

score: 0
Accepted
time: 418ms
memory: 361556kb

input:

985438 998756 101254

output:

671487608

result:

ok 1 number(s): "671487608"

Test #18:

score: 0
Accepted
time: 441ms
memory: 361548kb

input:

998654 999856 2

output:

92085960

result:

ok 1 number(s): "92085960"

Test #19:

score: 0
Accepted
time: 450ms
memory: 361536kb

input:

45876 1000000 13

output:

208089291

result:

ok 1 number(s): "208089291"

Test #20:

score: 0
Accepted
time: 1351ms
memory: 416984kb

input:

15000000 14999999 514

output:

143843956

result:

ok 1 number(s): "143843956"

Test #21:

score: 0
Accepted
time: 1352ms
memory: 414796kb

input:

14985345 14999998 145124

output:

785676527

result:

ok 1 number(s): "785676527"

Test #22:

score: 0
Accepted
time: 1224ms
memory: 414836kb

input:

14855345 14993298 1451424

output:

779861797

result:

ok 1 number(s): "779861797"

Test #23:

score: 0
Accepted
time: 370ms
memory: 355688kb

input:

1 1 1

output:

2

result:

ok 1 number(s): "2"

Test #24:

score: 0
Accepted
time: 1151ms
memory: 414744kb

input:

15000000 15000000 15000000

output:

30000000

result:

ok 1 number(s): "30000000"