QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#96669#5586. Digits of UnityNicolas125841WA 4059ms120088kbC++142.3kb2023-04-15 00:38:332023-04-15 00:42:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-15 00:42:17]
  • 评测
  • 测评结果:WA
  • 用时:4059ms
  • 内存:120088kb
  • [2023-04-15 00:38:33]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll mod = 998244353;

vector<ll> fac(5000001, 0), ifac(5000001, 0), inv(5000001, 0);

ll perm(int n, int k){
    return fac[n] * ifac[n-k] % mod;
}

ll comb(int n, int k){
    return ((fac[n] * ifac[k]) % mod) * ifac[n-k] % mod;
}

int main(){
    cin.tie(NULL)->sync_with_stdio(false);

    fac[0] = fac[1] = 1;
    ifac[0] = ifac[1] = 1;
    inv[0] = inv[1] = 1;

    for(ll i = 2; i <= 5000000; i++){
        inv[i] = mod - (mod/i) * inv[mod%i] % mod;

        fac[i] = i * fac[i-1] % mod;        
        ifac[i] = inv[i] * ifac[i-1] % mod;
    }

    int n, k, m;
    cin >> n >> k >> m;

    int ml = 0;

    while((1<<ml) <= m)
        ml++;

    ll ans = 0;

    vector<ll> weights(20, 0);


    for(int i = k; i < 20; i++){
        ll weight = 0;

        for(int j = k; j < i; j++){
            weight += weights[j] * comb(i, j) % mod;
            weight %= mod;
        }

        weight = 1 - weight;
        weight %= mod;
        if(weight < 0)
            weight += mod;

        weights[i] = weight;
    }

    for(int i = 0; i <= m; i++){
        if(__builtin_popcount(i) >= k){
            vector<vector<ll>> dp(ml, vector<ll>(3, 0));

            dp[ml-1][2] = 1;

            if((i & (1<<(ml-1))) == 0)
                dp[ml-1][0] = 1;
            
            for(int j = ml-2; j >= 0; j--){
                if(m & (1<<j)){
                    dp[j][2] = dp[j+1][2];
                    dp[j][1] = dp[j+1][0] + dp[j+1][1];

                    if((i & (1<<j)) == 0){
                        dp[j][0] = dp[j+1][0] + dp[j+1][1] + dp[j+1][2];
                    }
                }else{
                    dp[j][1] = dp[j+1][0] + dp[j+1][1];

                    if((i & (1<<j)) == 0){
                        dp[j][2] = dp[j+1][2];
                        dp[j][0] = dp[j+1][0] + dp[j+1][1];
                    }
                }
            }

            int mx = dp[0][0] + dp[0][1] + dp[0][2];

            if(mx >= n){
                ans += weights[__builtin_popcount(i)] * perm(mx, n) % mod;
                ans %= mod;
                if(ans < 0)
                    ans += mod;
            }                         
        }
    }

    cout << ans << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 224ms
memory: 120016kb

input:

2 2 10

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 219ms
memory: 119960kb

input:

3 4 14

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 275ms
memory: 120080kb

input:

2 1 100000

output:

910073387

result:

ok single line: '910073387'

Test #4:

score: 0
Accepted
time: 283ms
memory: 119952kb

input:

30 6 136665

output:

552360422

result:

ok single line: '552360422'

Test #5:

score: 0
Accepted
time: 251ms
memory: 120048kb

input:

178 6 51500

output:

788418998

result:

ok single line: '788418998'

Test #6:

score: 0
Accepted
time: 261ms
memory: 119968kb

input:

445 4 91471

output:

322733059

result:

ok single line: '322733059'

Test #7:

score: 0
Accepted
time: 302ms
memory: 120012kb

input:

23634 10 299334

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 360ms
memory: 120080kb

input:

242554 5 287650

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 202ms
memory: 119980kb

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 197ms
memory: 120088kb

input:

1 3 7

output:

1

result:

ok single line: '1'

Test #11:

score: 0
Accepted
time: 225ms
memory: 119964kb

input:

1 1 7

output:

7

result:

ok single line: '7'

Test #12:

score: 0
Accepted
time: 238ms
memory: 120020kb

input:

500000 500000 5000000

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 4059ms
memory: 120008kb

input:

250000 1 5000000

output:

578914111

result:

ok single line: '578914111'

Test #14:

score: 0
Accepted
time: 445ms
memory: 119992kb

input:

4096 6 449389

output:

129538870

result:

ok single line: '129538870'

Test #15:

score: 0
Accepted
time: 220ms
memory: 119968kb

input:

50 2 50

output:

0

result:

ok single line: '0'

Test #16:

score: 0
Accepted
time: 226ms
memory: 119900kb

input:

250000 65 5000000

output:

0

result:

ok single line: '0'

Test #17:

score: -100
Wrong Answer
time: 3579ms
memory: 120044kb

input:

1 1 5000000

output:

5002335

result:

wrong answer 1st lines differ - expected: '5000000', found: '5002335'