Skip to content

Commit

Permalink
Codeforces Gym: 2023-2024 ICPC NERC (NEERC), North-Western Russia Reg…
Browse files Browse the repository at this point in the history
…ional Contest (Northern Subregionals)
  • Loading branch information
Macesuted committed Jul 2, 2024
1 parent b06ca43 commit 6089859
Show file tree
Hide file tree
Showing 9 changed files with 540 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Codeforces Gym/104772A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file 104772A.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-02
*
* @copyright Copyright (c) 2024
*
*/

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

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

bool mem1;

void solve(void) {
int a[4];
for (int i = 0; i < 4; i++) cin >> a[i];
sort(a, a + 4);
cout << a[0] * a[2] << 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;
}
47 changes: 47 additions & 0 deletions Codeforces Gym/104772D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file 104772D.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-02
*
* @copyright Copyright (c) 2024
*
*/

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

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

bool mem1;

int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }

void solve(void) {
int n;
cin >> n;
int sum = 0, tn = n;
while (tn) sum += tn % 10, tn /= 10;
int lcm = sum / gcd(sum, n) * n;
for (int i = lcm / sum; i; i--) cout << n;
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;
}
79 changes: 79 additions & 0 deletions Codeforces Gym/104772E.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @file 104772E.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-02
*
* @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;

void solve(void) {
int n;
cin >> n;
int f1, f2, f3, f4;
bool x1 = true, x2 = true, x3 = true, x4 = true;
set<pii> S;
for (int i = 1, x, y; i <= n; i++) {
cin >> x >> y;
int g1 = x, g2 = y, g3 = x - y, g4 = x + y;
if (i == 1) f1 = g1, f2 = g2, f3 = g3, f4 = g4;
if (x1 && f1 != g1) x1 = false, S.emplace(f1, y - (f1 - g1)), S.emplace(f1, y), S.emplace(f1, y + (f1 - g1));
if (x2 && f2 != g2) x2 = false, S.emplace(x - (f2 - g2), f2), S.emplace(x, f2), S.emplace(x + (f2 - g2), f2);
if (x3 && f3 != g3) {
x3 = false, S.emplace(x, x - f3), S.emplace(f3 + y, y);
int d = f3 - g3;
if (d % 2 == 0) S.emplace(x + d / 2, y - d / 2);
}
if (x4 && f4 != g4) {
x4 = false, S.emplace(x, f4 - x), S.emplace(f4 - y, y);
int d = f4 - g4;
if (d % 2 == 0) S.emplace(x + d / 2, y + d / 2);
}
for (auto i = S.begin(); i != S.end();)
if (i->first != x && i->second != y && abs(i->first - x) != abs(i->second - y))
i = S.erase(i);
else
i++;
// cerr << "###" << x1 << ' ' << f1 << ' ' << x2 << ' ' << f2 << ' ' << x3 << ' ' << f3 << ' ' << x4 << ' ' << f4 << endl;
// for (auto [x, y] : S) cerr << x << ' ' << y << endl;
// cerr << endl;
}
if (!S.empty()) return cout << "YES" << endl << S.begin()->first << ' ' << S.begin()->second << endl, void();
if (x1) return cout << "YES" << endl << f1 << ' ' << 0 << endl, void();
if (x2) return cout << "YES" << endl << 0 << ' ' << f2 << endl, void();
if (x3) return cout << "YES" << endl << f3 << ' ' << 0 << endl, void();
if (x4) return cout << "YES" << endl << f4 << ' ' << 0 << endl, void();
cout << "NO" << 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;
cin >> _;
while (_--) solve();

#ifdef LOCAL
cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl;
#endif
return 0;
}
74 changes: 74 additions & 0 deletions Codeforces Gym/104772F.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file 104772F.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-02
*
* @copyright Copyright (c) 2024
*
*/

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

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

bool mem1;

#define maxn 105

int a[maxn], b[maxn];
int f[maxn][maxn][maxn];

void dfs(int i, int j, int k) {
if (i == 0) return;
if (i == 1) return cout << "SC", void();
int p = f[i][j][k];
if (p == -1) return cout << "SC", dfs(i - 1, j + 1, k + 1);
cout << "S";
dfs(p, j + 1, k);
cout << "C";
dfs(i - p - 1, j + p + 1, k + p + 1);
return;
}

void solve(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (a[i] == b[j]) f[1][i][j] = true;
for (int i = 2; i <= n; i++)
for (int j = 1; j + i - 1 <= n; j++)
for (int k = 1; k + i - 1 <= n; k++) {
if (a[j] == b[k] && f[i - 1][j + 1][k + 1]) f[i][j][k] = -1;
if (a[j] == b[k + i - 1] && f[i - 1][j + 1][k]) f[i][j][k] = i - 1;
for (int p = 1; p < i - 1 && !f[i][j][k]; p++)
if (a[j] == b[k + p] && f[p][j + 1][k] && f[i - p - 1][j + p + 1][k + p + 1]) f[i][j][k] = p;
}
if (!f[n][1][1]) return cout << "NO" << endl, void();
cout << "YES" << endl;
dfs(n, 1, 1);
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;
}
49 changes: 49 additions & 0 deletions Codeforces Gym/104772G.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @file G.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-02
*
* @copyright Copyright (c) 2024
*
*/

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

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

bool mem1;

#define maxn 555

int f[maxn][maxn];

void solve(void) {
int n, p, mod;
cin >> n >> p >> mod;
f[0][p] = 1;
for (int i = 1; i <= n - p; i++)
for (int j = 0; j + i <= n - p; j++)
for (int k = 0; k < 512; k++) f[j + i][k ^ i] = (f[j + i][k ^ i] + f[j][k]) % mod;
cout << f[n - p][0] << 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/104772I.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @file 104772I.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-07-02
*
* @copyright Copyright (c) 2024
*
*/

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

bool mem1;

int n, k;
bool f[15];

int post(int l, int r) {
cout << l << ' ' << r << endl;
cin >> k;
if (k == n) exit(0);
return k;
}

void solve(void) {
cin >> n >> k;
if (k == n) return;
auto check = [&](int p) {
if (f[p]) return true;
int v = k;
post(p, p);
if (v + 1 == k) return f[p] = true;
if (v - 1 == k) return post(p, p), f[p] = true;
return f[p] = false;
};
for (int i = 1; i <= n; i++) check(i);
for (int i = 1; i <= n; i++)
while (!f[i]) {
int d = 1;
while (i + d <= n && !f[i + d]) d++;
bool stop = false;
vector<int> SS;
SS.push_back(0);
for (int t = 0; t < d; t++)
for (int i = (int)SS.size() - 1; ~i; i--) SS.push_back(SS[i] + (1 << t));
for (int S = 1; S < (int)SS.size(); S++) {
for (int j = 0; j < d; j++)
if ((SS[S] >> j & 1) != (SS[S - 1] >> j & 1)) {
int v = k;
post(i, i + j);
if (v != k) {
for (int t = i; t <= n; t++) check(t);
stop = true;
break;
}
}
if (stop) break;
}
}
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 6089859

Please sign in to comment.