Skip to content

Commit 5e8fbc8

Browse files
author
Khanh Vu
committed
add: eth icpc and arc178
1 parent d6792a6 commit 5e8fbc8

38 files changed

+2176
-8
lines changed

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 4
3+
ColumnLimit: 120
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"Local: main","url":"/Users/kvu/github/competitiveprogramming/main.cpp","tests":[{"id":1712947544040,"input":"0","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/Users/kvu/github/competitiveprogramming/main.cpp","group":"local","local":true}
1+
{"name":"Local: main","url":"/Users/kvu/github/competitiveprogramming/main.cpp","tests":[{"id":1716127682860,"input":"5 2\n2 4","output":"1 3 2 5 4"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/Users/kvu/github/competitiveprogramming/main.cpp","group":"local","local":true}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
.DS_Store
1+
**/.DS_Store
2+
**/.cph
23
main

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"files.associations": {
3+
"vector": "cpp"
4+
}
5+
}

atcoder/arc178/b.bin

37.5 KB
Binary file not shown.

atcoder/arc178/b.cpp

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#include <bits/stdc++.h>
2+
3+
#include <ranges>
4+
using namespace std;
5+
6+
#ifdef LOCAL
7+
#include "../../debug.h"
8+
#else
9+
#define debug(...) 42
10+
#endif
11+
12+
namespace utils {
13+
template <typename T, typename... Args>
14+
void setValues(const T& value, T& first, Args&... args) {
15+
first = value;
16+
if constexpr (sizeof...(args) > 0) {
17+
setValues(value, args...);
18+
}
19+
}
20+
21+
template <typename T>
22+
void setMax(T& target, const T& value) {
23+
if (value > target) {
24+
target = value;
25+
}
26+
}
27+
28+
template <typename T>
29+
void setMin(T& target, const T& value) {
30+
if (value < target) {
31+
target = value;
32+
}
33+
}
34+
} // namespace utils
35+
using namespace utils;
36+
37+
using ll = long long;
38+
using ld = long double;
39+
const char el = '\n';
40+
const bool is_multitest = true;
41+
42+
template <int MOD_> struct modnum {
43+
static constexpr int MOD = MOD_;
44+
static_assert(MOD_ > 0, "MOD must be positive");
45+
46+
private:
47+
using ll = int64_t;
48+
49+
int v;
50+
51+
static int minv(int a, int m) {
52+
a %= m;
53+
assert(a);
54+
return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
55+
}
56+
57+
public:
58+
59+
modnum() : v(0) {}
60+
modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
61+
explicit operator int() const { return v; }
62+
friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
63+
friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
64+
65+
friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
66+
friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
67+
68+
modnum inv() const {
69+
modnum res;
70+
res.v = minv(v, MOD);
71+
return res;
72+
}
73+
friend modnum inv(const modnum& m) { return m.inv(); }
74+
modnum neg() const {
75+
modnum res;
76+
res.v = v ? MOD-v : 0;
77+
return res;
78+
}
79+
friend modnum neg(const modnum& m) { return m.neg(); }
80+
81+
modnum operator- () const {
82+
return neg();
83+
}
84+
modnum operator+ () const {
85+
return modnum(*this);
86+
}
87+
88+
modnum& operator ++ () {
89+
v ++;
90+
if (v == MOD) v = 0;
91+
return *this;
92+
}
93+
modnum& operator -- () {
94+
if (v == 0) v = MOD;
95+
v --;
96+
return *this;
97+
}
98+
modnum& operator += (const modnum& o) {
99+
v += o.v;
100+
if (v >= MOD) v -= MOD;
101+
return *this;
102+
}
103+
modnum& operator -= (const modnum& o) {
104+
v -= o.v;
105+
if (v < 0) v += MOD;
106+
return *this;
107+
}
108+
modnum& operator *= (const modnum& o) {
109+
v = int(ll(v) * ll(o.v) % MOD);
110+
return *this;
111+
}
112+
modnum& operator /= (const modnum& o) {
113+
return *this *= o.inv();
114+
}
115+
116+
friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
117+
friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
118+
friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
119+
friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
120+
friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
121+
friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
122+
};
123+
124+
template <typename T> T pow(T a, long long b) {
125+
assert(b >= 0);
126+
T r = 1; while (b) { if (b & 1) r *= a; b >>= 1; a *= a; } return r;
127+
}
128+
129+
using num = modnum<998244353>;
130+
131+
132+
void solve() {
133+
ll a1, a2, a3;
134+
cin >> a1 >> a2 >> a3;
135+
if (a1 > a2) swap(a1, a2);
136+
if (a3 < a2 || a3 > a2 + 1) {
137+
cout << 0 << el;
138+
return;
139+
}
140+
141+
// Assume that a2 == a3
142+
num res;
143+
if (a1 == a2) {
144+
num x = pow(num(10), a1) - num(2) * pow(num(10), a1 - 1) + num(1);
145+
res = x * (x - num(1)) / num(2);
146+
}
147+
else if (a1 < a2) {
148+
num x = pow(num(10), a2) - num(1) - pow(num(10), a1 - 1) - pow(num(10), a2 - 1) + num(1);
149+
num y = pow(num(10), a2) - pow(num(10), a1) - pow(num(10), a2 - 1) + num(1);
150+
res = (x + y) * (x - y + num(1)) / num(2);
151+
}
152+
153+
// if a2 < a3, we take the complement
154+
if (a2 < a3) {
155+
res = num(81) * pow(num(10), a1 + a2 - 2) - res;
156+
}
157+
158+
cout << res << el;
159+
}
160+
161+
int main() {
162+
ios_base::sync_with_stdio(false);
163+
cin.tie(0);
164+
int t = 1;
165+
if (is_multitest) cin >> t;
166+
while (t--) solve();
167+
return 0;
168+
}

atcoder/arc178/b_sol.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
MOD = 998244353
2+
3+
# return 10 ^ a
4+
def powten(a):
5+
return pow(10, a, MOD)
6+
7+
def solve(a1, a2, a3):
8+
# a1 <= a2
9+
if a1 > a2:
10+
a1, a2 = a2, a1
11+
# impossible
12+
if a2 != a3 and a2 + 1 != a3:
13+
return 0
14+
# a2 == a3
15+
if a2 != a3:
16+
return (81 * powten(a1 + a2 - 2) - solve(a1, a2, a2)) % MOD
17+
# calc
18+
if a1 == a2:
19+
return 4 * powten(a1 - 1) * (8 * powten(a1 - 1) + 1) % MOD
20+
else:
21+
ans = (9 * powten(a2 - 1) - (11 * powten(a1 - 1) - 1) * pow(2, -1, MOD)) % MOD
22+
ans = ans * 9 * powten(a1 - 1) % MOD
23+
return ans
24+
25+
26+
# I/O
27+
T = int(input())
28+
for _ in range(T):
29+
a1, a2, a3 = map(int, input().split())
30+
print(solve(a1, a2, a3))

eth-cp-spring24/debug.h

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
template <typename A, typename B>
2+
string to_string(pair<A, B> p);
3+
4+
template <typename A, typename B, typename C>
5+
string to_string(tuple<A, B, C> p);
6+
7+
template <typename A, typename B, typename C, typename D>
8+
string to_string(tuple<A, B, C, D> p);
9+
10+
string to_string(const string& s) {
11+
return '"' + s + '"';
12+
}
13+
14+
string to_string(const char* s) {
15+
return to_string((string) s);
16+
}
17+
18+
string to_string(bool b) {
19+
return (b ? "true" : "false");
20+
}
21+
22+
string to_string(vector<bool> v) {
23+
bool first = true;
24+
string res = "{";
25+
for (int i = 0; i < static_cast<int>(v.size()); i++) {
26+
if (!first) {
27+
res += ", ";
28+
}
29+
first = false;
30+
res += to_string(v[i]);
31+
}
32+
res += "}";
33+
return res;
34+
}
35+
36+
template <size_t N>
37+
string to_string(bitset<N> v) {
38+
string res = "";
39+
for (size_t i = 0; i < N; i++) {
40+
res += static_cast<char>('0' + v[i]);
41+
}
42+
return res;
43+
}
44+
45+
template <typename A>
46+
string to_string(A v) {
47+
bool first = true;
48+
string res = "{";
49+
for (const auto &x : v) {
50+
if (!first) {
51+
res += ", ";
52+
}
53+
first = false;
54+
res += to_string(x);
55+
}
56+
res += "}";
57+
return res;
58+
}
59+
60+
template <typename A, typename B>
61+
string to_string(pair<A, B> p) {
62+
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
63+
}
64+
65+
template <typename A, typename B, typename C>
66+
string to_string(tuple<A, B, C> p) {
67+
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
68+
}
69+
70+
template <typename A, typename B, typename C, typename D>
71+
string to_string(tuple<A, B, C, D> p) {
72+
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
73+
}
74+
75+
void debug_out() { cerr << endl; }
76+
77+
template <typename Head, typename... Tail>
78+
void debug_out(Head H, Tail... T) {
79+
cerr << " " << to_string(H);
80+
debug_out(T...);
81+
}
82+
83+
#ifdef LOCAL
84+
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
85+
#else
86+
#define debug(...) 42
87+
#endif

eth-cp-spring24/official/a.bin

39.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)