CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Planeetat
Sender:hltk
Submission time:2020-09-27 15:50:55 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2, 3details
#2ACCEPTED0.02 s1, 2, 3details
#3ACCEPTED0.02 s1, 2, 3details
#40.02 s1, 2, 3details
#50.02 s1, 2, 3details
#60.02 s1, 2, 3details
#70.03 s1, 2, 3details
#80.02 s1, 2, 3details
#90.02 s1, 2, 3details
#100.02 s1, 2, 3details
#110.02 s2, 3details
#120.07 s2, 3details
#13--2, 3details
#14--3details
#15--3details
#16--3details
#17--3details
#18--3details
#19--3details
#20--3details
#21--3details
#22--3details
#23--3details
#24--3details
#25--3details

Code

#include <functional>
#include <iostream>
#include <vector>

using ll = long long;

template <typename T> T pow(T a, ll b) {
	T r = 1;
	for (; b; b /= 2, a *= a)
		if (b % 2) r *= a;
	return r;
}

// source: ecnerwala, own, benq
template <int MOD> struct modint {
	int v;
	modint() : v(0) {}
	modint(ll x) : v(x % MOD) {
		if (v < 0) v += MOD;
	}
	explicit operator int() const { return v; }
	explicit operator ll() const { return v; }

	friend std::ostream &operator<<(std::ostream &out, const modint &a) {
		return out << int(a);
	}
	friend std::istream &operator>>(std::istream &in, modint &a) {
		ll x;
		in >> x;
		a = modint(x);
		return in;
	}

	// only works if MOD is prime
	modint inv() const {
		return pow(*this, MOD - 2);
	}
	friend modint inv(const modint &x) { return x.inv(); }

	modint &operator+=(const modint &a) {
		v += a.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modint &operator-=(const modint &a) {
		v -= a.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modint &operator*=(const modint &a) {
		v = ll(v) * ll(a.v) % MOD;
		return *this;
	}
	modint &operator/=(const modint &a) { return *this *= a.inv(); }

	friend modint operator+(const modint &a, const modint &b) {
		return modint(a) += b;
	}
	friend modint operator-(const modint &a, const modint &b) {
		return modint(a) -= b;
	}
	friend modint operator*(const modint &a, const modint &b) {
		return modint(a) *= b;
	}
	friend modint operator/(const modint &a, const modint &b) {
		return modint(a) /= b;
	}
};

constexpr ll MOD = 998244353;
using mint = modint<MOD>;

namespace nCr {
	std::vector<mint> fact, ifact;
	void init(int N = int(1e6)) {
		fact.resize(N + 1);
		ifact.resize(N + 1);
		fact[0] = 1;
		for (int i = 1; i <= N; ++i)
			fact[i] = fact[i - 1] * i;
		ifact[N] = 1 / fact[N];
		for (int i = N; i > 0; --i)
			ifact[i - 1] = i * ifact[i];
	}

	mint choose(int a, int b) {
		if (a < b || b < 0) return 0;
		return fact[a] * ifact[b] * ifact[a - b];
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	nCr::init();
	int n;
	std::cin >> n;
	std::vector<mint> p(n + 1);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= i; ++j)
			p[i] += nCr::choose(i, j) * pow(mint(i-j), i-j) * pow(mint(j), j);
	for (int i = 1; i <= n; ++i)
		p[i] /= i;
	std::vector<mint> score(n);
	std::function<void(int, std::vector<int>&)> brute = [&](int sum, std::vector<int>& k) {
		if (sum == n) {
			int l = n;
			mint ways(1);
			for (auto& x : k)
				ways *= p[x];
			for (int i = 0, j = 0; i < int(k.size()); i = j) {
				while (j < int(k.size()) && k[i] == k[j])
					++j;
				ways *= nCr::choose(l, k[i] * (j - i));
				l -= k[i] * (j - i);
			}
			score[k.size() - 1] += ways;
			return;
		}
		for (int j = (k.empty() ? 1 : k.back()); j <= n - sum; ++j) {
			k.push_back(j);
			brute(sum + j, k);
			k.pop_back();
		}
	};
	std::vector<int> base;
	brute(0, base);
	for (auto& x : score)
		std::cout << x << '\n';
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1

correct output
1

user output
1

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
2

correct output
3
1

user output
3
1

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
3

correct output
17
9
1

user output
17
9
1

Test 4

Group: 1, 2, 3

Verdict:

input
4

correct output
142
95
18
1

user output
142
77
18
1

Test 5

Group: 1, 2, 3

Verdict:

input
5

correct output
1569
1220
305
30
1

user output
1569
1220
215
30
1

Test 6

Group: 1, 2, 3

Verdict:

input
6

correct output
21576
18694
5595
745
45
...

user output
21576
16093
5217
475
45
...

Test 7

Group: 1, 2, 3

Verdict:

input
7

correct output
355081
334369
113974
18515
1540
...

user output
355081
334369
85057
15869
910
...

Test 8

Group: 1, 2, 3

Verdict:

input
8

correct output
6805296
6852460
2581964
484729
49840
...

user output
6805296
6166884
2184560
317797
39256
...

Test 9

Group: 1, 2, 3

Verdict:

input
9

correct output
148869153
158479488
64727522
13591116
1632099
...

user output
148869153
158479488
53628119
9474696
952239
...

Test 10

Group: 1, 2, 3

Verdict:

input
10

correct output
660215659
85349908
783995053
409987640
55545735
...

user output
665482621
782896752
534078847
302732480
32035323
...

Test 11

Group: 2, 3

Verdict:

input
20

correct output
8033007
474885151
998010619
720259168
345757330
...

user output
460697506
793147852
687410479
3592777
290216859
...
Truncated

Test 12

Group: 2, 3

Verdict:

input
50

correct output
637699856
613177596
194234103
50828885
988168359
...

user output
613718872
235524219
831125122
132935096
622043637
...
Truncated

Test 13

Group: 2, 3

Verdict:

input
100

correct output
894456323
406549429
962038245
430640330
61348310
...

user output
(empty)

Test 14

Group: 3

Verdict:

input
666

correct output
189730587
968711879
553374698
53051125
139917248
...

user output
(empty)

Test 15

Group: 3

Verdict:

input
3333

correct output
79235821
455292218
627100211
591681254
695866885
...

user output
(empty)

Test 16

Group: 3

Verdict:

input
4991

correct output
482116496
245260697
151422537
180441123
318466624
...

user output
(empty)

Test 17

Group: 3

Verdict:

input
4992

correct output
141010647
787351178
684701591
872974815
631476284
...

user output
(empty)

Test 18

Group: 3

Verdict:

input
4993

correct output
504034249
588971460
281533415
928250892
416697844
...

user output
(empty)

Test 19

Group: 3

Verdict:

input
4994

correct output
266134603
90079109
544661648
812099750
17249410
...

user output
(empty)

Test 20

Group: 3

Verdict:

input
4995

correct output
833898560
663839791
109127071
321675160
86285359
...

user output
(empty)

Test 21

Group: 3

Verdict:

input
4996

correct output
721158645
167929822
115103278
491345159
114397872
...

user output
(empty)

Test 22

Group: 3

Verdict:

input
4997

correct output
691405606
436947443
82656395
514529009
783319673
...

user output
(empty)

Test 23

Group: 3

Verdict:

input
4998

correct output
829675470
688714502
189351950
956110193
20883331
...

user output
(empty)

Test 24

Group: 3

Verdict:

input
4999

correct output
343936737
47032567
190931571
827280581
160866637
...

user output
(empty)

Test 25

Group: 3

Verdict:

input
5000

correct output
364064601
633559852
352848841
666954216
428009512
...

user output
(empty)