Skip to content

Commit 13d5e65

Browse files
Codeforces Round 799
1 parent 9de7c11 commit 13d5e65

File tree

31 files changed

+682
-29
lines changed

31 files changed

+682
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
n = sint()
17+
nums = ints()
18+
suff = [0] * (n + 1)
19+
s = mx = 0
20+
for i in range(n - 1, -1, -1):
21+
s += nums[i]
22+
suff[i] = max(nums[i], suff[i + 1])
23+
ans = []
24+
for i, x in enumerate(nums, 1):
25+
if s - x == max(suff[i], mx) * 2:
26+
ans.append(i)
27+
mx = max(mx, x)
28+
29+
print(len(ans))
30+
print(*ans)
31+
32+
33+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()

Diff for: Contests/CodeforcesPython/Codeforces Round 799 Div. 4/A_Marathon/A_Marathon.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
1414

1515
def solve() -> None:
16-
return
16+
d = ints()
17+
print(sum(x > d[0] for x in d[1:]))
1718

1819

1920
for _ in range(int(input())):

Diff for: Contests/CodeforcesPython/Codeforces Round 799 Div. 4/B_All_Distinct/B_All_Distinct.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from collections import Counter
23

34
# region fastio
45
input = lambda: sys.stdin.readline().rstrip()
@@ -13,7 +14,10 @@
1314
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
1415

1516
def solve() -> None:
16-
return
17+
n = sint()
18+
nums = ints()
19+
cnt = Counter(nums)
20+
print(n - (sum(v - 1 for v in cnt.values()) + 1) // 2 * 2)
1721

1822

1923
for _ in range(int(input())):

Diff for: Contests/CodeforcesPython/Codeforces Round 799 Div. 4/C_Wheres_the_Bishop/C_Wheres_the_Bishop.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
1414

1515
def solve() -> None:
16-
return
16+
input()
17+
g = []
18+
for i in range(8):
19+
g.append(input())
20+
21+
for i in range(1, 7):
22+
for j in range(1, 7):
23+
if g[i][j] == '#' and g[i - 1][j - 1] == '#' and g[i - 1][j + 1] == '#':
24+
print(i + 1, j + 1)
25+
return
1726

1827

1928
for _ in range(int(input())):

Diff for: Contests/CodeforcesPython/Codeforces Round 799 Div. 4/D_The_Clock/D_The_Clock.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import sys
23

34
# region fastio
@@ -12,8 +13,25 @@
1213
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
1314
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
1415

16+
pal = set()
17+
for t in range(1440):
18+
h, m = divmod(t, 60)
19+
h0, h1 = divmod(h, 10)
20+
m0, m1 = divmod(m, 10)
21+
if h0 == m1 and h1 == m0:
22+
pal.add(t)
23+
24+
1525
def solve() -> None:
16-
return
26+
s, x = input().split()
27+
h, m = s.split(':')
28+
t = int(h) * 60 + int(m)
29+
g = math.gcd(int(x), 1440)
30+
ans = 0
31+
for p in pal:
32+
if (p - t) % 1440 % g == 0:
33+
ans += 1
34+
print(ans)
1735

1836

1937
for _ in range(int(input())):

Diff for: Contests/CodeforcesPython/Codeforces Round 799 Div. 4/E_Binary_Deque/E_Binary_Deque.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import sys
23

34
# region fastio
@@ -13,7 +14,19 @@
1314
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
1415

1516
def solve() -> None:
16-
return
17+
n, s = mint()
18+
nums = ints()
19+
ans = math.inf
20+
l = m = 0
21+
for r, x in enumerate(nums):
22+
m += x
23+
while m > s:
24+
m -= nums[l]
25+
l += 1
26+
if m == s:
27+
ans = min(ans, l + n - 1 - r)
28+
29+
print(-1 if ans == math.inf else ans)
1730

1831

1932
for _ in range(int(input())):

Diff for: Contests/CodeforcesPython/Codeforces Round 799 Div. 4/G_2Sort/G_2Sort.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@
1313
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
1414

1515
def solve() -> None:
16-
return
16+
n, k = mint()
17+
nums = ints()
18+
suff = 1
19+
ans = 0
20+
for i in range(n - 2, -1, -1):
21+
if nums[i] < nums[i + 1] * 2:
22+
suff += 1
23+
else:
24+
suff = 1
25+
if suff > k:
26+
ans += 1
27+
print(ans)
1728

1829

1930
for _ in range(int(input())):

Diff for: Contests/CodeforcesPython/Codeforces Round 799 Div. 4/H_Gambling/H_Gambling.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import sys
2+
from collections import defaultdict
3+
from random import getrandbits
24

35
# region fastio
46
input = lambda: sys.stdin.readline().rstrip()
@@ -13,7 +15,21 @@
1315
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
1416

1517
def solve() -> None:
16-
return
18+
n = sint()
19+
nums = ints()
20+
h = getrandbits(30)
21+
pos = defaultdict(list)
22+
for i, x in enumerate(nums, 1):
23+
pos[x ^ h].append(i)
24+
ans, l, r, mx = nums[0], 1, 1, 1
25+
for x, arr in pos.items():
26+
i = 0
27+
for j in range(len(arr)):
28+
if j * 2 - i * 2 + 1 - arr[j] + arr[i] < 1:
29+
i = j
30+
if j * 2 - i * 2 + 1 - arr[j] + arr[i] > mx:
31+
ans, l, r, mx = x ^ h, arr[i], arr[j], j * 2 - i * 2 + 1 - arr[j] + arr[i]
32+
print(ans, l, r)
1733

1834

1935
for _ in range(int(input())):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
n = sint()
17+
nums = ints()
18+
print(nums[-1] + max(nums[:-1]))
19+
20+
21+
for _ in range(int(input())):
22+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
n, a, b = mint()
17+
ans = a * n
18+
if b > a:
19+
i = min(n, b - a + 1)
20+
ans = a * (n - i) + (b * 2 - i + 1) * i // 2
21+
print(ans)
22+
23+
24+
for _ in range(int(input())):
25+
solve()

0 commit comments

Comments
 (0)