QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#348939#8339. Rooted Treeucup-team1516#AC ✓1114ms42724kbC++201.4kb2024-03-09 22:24:342024-03-09 22:24:36

Judging History

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

  • [2024-03-09 22:24:36]
  • 评测
  • 测评结果:AC
  • 用时:1114ms
  • 内存:42724kb
  • [2024-03-09 22:24:34]
  • 提交

answer

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

constexpr int mod = 1000000009;

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

int dp[10010010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int M,K;
    cin >> M >> K;
    int ans = 0;
    for(int i = K; i >= 1; i--) {
        if(i == K) {
            mpl(ans,M);
            continue;
        }
        int res = 1+(M-1)*i;
        int inv = modpow(res,mod-2);
        mpl(dp[i],1ll*dp[i+1]*(mod+1-inv)%mod);
        mpl(dp[i],(1ll*dp[i+1]*M%mod+M)*inv%mod);
        mpl(ans,1ll*(dp[i]+1)*M%mod);
    }
    cout << ans << "\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 62ms
memory: 5976kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 738ms
memory: 29756kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: 0
Accepted
time: 814ms
memory: 32084kb

input:

28 7304152

output:

457266679

result:

ok 1 number(s): "457266679"

Test #7:

score: 0
Accepted
time: 449ms
memory: 19696kb

input:

38 4101162

output:

232117382

result:

ok 1 number(s): "232117382"

Test #8:

score: 0
Accepted
time: 1104ms
memory: 42364kb

input:

51 9921154

output:

340670552

result:

ok 1 number(s): "340670552"

Test #9:

score: 0
Accepted
time: 203ms
memory: 10712kb

input:

79 1801157

output:

620550406

result:

ok 1 number(s): "620550406"

Test #10:

score: 0
Accepted
time: 597ms
memory: 24772kb

input:

22 5417157

output:

457449071

result:

ok 1 number(s): "457449071"

Test #11:

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

input:

25 3210162

output:

36368303

result:

ok 1 number(s): "36368303"

Test #12:

score: 0
Accepted
time: 324ms
memory: 15076kb

input:

67 2919160

output:

935195555

result:

ok 1 number(s): "935195555"

Test #13:

score: 0
Accepted
time: 955ms
memory: 37200kb

input:

77 8613163

output:

482832472

result:

ok 1 number(s): "482832472"

Test #14:

score: 0
Accepted
time: 1099ms
memory: 42660kb

input:

90 10000000

output:

275581651

result:

ok 1 number(s): "275581651"

Test #15:

score: 0
Accepted
time: 1114ms
memory: 42676kb

input:

99 9999999

output:

126087169

result:

ok 1 number(s): "126087169"

Test #16:

score: 0
Accepted
time: 1112ms
memory: 42724kb

input:

100 10000000

output:

451590067

result:

ok 1 number(s): "451590067"

Extra Test:

score: 0
Extra Test Passed