Skip to content

Commit

Permalink
Codeforces Gym: 105053
Browse files Browse the repository at this point in the history
The 2024 ICPC Latin America Championship
  • Loading branch information
Macesuted committed Jul 4, 2024
1 parent cfc7890 commit a0eabe7
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Codeforces Gym/105053D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @file 105053D.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-03
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

typedef pair<int, int> pii;

vector<pii> 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;
}
78 changes: 78 additions & 0 deletions Codeforces Gym/105053E.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @file 105053E.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-03
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

#define maxn 1005

typedef pair<int, int> pii;

vector<int> 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;
}
65 changes: 65 additions & 0 deletions Codeforces Gym/105053F.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @file 105053F.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-03
*
* @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], 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;
}
98 changes: 98 additions & 0 deletions Codeforces Gym/105053G.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @file 105053G.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-03
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
using namespace std;

#ifndef LOCAL
#define endl '\n'
#endif

bool mem1;

#define maxn 100005

typedef pair<int, int> pii;

double p[maxn], f[maxn];
bool notPrime[maxn];
vector<int> num[maxn], prime;
vector<pii> 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;
}
71 changes: 71 additions & 0 deletions Codeforces Gym/105053K.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @file 105053K.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-03
*
* @copyright Copyright (c) 2024
*
*/

#include <bits/stdc++.h>
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;
}
Loading

0 comments on commit a0eabe7

Please sign in to comment.