more code

This commit is contained in:
Barrett Ruth 2025-01-30 17:06:38 -05:00
parent 7aacde99f4
commit 742bf851a9
149 changed files with 7065 additions and 0 deletions

45
codeforces/984/a.cc Normal file
View file

@ -0,0 +1,45 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << (x) << '\n'
#else
#define dbg(x)
#endif
void solve() {
int n;
cin >> n;
vector<int> notes(n, 0);
for (auto &x : notes)
cin >> x;
for (int i = 1; i < notes.size(); ++i) {
auto diff = abs(notes[i] - notes[i - 1]);
if (!(diff == 5 || diff == 7)) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

17
codeforces/984/a.in Normal file
View file

@ -0,0 +1,17 @@
8
2
114 109
2
17 10
3
76 83 88
8
38 45 38 80 85 92 99 106
5
63 58 65 58 65
8
117 124 48 53 48 43 54 49
5
95 102 107 114 121
10
72 77 82 75 70 75 68 75 68 75

54
codeforces/984/b.cc Normal file
View file

@ -0,0 +1,54 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << (x) << '\n'
#else
#define dbg(x)
#endif
#define MAX_K 2 * 100000
// clearing/resetting vector
// clean way for x^n; exppow
// sorting in orders
// totally misread: test case time *
// how does time work???? per-test case... or
void solve() {
int n, k;
cin >> n >> k;
vector<int> brand_to_cost(k + 1, 0);
for (int i = 0; i < k; ++i) {
int b, c;
cin >> b >> c;
brand_to_cost[b] += c;
}
sort(all(brand_to_cost), std::greater<int>{});
std::cout << accumulate(brand_to_cost.begin(),
brand_to_cost.begin() + min(n, sz(brand_to_cost)),
0LL)
<< '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

14
codeforces/984/b.in Normal file
View file

@ -0,0 +1,14 @@
4
3 3
2 6
2 7
1 15
1 3
2 6
2 7
1 15
6 2
1 7
2 5
190000 1
1 1000

0
codeforces/984/b.out Normal file
View file

76
codeforces/984/c.cc Normal file
View file

@ -0,0 +1,76 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
// variable iterator macro needed
// NOTE: can prob optimize by sorting queries
// fix matchparen highlight
// NOTE: didn't realize queries are independent (bruh)
void solve() {
string s;
cin >> s;
auto valid = [&](int i) -> bool {
return i >= 0 && i < sz(s) - 3 && s[i] == '1' && s[i + 1] == '1' &&
s[i + 2] == '0' && s[i + 3] == '0';
};
int count = 0;
for (int i = 0; i < sz(s); ++i) {
if (valid(i)) {
++count;
}
}
int q;
cin >> q;
for (int _ = 0; _ < q; _++) {
int i;
char v;
cin >> i >> v;
--i;
if (s[i] != v) {
bool left = false;
for (int j = i - 3; j <= i; ++j) {
if (valid(j)) {
left = true;
break;
}
}
s[i] = v;
bool right = false;
for (int j = i - 3; j <= i; ++j) {
if (valid(j)) {
right = true;
break;
}
}
count += (right - left);
}
cout << (count > 0 ? "YES" : "NO") << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

24
codeforces/984/c.in Normal file
View file

@ -0,0 +1,24 @@
4
100
4
1 1
2 0
2 0
3 1
1100000
3
6 1
7 1
4 1
111010
4
1 1
5 0
4 1
5 0
0100
4
3 1
1 1
2 0
2 1

15
codeforces/984/c.out Normal file
View file

@ -0,0 +1,15 @@
NO
NO
NO
NO
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO

93
codeforces/984/d.cc Normal file
View file

@ -0,0 +1,93 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
#ifdef LOCAL
#define dbg(x) cerr << #x << " = " << (x) << '\n'
#else
#define dbg(x)
#endif
constexpr auto _1543 = "1543";
int find_1543(const string &layer) {
if (sz(layer) < 4) {
return 0;
}
string extended = layer + layer.substr(0, 3);
int count = 0;
for (int i = 0; i < sz(layer); ++i) {
bool found = true;
for (int j = 0; j < 4; j++) {
if (extended[i + j] != _1543[j]) {
found = false;
break;
}
}
count += found;
}
return count;
}
string layer(const vector<string> &carpet, int n, int m, int i) {
int top = i, bot = n - 1 - i, l = i, r = m - 1 - i;
string pattern;
for (int c = l; c <= r; c++) {
pattern.push_back(carpet[top][c]);
}
for (int row = top + 1; row < bot; row++) {
pattern.push_back(carpet[row][r]);
}
if (bot > top) {
for (int c = r; c >= l; c--) {
pattern.push_back(carpet[bot][c]);
}
}
if (l < r) {
for (int r = bot - 1; r > top; r--) {
pattern.push_back(carpet[r][l]);
}
}
return pattern;
}
void solve() {
int n, m;
cin >> n >> m;
vector<string> carpet(n);
for (auto &x : carpet) {
cin >> x;
}
long long ans = 0;
const int LAYER_COUNT = min(n, m) / 2;
for (int i = 0; i < LAYER_COUNT; ++i) {
string ring = layer(carpet, n, m, i);
ans += find_1543(ring);
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}

31
codeforces/984/d.in Normal file
View file

@ -0,0 +1,31 @@
8
2 4
1543
7777
2 4
7154
8903
2 4
3451
8888
2 2
54
13
2 2
51
43
2 6
432015
512034
4 4
5431
1435
5518
7634
6 4
5432
1152
4542
2432
2302
5942

0
codeforces/984/d.out Normal file
View file

64
codeforces/984/e.cc Normal file
View file

@ -0,0 +1,64 @@
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())
#define FOR(x) for (int i = 0; i < (x).size(); ++i)
void solve() {
int n, k, q;
cin >> n >> k >> q;
vector<vector<int>> b(k + 1, vector<int>(n + 1, 0));
int v;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) {
cin >> v;
b[j][i] = b[j][i - 1] | v;
}
}
while (q--) {
int m;
cin >> m;
int l = 0, r = n - 1;
while (m--) {
int R, v;
char c;
cin >> R;
cin >> c;
cin >> v;
if (c == '<') {
int i = distance(b[R].begin() + 1, lower_bound(all(b[R]), v)) - 1;
r = min(r, i);
} else {
int i = distance(b[R].begin() + 1, upper_bound(all(b[R]), v));
l = max(l, i);
}
}
if (l <= r) {
cout << l + 1 << '\n';
} else {
cout << -1 << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// int t;
// cin >> t;
// while (t--) {
solve();
// }
return 0;
}

16
codeforces/984/e.in Normal file
View file

@ -0,0 +1,16 @@
3 4 4
1 3 5 9
4 6 5 3
2 1 2 7
3
1 > 4
2 < 8
1 < 6
2
1 < 8
2 > 8
1
3 > 5
2
4 > 8
1 < 8

4
codeforces/984/e.out Normal file
View file

@ -0,0 +1,4 @@
2
-1
3
1