Skip to content

Commit cdf368d

Browse files
Add files via upload
1 parent ff5c76d commit cdf368d

5 files changed

+148
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
x = n // 15 + 1
4+
ans = 3 * x
5+
if n % 15 == 0:
6+
ans -= 2
7+
elif (n - 1) % 15 == 0:
8+
ans -= 1
9+
print(ans)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
typedef vector<int> vi;
8+
#define fast_cin() \
9+
ios_base::sync_with_stdio(false); \
10+
cin.tie(NULL); \
11+
cout.tie(NULL);
12+
13+
int main() {
14+
int tc;
15+
cin >> tc;
16+
while (tc--) {
17+
ll n, x, k;
18+
cin >> n >> x >> k;
19+
string s;
20+
cin >> s;
21+
22+
// consider x to 0
23+
ll c = x;
24+
ll t = 0;
25+
for (; t < n && c != 0; t++) {
26+
if (s[t] == 'R') {
27+
c++;
28+
} else {
29+
c--;
30+
}
31+
}
32+
33+
if (c != 0) {
34+
cout << 0 << endl;
35+
continue;
36+
}
37+
38+
ll l = 0;
39+
do {
40+
if (s[l] == 'R') {
41+
c++;
42+
} else {
43+
c--;
44+
}
45+
l++;
46+
} while (l < n && c != 0);
47+
48+
if (c != 0) {
49+
cout << 1 << endl;
50+
continue;
51+
}
52+
cout << (k - t) / l + 1 << endl;
53+
}
54+
55+
return 0;
56+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
typedef vector<int> vi;
8+
#define fast_cin() \
9+
ios_base::sync_with_stdio(false); \
10+
cin.tie(NULL); \
11+
cout.tie(NULL);
12+
13+
ll n, k;
14+
string s;
15+
vector<int> a;
16+
17+
bool canDo(int maxPenalty) {
18+
int numOperations = k;
19+
20+
bool painting = false;
21+
for (int i = 0; i < n; i++) {
22+
if (a[i] <= maxPenalty) {
23+
continue;
24+
}
25+
26+
if (!painting) {
27+
if (s[i] == 'B') {
28+
painting = true;
29+
if (numOperations == 0) return false;
30+
numOperations--;
31+
}
32+
} else {
33+
if (s[i] == 'R') {
34+
painting = false;
35+
}
36+
}
37+
}
38+
39+
return true;
40+
}
41+
42+
int main() {
43+
int tc;
44+
cin >> tc;
45+
while (tc--) {
46+
cin >> n >> k;
47+
cin >> s;
48+
a.resize(n);
49+
for (int i = 0; i < n; i++) {
50+
cin >> a[i];
51+
}
52+
53+
int l = 0;
54+
int h = 1e9;
55+
56+
while (l < h) {
57+
int m = (h + l) / 2;
58+
if (canDo(m)) {
59+
h = m;
60+
} else {
61+
l = m + 1;
62+
}
63+
}
64+
65+
cout << l << endl;
66+
}
67+
68+
return 0;
69+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
for _ in range(int(input())):
2+
n, k, p = map(int, input().split())
3+
need = (abs(k) + p - 1) // p
4+
print(-1 if n < need else need)
5+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from collections import Counter
2+
3+
for _ in range(int(input())):
4+
n = int(input())
5+
c = Counter(input())
6+
x = c["-"] // 2
7+
y = c["_"]
8+
z = c["-"] - x
9+
print(x * y * z)

0 commit comments

Comments
 (0)