Skip to content

Commit 47f2a11

Browse files
committed
676 easy
1 parent a5e104f commit 47f2a11

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

Diff for: codeforces/676/a.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
n = int(input())
2+
a = list(map(int, input().split()))
3+
4+
x = 0
5+
y = n - 1
6+
for i in range(n):
7+
if a[i] == 1:
8+
x = i
9+
if a[i] == n:
10+
y = i
11+
12+
old = abs(x - y)
13+
if n == 2:
14+
print(1)
15+
else:
16+
print(max(old, x, n - 1 - x, y, n - 1 - y))

Diff for: codeforces/676/b.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from fractions import Fraction
2+
3+
n, t = map(int, input().split())
4+
5+
tri = []
6+
for row in range(n):
7+
arr = [0] * (row + 1)
8+
tri.append(arr)
9+
10+
tri[0][0] = 2048 * t
11+
12+
ans = 0
13+
for i, row in enumerate(tri):
14+
for j, cell in enumerate(row):
15+
if cell >= 2048:
16+
ans += 1
17+
excess = cell - 2048
18+
if i + 1 < n:
19+
tri[i + 1][j] += excess // 2
20+
tri[i + 1][j + 1] += excess // 2
21+
22+
row[j] = 2048
23+
24+
print(ans)

Diff for: codeforces/676/c.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <iostream>
2+
#include <cstring>
3+
#include <algorithm>
4+
#include <utility>
5+
#include <vector>
6+
7+
using namespace std;
8+
9+
typedef long long ll;
10+
typedef pair<int, int> pii;
11+
12+
int n, k;
13+
string s;
14+
15+
bool works(int size) {
16+
//cout << "Trying " << size << '\n';
17+
int ac = 0;
18+
int bc = 0;
19+
for (int i = 0; i < size; ++i) {
20+
if (s[i] == 'a') ++ac;
21+
else ++bc;
22+
}
23+
if (ac <= k || bc <= k) {
24+
//cout << "First chars match" << '\n';
25+
return true;
26+
}
27+
28+
29+
for (int i = size; i < n; ++i) {
30+
if (s[i - size] == 'a') --ac;
31+
else --bc;
32+
33+
if (s[i] == 'a') ++ac;
34+
else ++bc;
35+
if (ac <= k || bc <= k) {
36+
//cout << "Match at " << i << '\n';
37+
return true;
38+
}
39+
}
40+
41+
return false;
42+
}
43+
44+
int main() {
45+
cin >> n >> k;
46+
cin >> s;
47+
if (works(n)) {
48+
cout << n << '\n';
49+
} else {
50+
int lo = 0;
51+
int hi = n;
52+
while (lo + 1 < hi) {
53+
int mid = (lo + hi) / 2;
54+
if (works(mid)) {
55+
lo = mid;
56+
} else {
57+
hi = mid;
58+
}
59+
}
60+
cout << lo << '\n';
61+
}
62+
return 0;
63+
}

0 commit comments

Comments
 (0)