Skip to content

Commit c87d579

Browse files
committed
contest 686
1 parent 1466d14 commit c87d579

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

codeforces/686/a.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
n, x = map(int, input().split())
2+
3+
distress = 0
4+
for _ in range(n):
5+
s, v = input().split()
6+
v = int(v)
7+
if s == '+':
8+
x += v
9+
else:
10+
if x < v:
11+
distress += 1
12+
else:
13+
x -= v
14+
15+
print(x, distress)

codeforces/686/b.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
n = int(input())
2+
a = list(map(int, input().split()))
3+
4+
swaps = []
5+
for i in range(n):
6+
# find the value at element i
7+
smallest = a[i]
8+
best_pos = i
9+
for j in range(i + 1, n):
10+
if a[j] < smallest:
11+
smallest = a[j]
12+
best_pos = j
13+
# swap from i to j
14+
while best_pos > i:
15+
a[best_pos - 1], a[best_pos] = a[best_pos], a[best_pos - 1]
16+
swaps.append((best_pos, best_pos + 1))
17+
best_pos -= 1
18+
19+
for a, b in swaps:
20+
print(a, b)

codeforces/686/c.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import itertools
2+
def tobase(n):
3+
if n == 0:
4+
return 1
5+
6+
l = 0
7+
while n > 0:
8+
l += 1
9+
n //= 7
10+
11+
return l
12+
13+
def main():
14+
n, m = map(int, input().split())
15+
nlen = tobase(n - 1)
16+
mlen = tobase(m - 1)
17+
places = nlen + mlen
18+
19+
ans = 0
20+
for perm in itertools.permutations('0123456', places):
21+
hour = ''.join(perm[:nlen])
22+
minute = ''.join(perm[nlen:])
23+
if int(hour, 7) < n and int(minute, 7) < m:
24+
ans += 1
25+
26+
print(ans)
27+
28+
main()

0 commit comments

Comments
 (0)