QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#411017#8339. Rooted TreeErrormakerTL 1493ms6740kbC++173.1kb2024-05-14 20:11:552024-05-14 20:11:57

Judging History

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

  • [2024-05-14 20:11:57]
  • 评测
  • 测评结果:TL
  • 用时:1493ms
  • 内存:6740kb
  • [2024-05-14 20:11:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+9;
template <long long P>
struct ModInt
{
public:
	ModInt() : v(0) {}
	template <typename T>
	ModInt(T x) { v = ((long long)x % P + P) % P; }
	long long val() const { return v; }
	ModInt &operator++()
	{
		++v;
		if (v == P)
			v = 0;
		return *this;
	}
	ModInt &operator--()
	{
		if (v == 0)
			v = P;
		--v;
		return *this;
	}
	ModInt operator++(int)
	{
		ModInt oldVal = *this;
		++*this;
		return oldVal;
	}
	ModInt operator--(int)
	{
		ModInt oldVal = *this;
		--*this;
		return oldVal;
	}
	ModInt &operator+=(const ModInt &rhs)
	{
		v += rhs.v;
		v %= P;
		return *this;
	}
	ModInt &operator-=(const ModInt &rhs)
	{
		v -= rhs.v;
		v = (v + P) % P;
		return *this;
	}
	ModInt &operator*=(const ModInt &rhs)
	{
		v *= rhs.v;
		v %= P;
		return *this;
	}
	ModInt &operator/=(const ModInt &rhs) { return *this = *this * rhs.inv(); }
	ModInt operator+() const { return *this; }
	ModInt operator-() const { return ModInt() - *this; }
	ModInt pow(long long exp) const
	{
		// assert(exp>=0);
		ModInt res = 1;
		ModInt base = *this;
		while (exp)
		{
			if (exp & 1)
				res *= base;
			base *= base;
			exp >>= 1;
		}
		return res;
	}
	ModInt inv() const
	{
		// assert(v);
		return pow(P - 2);
	}
	friend ModInt operator+(const ModInt &lhs, const ModInt &rhs)
	{
		ModInt res = lhs;
		res += rhs;
		return res;
	}
	friend ModInt operator-(const ModInt &lhs, const ModInt &rhs)
	{
		ModInt res = lhs;
		res -= rhs;
		return res;
	}
	friend ModInt operator*(const ModInt &lhs, const ModInt &rhs)
	{
		ModInt res = lhs;
		res *= rhs;
		return res;
	}
	friend ModInt operator/(const ModInt &lhs, const ModInt &rhs)
	{
		ModInt res = lhs;
		res /= rhs;
		return res;
	}
	friend bool operator==(const ModInt &lhs, const ModInt &rhs) { return lhs.v == rhs.v; }
	friend bool operator!=(const ModInt &lhs, const ModInt &rhs) { return lhs.v != rhs.v; }
	friend std::istream &operator>>(std::istream &is, ModInt &aim)
	{
		long long tmp;
		is >> tmp;
		aim = ModInt(tmp);
		return is;
	}
	friend std::ostream &operator<<(std::ostream &os, const ModInt &aim) { return os << aim.val(); }

private:
	long long v;
};
using mint = ModInt<MOD>;
mint fact[200005];
mint infact[200005];
void init()
{
    infact[0] = fact[0] = 1;
    for(int i = 1;i<= 200002 ;i++)
        fact[i] = fact[i-1] * i , infact[i] = infact[i-1] / i;
}
mint C(int a,int b)
{
    if( a < b || a < 0 || b < 0 ) return 0;
    return fact[a] * infact[b] * infact[a-b];
}
void Solve()
{
    int n,k;cin >> k >> n;

    mint avg_dep = 0;
    mint yenum = 1;
    mint rem = 0;

    mint ans = 0;
    while(n--)
    {

        mint nxtnum = yenum + k-1;
        rem += avg_dep;
        avg_dep = (avg_dep * (yenum-1)/nxtnum + (k * (avg_dep + 1) / nxtnum));

        yenum += k-1;


//        ans += avg_dep * yenum;
//        cout<<avg_dep<<" "<<yenum<<"\n";
    }
//    cout<<ans<<"\n";
    cout<<avg_dep * yenum + rem;

}

int main()
{
    Solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

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

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 138ms
memory: 6644kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: 0
Accepted
time: 1493ms
memory: 6636kb

input:

48 6713156

output:

198541581

result:

ok 1 number(s): "198541581"

Test #5:

score: 0
Accepted
time: 1ms
memory: 6552kb

input:

1 111

output:

6216

result:

ok 1 number(s): "6216"

Test #6:

score: -100
Time Limit Exceeded

input:

28 7304152

output:


result: