From 2bf9ab74030148f6f4a6889f672625e0f3d64510 Mon Sep 17 00:00:00 2001 From: Macesuted Date: Sun, 11 Aug 2024 23:06:09 +0800 Subject: [PATCH] AtCoder: AtCoder Regular Contest 182 --- AtCoder/arc182_a.cpp | 61 ++++++++++++++++++++++++ AtCoder/arc182_b.cpp | 55 ++++++++++++++++++++++ AtCoder/arc182_c.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++ AtCoder/arc182_d.cpp | 53 +++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 AtCoder/arc182_a.cpp create mode 100644 AtCoder/arc182_b.cpp create mode 100644 AtCoder/arc182_c.cpp create mode 100644 AtCoder/arc182_d.cpp diff --git a/AtCoder/arc182_a.cpp b/AtCoder/arc182_a.cpp new file mode 100644 index 0000000..574be35 --- /dev/null +++ b/AtCoder/arc182_a.cpp @@ -0,0 +1,61 @@ +/** + * @file arc182_a.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-08-11 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 5005 +#define mod 998244353 + +typedef pair pii; + +pii a[maxn]; + +void solve(void) { + int n, m; + cin >> n >> m; + for (int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second; + int64_t ans = 1; + for (int i = 1; i <= m; i++) { + int cntl = 0, cntr = 0; + for (int j = 1; j <= m; j++) + if ((j < i && a[j].second > a[i].second) || (j > i && a[j].second < a[i].second)) { + if (a[j].first <= a[i].first) cntl++; + if (a[j].first >= a[i].first) cntr++; + } + if (cntl && cntr) return cout << 0 << endl, void(); + if (!cntl && !cntr) ans = ans * 2 % mod; + } + cout << ans << endl; + return; +} + +bool mem2; + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr); +#ifdef LOCAL + cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; +#endif + + int _ = 1; + // cin >> _; + while (_--) solve(); + +#ifdef LOCAL + cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; +#endif + return 0; +} \ No newline at end of file diff --git a/AtCoder/arc182_b.cpp b/AtCoder/arc182_b.cpp new file mode 100644 index 0000000..aee357a --- /dev/null +++ b/AtCoder/arc182_b.cpp @@ -0,0 +1,55 @@ +/** + * @file arc182_b.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-08-11 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 100005 + +void solve(void) { + int n, k; + cin >> n >> k; + vector ans; + ans.push_back(1); + for (int d = 1; d < k; d++) { + for (auto &i : ans) i <<= 1; + int cnt = ans.size(); + for (int i = 0; i < cnt; i++) + if ((int)ans.size() < n) ans.push_back(ans[i] + 1); + } + while ((int)ans.size() < n) ans.push_back(1); + sort(ans.begin(), ans.end()); + for (auto i : ans) cout << i << ' '; + cout << endl; + return; +} + +bool mem2; + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr); +#ifdef LOCAL + cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; +#endif + + int _ = 1; + cin >> _; + while (_--) solve(); + +#ifdef LOCAL + cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; +#endif + return 0; +} \ No newline at end of file diff --git a/AtCoder/arc182_c.cpp b/AtCoder/arc182_c.cpp new file mode 100644 index 0000000..e6b9553 --- /dev/null +++ b/AtCoder/arc182_c.cpp @@ -0,0 +1,110 @@ +/** + * @file arc182_c.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-08-11 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define mod 998244353 + +const int prime[6] = {2, 3, 5, 7, 11, 13}; + +class Matrix { + private: + vector> a; + int n, m; + + public: + void resize(int _n, int _m) { return a.resize(n = _n, vector(m = _m, 0)); } + + vector& operator[](size_t x) { return a[x]; } + int64_t get(int x, int y) const { return a[x][y]; } + + Matrix operator+(const Matrix& o) const { + Matrix ans = *this; + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) ans[i][j] = (ans[i][j] + o.get(i, j)) % mod; + return ans; + } + Matrix operator*(const Matrix& o) const { + Matrix ans; + ans.resize(n, o.m); + for (int i = 0; i < n; i++) + for (int j = 0; j < m; j++) + for (int k = 0; k < o.m; k++) ans[i][k] = (ans[i][k] + this->get(i, j) * o.get(j, k)) % mod; + return ans; + } + Matrix operator^(int64_t x) const { + Matrix a = *this, ans; + ans.resize(n, n); + for (int i = 0; i < n; i++) ans[i][i] = 1; + while (x) { + if (x & 1) ans = ans * a; + a = a * a, x >>= 1; + } + return ans; + } +}; + +void solve(void) { + int64_t n, m; + cin >> n >> m; + Matrix base; + base.resize(65, 65); + base[63][64] = base[64][64] = 1; + for (int i = 1; i <= m; i++) { + int own = 0, cnt[6] = {0, 0, 0, 0, 0, 0}, v = i; + for (int j = 0; j < 6; j++) + while (v % prime[j] == 0) own |= 1 << j, cnt[j]++, v /= prime[j]; + Matrix F; + F.resize(65, 65); + for (int S = 0; S < 64; S++) { + int O = 0; + for (int i = 0; i < 6; i++) + if ((S >> i & 1) && (own >> i & 1)) O |= 1 << i; + for (int T = 0; T < 64; T++) + if ((T & O) == T) { + int coef = 1; + for (int i = 0; i < 6; i++) + if (T >> i & 1) coef *= cnt[i]; + assert(F[S ^ T][S] == 0); + F[S ^ T][S] = coef; + } + } + base = base + F; + } + Matrix A; + A.resize(1, 65); + for (int i = 0; i < 64; i++) A[0][i] = 1; + A = A * (base ^ (n + 1)); + cout << (A[0][64] + mod - 1) % mod << endl; + return; +} + +bool mem2; + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr); +#ifdef LOCAL + cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; +#endif + + int _ = 1; + while (_--) solve(); + +#ifdef LOCAL + cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; +#endif + return 0; +} \ No newline at end of file diff --git a/AtCoder/arc182_d.cpp b/AtCoder/arc182_d.cpp new file mode 100644 index 0000000..726ced8 --- /dev/null +++ b/AtCoder/arc182_d.cpp @@ -0,0 +1,53 @@ +/** + * @file arc182_d.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-08-11 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 200005 + +int a[maxn], b[maxn]; + +void solve(void) { + int n, m; + cin >> n >> m; + for (int i = 1; i <= n; i++) cin >> a[i]; + for (int i = 1; i <= n; i++) cin >> b[i]; + { + bool chk = true; + for (int i = 1; i <= n; i++) chk &= (a[i] == b[i]); + if (chk) return cout << 0 << endl, void(); + } + if (m == 2) return cout << -1 << endl, void(); + + return; +} + +bool mem2; + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr); +#ifdef LOCAL + cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; +#endif + + int _ = 1; + while (_--) solve(); + +#ifdef LOCAL + cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; +#endif + return 0; +} \ No newline at end of file