QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#124015#6678. Gem Island 2batrr#WA 1243ms474756kbC++173.2kb2023-07-14 03:52:042023-07-14 03:52:59

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:52:59]
  • 评测
  • 测评结果:WA
  • 用时:1243ms
  • 内存:474756kb
  • [2023-07-14 03:52:04]
  • 提交

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 <= d; 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();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 438ms
memory: 358460kb

input:

2 3 1

output:

499122180

result:

ok 1 number(s): "499122180"

Test #2:

score: 0
Accepted
time: 406ms
memory: 357760kb

input:

3 3 2

output:

698771052

result:

ok 1 number(s): "698771052"

Test #3:

score: 0
Accepted
time: 388ms
memory: 357268kb

input:

5 10 3

output:

176512750

result:

ok 1 number(s): "176512750"

Test #4:

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

input:

5 4 3

output:

71303175

result:

ok 1 number(s): "71303175"

Test #5:

score: 0
Accepted
time: 362ms
memory: 358460kb

input:

37 47 12

output:

962577218

result:

ok 1 number(s): "962577218"

Test #6:

score: 0
Accepted
time: 394ms
memory: 358696kb

input:

29 50 26

output:

175627840

result:

ok 1 number(s): "175627840"

Test #7:

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

input:

298 498 221

output:

765832019

result:

ok 1 number(s): "765832019"

Test #8:

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

input:

497 456 243

output:

414028615

result:

ok 1 number(s): "414028615"

Test #9:

score: 0
Accepted
time: 362ms
memory: 357384kb

input:

114514 1926 817

output:

691374994

result:

ok 1 number(s): "691374994"

Test #10:

score: 0
Accepted
time: 382ms
memory: 357320kb

input:

1919810 1554 1999

output:

3553

result:

ok 1 number(s): "3553"

Test #11:

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

input:

1926817 1514 1001

output:

685086550

result:

ok 1 number(s): "685086550"

Test #12:

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

input:

1432132 1425 1425

output:

2850

result:

ok 1 number(s): "2850"

Test #13:

score: 0
Accepted
time: 1243ms
memory: 474756kb

input:

14999999 15000000 14999999

output:

29999999

result:

ok 1 number(s): "29999999"

Test #14:

score: 0
Accepted
time: 340ms
memory: 358924kb

input:

98765 99654 85647

output:

815183913

result:

ok 1 number(s): "815183913"

Test #15:

score: 0
Accepted
time: 316ms
memory: 359080kb

input:

99999 100000 99998

output:

832290200

result:

ok 1 number(s): "832290200"

Test #16:

score: -100
Wrong Answer
time: 334ms
memory: 359896kb

input:

1541 99998 725

output:

104535801

result:

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