Skip to content

Commit 00bd9bc

Browse files
committed
abc 358 E + template update
1 parent 142ea1d commit 00bd9bc

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

atcoder-p/E-Alphabet_Tiles.cpp

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @file E-Alphabet_Tiles.cpp
3+
* @author Naowal Rahman
4+
* @date 2024-06-23 14:54
5+
*/
6+
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
#pragma GCC optimize("Ofast,unroll-loops")
11+
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
12+
13+
#ifndef ONLINE_JUDGE
14+
#include "/home/naowal/Desktop/code/competitive-programming/debug.h"
15+
#else
16+
#define dbg(x)
17+
#define timer()
18+
#endif
19+
20+
#define int long long
21+
template<class T> using V = vector<T>;
22+
using vi = V<int>;
23+
using pii = pair<int, int>;
24+
#define first f
25+
#define second s
26+
#define sz(x) (int)((x).size())
27+
#define all(x) begin(x), end(x)
28+
#define rall(x) rbegin(x), rend(x)
29+
30+
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
31+
#define F0R(i,a) FOR(i,0,a)
32+
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
33+
#define R0F(i,a) ROF(i,0,a)
34+
35+
signed main() {
36+
cin.tie(0)->sync_with_stdio(0);
37+
38+
constexpr int mod = 998244353;
39+
40+
// precompute binomial coefficients with Pascal's triangle
41+
V<vi> C(1001, vi(1001));
42+
F0R(n, 1001) C[n][0] = 1, C[n][n] = 1;
43+
FOR(n, 1, 1001) FOR(k, 1, 1001) C[n][k] = (C[n-1][k-1] + C[n-1][k]) % mod;
44+
45+
int K; cin >> K;
46+
vi f(26);
47+
F0R(i, 26) cin >> f[i];
48+
49+
V<vi> dp(27, vi(K+1));
50+
dp[0][0] = 1;
51+
F0R(i, 26) F0R(j, K+1) F0R(k, min(j, f[i])+1) {
52+
dp[i+1][j] += dp[i][j-k] * C[j][k] % mod;
53+
dp[i+1][j] %= mod;
54+
}
55+
56+
int ans = 0;
57+
FOR(j, 1, K+1) ans += dp[26][j], ans %= mod;
58+
cout << ans;
59+
60+
timer();
61+
return 0;
62+
}
63+
64+
/* stuff you should look for
65+
-------------------------
66+
* int overflow, array bounds
67+
* special cases (n=1?)
68+
* do smth instead of nothing and stay organized
69+
* WRITE STUFF DOWN
70+
* DON'T GET STUCK ON ONE APPROACH
71+
*/

debug.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
template<typename T>
22
int SIZE(T (&t)){
3-
return t.size();
3+
return (int)t.size();
44
}
55

66
template<typename T, size_t N>
@@ -88,6 +88,13 @@ void dbgr(Heads H, Tails... T){
8888
dbgr(T...);
8989
}
9090

91+
const auto _start_time = chrono::high_resolution_clock::now();
92+
void timer() {
93+
auto _end_time = chrono::high_resolution_clock::now();
94+
chrono::duration<double, milli> diff = _end_time - _start_time;
95+
cerr << "\nTime Taken: " << diff.count() << " ms\n";
96+
}
97+
9198
#define COLOR "\033[91m"
9299
#define DEFAULT "\033[39m"
93100
#define NUMARGS(...) tuple_size<decltype(make_tuple(__VA_ARGS__))>::value

template.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ using namespace std;
1414
#include "/home/naowal/Desktop/code/competitive-programming/debug.h"
1515
#else
1616
#define dbg(x)
17+
#define timer()
1718
#endif
1819

1920
#define int long long
@@ -31,12 +32,6 @@ using pii = pair<int, int>;
3132
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
3233
#define R0F(i,a) ROF(i,0,a)
3334

34-
const auto _start_time = chrono::high_resolution_clock::now();
35-
void timer() {
36-
auto _end_time = chrono::high_resolution_clock::now();
37-
chrono::duration<double, milli> diff = _end_time - _start_time;
38-
cerr << "Time Taken: " << diff.count() << " ms\n";
39-
}
4035

4136
signed main() {
4237
cin.tie(0)->sync_with_stdio(0);

0 commit comments

Comments
 (0)