From a0eabe72cbe147c50e5cc20f641bbc7b187b88ed Mon Sep 17 00:00:00 2001 From: Macesuted Date: Thu, 4 Jul 2024 16:21:11 +0800 Subject: [PATCH] Codeforces Gym: 105053 The 2024 ICPC Latin America Championship --- Codeforces Gym/105053D.cpp | 53 +++++++++++++++++++++ Codeforces Gym/105053E.cpp | 78 ++++++++++++++++++++++++++++++ Codeforces Gym/105053F.cpp | 65 +++++++++++++++++++++++++ Codeforces Gym/105053G.cpp | 98 ++++++++++++++++++++++++++++++++++++++ Codeforces Gym/105053K.cpp | 71 +++++++++++++++++++++++++++ Codeforces Gym/105053L.cpp | 54 +++++++++++++++++++++ 6 files changed, 419 insertions(+) create mode 100644 Codeforces Gym/105053D.cpp create mode 100644 Codeforces Gym/105053E.cpp create mode 100644 Codeforces Gym/105053F.cpp create mode 100644 Codeforces Gym/105053G.cpp create mode 100644 Codeforces Gym/105053K.cpp create mode 100644 Codeforces Gym/105053L.cpp diff --git a/Codeforces Gym/105053D.cpp b/Codeforces Gym/105053D.cpp new file mode 100644 index 0000000..4debc76 --- /dev/null +++ b/Codeforces Gym/105053D.cpp @@ -0,0 +1,53 @@ +/** + * @file 105053D.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-07-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +typedef pair pii; + +vector split; + +void solve(void) { + int64_t n; + cin >> n; + for (int64_t v = 2; v * v <= n; v++) { + int cnt = 0; + while (n % v == 0) cnt++, n /= v; + if (cnt) split.emplace_back(cnt, v); + } + if (n > 1) split.emplace_back(1, n); + if (split.size() == 1) return cout << "NY"[split[0].first % 2] << endl, void(); + if (split.size() == 2 && split[0].first == 1 && split[1].first == 1) return cout << 'Y' << endl, void(); + cout << 'N' << 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/Codeforces Gym/105053E.cpp b/Codeforces Gym/105053E.cpp new file mode 100644 index 0000000..be8488b --- /dev/null +++ b/Codeforces Gym/105053E.cpp @@ -0,0 +1,78 @@ +/** + * @file 105053E.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-07-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 1005 + +typedef pair pii; + +vector graph[maxn * 2]; +pii a[maxn]; +bool vis[maxn * 2]; + +bool cross(pii a, pii b) { + if (a.first > b.first) swap(a, b); + return b.first < a.second && a.second < b.second; +} +void dfs(int p) { + vis[p] = true; + for (auto i : graph[p]) + if (!vis[i]) dfs(i); + return; +} + +void solve(void) { + int n; + cin >> n; + for (int i = 1; i <= 2 * n; i++) { + char c; + int x; + cin >> c >> x; + if (c == '+') + a[x].first = i; + else + a[x].second = i; + } + for (int i = 1; i <= n; i++) + for (int j = 1; j <= n; j++) + if (cross(a[i], a[j])) + graph[i].push_back(j + n), graph[j + n].push_back(i), graph[i + n].push_back(j), graph[j].push_back(i + n); + for (int i = 1; i <= n; i++) + if (!vis[i] && !vis[i + n]) dfs(i); + for (int i = 1; i <= n; i++) + if (vis[i] && vis[i + n]) return cout << '*' << endl, void(); + for (int i = 1; i <= n; i++) cout << "GS"[vis[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; + 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/Codeforces Gym/105053F.cpp b/Codeforces Gym/105053F.cpp new file mode 100644 index 0000000..f2b9ee4 --- /dev/null +++ b/Codeforces Gym/105053F.cpp @@ -0,0 +1,65 @@ +/** + * @file 105053F.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-07-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 200005 + +int a[maxn], b[maxn], cnt[maxn], g[maxn]; +bool f[maxn]; + +void solve(void) { + int n, sum = 0; + cin >> n; + int delt = 0; + bool zero = false; + for (int i = 1; i <= n; i++) { + cin >> a[i] >> b[i], sum += a[i], zero |= !a[i], delt = gcd(delt, b[i]); + if (i > 1) cnt[a[i]]++; + } + f[0] = true; + for (int t = 1; t < maxn; t++) { + if (!cnt[t]) continue; + for (int i = 0; i <= sum; i++) g[i] = 0; + for (int i = 0; i <= sum; i++) { + if (f[i]) g[i] = cnt[t] + 1; + if (i >= t) g[i] = max(g[i], g[i - t] - 1); + f[i] |= g[i]; + } + } + f[0] = zero; + for (int i = 0; i <= sum; i++) + if (f[i] && i % delt == (sum - i) % delt) return cout << 'Y' << endl, void(); + cout << 'N' << 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/Codeforces Gym/105053G.cpp b/Codeforces Gym/105053G.cpp new file mode 100644 index 0000000..16d9ea4 --- /dev/null +++ b/Codeforces Gym/105053G.cpp @@ -0,0 +1,98 @@ +/** + * @file 105053G.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-07-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 100005 + +typedef pair pii; + +double p[maxn], f[maxn]; +bool notPrime[maxn]; +vector num[maxn], prime; +vector primeNum[maxn]; + +void solve(void) { + int n; + cin >> n; + double psum = 0; + for (int i = 1; i <= n; i++) cin >> p[i], psum += p[i]; + for (int i = 1; i <= n; i++) p[i] /= psum; + + for (int i = 1; i <= n; i++) + for (int j = i; j <= n; j += i) num[j].push_back(i); + for (int i = 1; i <= n; i++) { + int x = i; + for (auto j = prime.begin(); *j * *j <= x; j++) { + int cnt = 1; + while (x % *j == 0) cnt *= *j, x /= *j; + if (cnt) primeNum[i].emplace_back(*j, cnt); + } + if (x > 1) primeNum[i].emplace_back(x, x); + } + + for (int x = n; x; x--) { + double own = 0; + for (int lcm = x; lcm <= n; lcm += x) { + int base = 1, extra = 1; + for (auto i = primeNum[x].begin(), j = primeNum[lcm].begin(); j != primeNum[lcm].end(); j++) + if (i != primeNum[x].end() && i->first == j->first) { + if (i->second < j->second) + base *= j->second; + else + extra *= i->second; + i++; + } else + base *= j->second; + for (auto y : num[extra]) { + if (base * y > n) break; + if (lcm == x) + own += p[base * y]; + else + f[x] += p[base * y] * (f[lcm] + 1); + } + } + f[x] = (own + f[x]) / (1 - own); + } + cout << setprecision(10) << fixed << f[1] << endl; + return; +} + +bool mem2; + +int main() { + ios::sync_with_stdio(false), cin.tie(nullptr); +#ifdef LOCAL + freopen("G.in", "r", stdin); + cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; +#endif + + for (int i = 2; i < maxn; i++) { + if (!notPrime[i]) prime.push_back(i); + for (auto j = prime.begin(); j != prime.end() && i * *j < maxn; j++) { + notPrime[i * *j] = true; + if (i % *j == 0) break; + } + } + + 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/Codeforces Gym/105053K.cpp b/Codeforces Gym/105053K.cpp new file mode 100644 index 0000000..c0c4080 --- /dev/null +++ b/Codeforces Gym/105053K.cpp @@ -0,0 +1,71 @@ +/** + * @file 105053K.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-07-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 1000005 + +int f[maxn][3]; + +bool isVowel(char c) { return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'Y'; } + +void solve(void) { + int n; + cin >> n; + memset(f, 0x3f, sizeof(f)); + f[0][0] = 0; + for (int i = 1; i <= n; i++) { + string s; + cin >> s; + int l = 0, r = 0; + bool pre = true; + for (int j = 0; j < min(3, (int)s.size()); j++) { + if (isVowel(s[j])) + pre = false, r = 0; + else { + if (pre) l++; + r++; + } + if (pre) + for (int x = 0; x + j + 1 < 3; x++) f[i][x + j + 1] = min(f[i][x + j + 1], f[i - 1][x] + j + 1); + else + for (int x = 0; x + l < 3; x++) f[i][r] = min(f[i][r], f[i - 1][x] + j + 1); + } + } + int64_t v = min({f[n][0], f[n][1], f[n][2]}); + if (v == 0x3f3f3f3f) + cout << '*' << endl; + else + cout << v << 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/Codeforces Gym/105053L.cpp b/Codeforces Gym/105053L.cpp new file mode 100644 index 0000000..0b7aa46 --- /dev/null +++ b/Codeforces Gym/105053L.cpp @@ -0,0 +1,54 @@ +/** + * @file 105053L.cpp + * @author Macesuted (i@macesuted.moe) + * @date 2024-07-03 + * + * @copyright Copyright (c) 2024 + * + */ + +#include +using namespace std; + +#ifndef LOCAL +#define endl '\n' +#endif + +bool mem1; + +#define maxn 1005 + +string S[maxn], T[maxn]; + +void solve(void) { + int r, c, k; + cin >> r >> c >> k; + bool ans = true; + for (int i = 1; i <= r; i++) { + cin >> S[i] >> T[i]; + bool have = false; + for (auto c : T[i]) have |= (c == '*'); + if (!have) continue; + for (auto c : S[i]) + if (c == '-') ans = false; + } + cout << "NY"[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; + while (_--) solve(); + +#ifdef LOCAL + cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; +#endif + return 0; +} \ No newline at end of file