-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AtCoder: AtCoder Regular Contest 182
- Loading branch information
Showing
4 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @file arc182_a.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-11 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#ifndef LOCAL | ||
#define endl '\n' | ||
#endif | ||
|
||
bool mem1; | ||
|
||
#define maxn 5005 | ||
#define mod 998244353 | ||
|
||
typedef pair<int, int> 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* @file arc182_b.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-11 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#ifndef LOCAL | ||
#define endl '\n' | ||
#endif | ||
|
||
bool mem1; | ||
|
||
#define maxn 100005 | ||
|
||
void solve(void) { | ||
int n, k; | ||
cin >> n >> k; | ||
vector<int> 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* @file arc182_c.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-11 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
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<vector<int64_t>> a; | ||
int n, m; | ||
|
||
public: | ||
void resize(int _n, int _m) { return a.resize(n = _n, vector<int64_t>(m = _m, 0)); } | ||
|
||
vector<int64_t>& 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @file arc182_d.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-11 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
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; | ||
} |