Skip to content

Commit f3d7ac9

Browse files
Add files via upload
1 parent dea3107 commit f3d7ac9

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
for _ in range(int(input())):
3+
x = int(input())
4+
5+
arr = [0, 0, 0]
6+
ans = 0
7+
while min(arr) < x:
8+
arr.sort()
9+
arr[0] = arr[1]*2+1
10+
ans += 1
11+
print(ans)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
fibo = [-1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
3+
4+
for _ in range(int(input())):
5+
n, q = map(int, input().split())
6+
7+
if n == 1:
8+
for _ in range(q):
9+
input()
10+
print(1, end="")
11+
print()
12+
continue
13+
14+
15+
biggest = fibo[n]
16+
second_biggest = fibo[n-1]
17+
18+
for _ in range(q):
19+
arr = list(map(int, input().split()))
20+
arr.sort()
21+
22+
if arr[0] >= biggest and arr[1] >= biggest and arr[2] >= biggest + second_biggest:
23+
print(1, end="")
24+
else:
25+
print(0, end="")
26+
print()
27+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
arr = list(map(int, input().split()))
4+
ans = int(1e12)
5+
6+
cur = -1
7+
cur_start = -1
8+
for i in range(n):
9+
if cur == arr[i]:
10+
continue
11+
12+
# We consider the new row
13+
if cur_start != -1:
14+
ans = min(ans, cur_start * cur + (n-i) * (cur))
15+
16+
cur = arr[i]
17+
cur_start = i
18+
19+
ans = min(ans, cur_start * cur)
20+
print(ans)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
for _ in range(int(input())):
2+
n, m = map(int, input().split())
3+
a = list(map(int, input().split()))
4+
arr = [(x // 100, x) for x in a]
5+
arr.sort()
6+
7+
for i in range(n):
8+
# assign furthest classrooms
9+
bottom = arr[i//2][1]
10+
top = arr[m-(i//2)-1][1]
11+
12+
if i%2 == 0:
13+
print(bottom, top, bottom, top, bottom, top)
14+
else:
15+
print(top, bottom, top, bottom, top, bottom)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
using ll = long long;
7+
using vi = vector<int>;
8+
#define fast_cin() \
9+
ios_base::sync_with_stdio(false); \
10+
cin.tie(NULL); \
11+
cout.tie(NULL);
12+
13+
int n, q;
14+
string s;
15+
set<int> ca, ba, cb, bc;
16+
17+
char a = 'a', b = 'b', c = 'c';
18+
void solve() {
19+
cin >> n >> q;
20+
cin >> s;
21+
22+
ca.clear();
23+
ba.clear();
24+
cb.clear();
25+
bc.clear();
26+
for (int i = 0; i < q; i++) {
27+
char x, y;
28+
cin >> x >> y;
29+
30+
if (x == 'c' && y == 'a') {
31+
ca.insert(i);
32+
} else if (x == 'b' && y == 'a') {
33+
ba.insert(i);
34+
} else if (x == 'c' && y == 'b') {
35+
cb.insert(i);
36+
} else if (x == 'b' && y == 'c') {
37+
bc.insert(i);
38+
}
39+
}
40+
41+
for (int i = 0; i < n; i++) {
42+
if (s[i] == a) continue;
43+
44+
if (s[i] == b) {
45+
// try to do b -> a first
46+
if (!ba.empty()) {
47+
s[i] = a;
48+
ba.erase(ba.begin());
49+
} else if (!bc.empty()) {
50+
// try to do b -> c -> a
51+
int idx = *bc.begin();
52+
53+
// see if we can do c -> a
54+
auto it = ca.upper_bound(idx);
55+
if (it != ca.end()) {
56+
s[i] = a;
57+
bc.erase(bc.begin());
58+
ca.erase(it);
59+
}
60+
}
61+
}
62+
63+
else if (s[i] == c) {
64+
// try to do c -> a first
65+
if (!ca.empty()) {
66+
s[i] = a;
67+
ca.erase(ca.begin());
68+
} else if (!cb.empty()) {
69+
// try to do c -> b
70+
int idx = *cb.begin();
71+
cb.erase(cb.begin());
72+
s[i] = b;
73+
74+
// try to do b -> a
75+
auto it = ba.upper_bound(idx);
76+
if (it != ba.end()) {
77+
s[i] = a;
78+
ba.erase(it);
79+
}
80+
}
81+
}
82+
}
83+
cout << s << endl;
84+
}
85+
86+
int main() {
87+
int tc;
88+
cin >> tc;
89+
while (tc--) solve();
90+
91+
return 0;
92+
}

0 commit comments

Comments
 (0)