Skip to content

Commit 4927b07

Browse files
committed
atcoder/abc185C
1 parent 39f47ae commit 4927b07

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

atcoder/abc185/C/main.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
3+
template<uint64_t MOD = std::numeric_limits<uint64_t>::max()>
4+
class CombinationPascal {
5+
size_t N;
6+
std::vector<std::vector<uint64_t>> comb;
7+
8+
public:
9+
// Time: O(N^2)
10+
CombinationPascal(
11+
size_t const N = 1000
12+
)
13+
{
14+
build(N);
15+
}
16+
// Time: O(N^2)
17+
void build(size_t const N) {
18+
this->N = N;
19+
comb.assign(N + 1, std::vector<uint64_t>(N + 1, 0));
20+
comb[0][0] = 1;
21+
for (size_t n = 1; n <= N; ++n) {
22+
comb[n][0] = 1;
23+
for (size_t k = 1; k <= N; ++k) {
24+
comb[n][k] = (comb[n-1][k-1] + comb[n-1][k]) % MOD;
25+
}
26+
}
27+
}
28+
// nCk
29+
// n = [0,N], k = [0,n]
30+
// Time: O(1)
31+
uint64_t C(size_t const n, size_t const k) const {
32+
if (k > n) throw std::out_of_range("k");
33+
if (n > N) throw std::out_of_range("n");
34+
return comb[n][k];
35+
}
36+
// nHk
37+
// H(n,k) = C(n+k-1,k)
38+
// n = [0,N-k+1], k = [0,N]
39+
// Time: O(1)
40+
uint64_t H(size_t const n, size_t const k) const {
41+
if (n == 0 && k == 0) return 1;
42+
return C(n+k-1,k);
43+
}
44+
// Time: O(1)
45+
size_t size() const {
46+
return N;
47+
}
48+
};
49+
50+
using namespace std;
51+
using ll = int64_t;
52+
using ff = long double;
53+
54+
int main() {
55+
ios_base::sync_with_stdio(false);
56+
cin.tie(0); cout.tie(0);
57+
58+
int L;
59+
cin >> L;
60+
61+
CombinationPascal<> solver(300);
62+
ll ans = solver.H(12, L-12);
63+
cout << ans << endl;
64+
65+
return 0;
66+
}

0 commit comments

Comments
 (0)