QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666413#8339. Rooted Tree1234576WA 1ms7628kbC++201.8kb2024-10-22 18:19:102024-10-22 18:19:21

Judging History

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

  • [2024-10-22 18:19:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7628kb
  • [2024-10-22 18:19:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll        long long
#define ull       unsigned long long
#define fir       first
#define sec       second
#define pii       pair<int, int>
#define pll       pair<long long, long long>
#define lowbit(a) (a & (-a))
#define SZ(a)     ((int)a.size())
#define all(a)    a.begin(), a.end()

constexpr int N = 2e7 + 50;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9 + 9;
constexpr int dir[4][2] = {
    {-1,  0},
    { 0,  1},
    { 1,  0},
    { 0, -1},
};

mt19937_64 rnd(random_device{}());
uniform_int_distribution<ull> dist(0, ULLONG_MAX); // use dist(rnd)
const int M = 4e7 + 10; 

#define int long long


ll qpow(ll a, ll b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1) res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

ll f[N], g[N];
ll inv[N];
void solve() {
	
	int m = 1, k = 10000000; 
	cin >> m >> k;
	g[0] = 1;
	for(int i = 1; i <= k; ++i) 
	{
		g[i] = g[i - 1] + m - 1;
		g[i] = 1ll * g[i] * g[i - 1];
	}
	g[k] = qpow(g[k], mod - 2);
	for(int i = k; i >= 1; --i)
	{
		g[i - 1] = 1ll * g[i - 1] * g[i] % mod;
	}
	int pv = qpow(m - 1, mod - 2);
	for(int i = 1; i <= k; ++i)
	{
		g[i] = inv[i]  * pv % mod;
	}
	ll Ans = 0;	
	f[0] = 0;
	ll pre = 1;
	for(int i = 1; i <= k; ++i)	
	{
		
		f[i] = ((1ll * (m - 1) * f[i - 1] % mod) * g[i - 1] % mod + f[i - 1] + m) % mod; 
//		pre = qpow(g[i], mod - 2);
		if(i < k) Ans = (Ans + f[i] * g[i]) % mod;
	}
	Ans += f[k];
	Ans %= mod;
	cout << Ans << '\n';
}
/*
4 1 3 1
1 2 3 100
9 1 9 1
2 4 5
*/

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _ = 1;
//    cin >> _;
    while (_--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7628kb

input:

6 2

output:

12

result:

wrong answer 1st numbers differ - expected: '18', found: '12'