QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638799#8339. Rooted TreeainuoWA 71ms16932kbC++14757b2024-10-13 16:57:322024-10-13 16:57:34

Judging History

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

  • [2024-10-13 16:57:34]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:16932kb
  • [2024-10-13 16:57:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e7+10;
const int mod=1e9+9;
ll num[N],dp[N];

ll qpow(ll n,ll m)
{
	ll ans=1;
	while(m)
    {
		if(m&1) ans=ans*n%mod;
		m>>=1;
		n=n*n%mod;
	}
	return ans;
}

ll getInv(ll a)
{
	return qpow(a,mod-2);
}

int main()
{
    int m,k;
    ll ans=0;
    cin>>m>>k;
    num[0]=1;
    for(int i=1;i<=k;i++) num[i]=num[i-1]+m-1;

    dp[0]=0;
    for(int i=1;i<=k;i++)
    {
        dp[i]=((((dp[i-1]*num[i-1])%mod+((dp[i-1]+1)*m)%mod-dp[i-1])%mod)*getInv(num[i]))%mod;
        ans=(ans+dp[i-1])%mod;
    }
    // cout<<num[1]<<'\n';
    // cout<<(dp[1]*num[1])%mod<<'\n';
    ans=(ans+((dp[k]*num[k])%mod))%mod;
    cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: -100
Wrong Answer
time: 71ms
memory: 16932kb

input:

83 613210

output:

-575799983

result:

wrong answer 1st numbers differ - expected: '424200026', found: '-575799983'