Skip to content

Commit 2620032

Browse files
author
IsHYuhi
committed
add ABCs
1 parent 7bbfb39 commit 2620032

File tree

19 files changed

+243
-0
lines changed

19 files changed

+243
-0
lines changed

ABC/ABC149/A.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s, t = input().split()
2+
print(t+s)

ABC/ABC149/B.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a, b, k = map(int, input().split())
2+
print(max(0, a-k), max(0, b-max(0, (k-a))))

ABC/ABC149/C.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import math
2+
3+
def min_prime(start, limit):
4+
for k in range(start, limit+1):
5+
6+
if k%2 == 0 and k !=2:
7+
continue
8+
9+
factor = 0
10+
11+
for divisor in range(2, math.ceil(math.sqrt(k))):
12+
if k % divisor == 0:
13+
factor += 1
14+
15+
if factor == 0:
16+
return k
17+
18+
x = int(input())
19+
print(min_prime(x, 10**6))

ABC/ABC180/A.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
n, a, b = map(int, input().split())
2+
print(n-a+b)

ABC/ABC180/B.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import math
2+
n = int(input())
3+
x = list(map(lambda x: abs(int(x)), input().split()))
4+
print(sum(x))
5+
mx = max(x)
6+
x = [i**2 for i in x]
7+
print(math.sqrt(sum(x)))
8+
print(mx)

ABC/ABC180/C.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import math
2+
n = int(input())
3+
4+
def decomp(n):
5+
ans = []
6+
ans_ = []
7+
for i in range(1, int(n**0.5)+1):
8+
if n%i == 0:
9+
ans.append(i)
10+
if n//i != i:
11+
ans_.append(n//i)
12+
#if (n//i)*i==n:
13+
return ans+ans_[::-1]
14+
15+
ans = decomp(n)
16+
for i in ans:
17+
print(i)

ABC/ABC185/A.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a, b, c, d = map(int, input().split())
2+
3+
print(min(a, b, c, d))

ABC/ABC185/B.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
max_n, m, t = map(int, input().split())
2+
n = max_n
3+
ab = [list(map(int, input().split())) for _ in range(m)]
4+
now = 0
5+
for i in range(m):
6+
7+
a, b = ab[i]
8+
n = min(max_n, n-(a-now))
9+
now = a
10+
if n<=0:
11+
print('No')
12+
exit()
13+
n = min(max_n, n+(b-now))
14+
now = b
15+
16+
if n-(t-now)<=0:
17+
18+
print('No')
19+
else:
20+
print('Yes')
21+

ABC/ABC185/C.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import math
2+
def combinations_count(n, r):
3+
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
4+
5+
l = int(input())
6+
print(combinations_count(l-1, 11))

ABC/ABC185/D.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from collections import deque
2+
n, m = map(int ,input().split())
3+
a = list(map(int, input().split()))
4+
if m == 0:
5+
print(1)
6+
exit()
7+
8+
a = deque(sorted(a))
9+
va = []
10+
s = 0
11+
f = n
12+
a.append(n+1)
13+
m += 1
14+
mi = n
15+
for i in range(m):
16+
if a[i]-s-1>0:
17+
va.append(a[i]-s-1)
18+
mi = min(a[i]-s-1, mi)
19+
s = a[i]
20+
21+
if not va:
22+
print(0)
23+
exit()
24+
25+
#print(va)
26+
#mi = min(va)
27+
ans = 0
28+
29+
for j in va:
30+
r = 1 if j%mi > 0 else 0
31+
ans += j//mi+r
32+
print(ans)

ABC/ABC186/A.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
n, w = map(int, input().split())
2+
print(n//w)

ABC/ABC186/B.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
h, w = map(int, input().split())
2+
3+
field = [list(map(int, input().split())) for _ in range(h)]
4+
mn = 100
5+
for i in field:
6+
mn = min(mn, min(i))
7+
8+
ans = 0
9+
for i in range(h):
10+
for j in range(w):
11+
ans += abs(field[i][j]-mn)
12+
13+
print(ans)

ABC/ABC186/C.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n = int(input())
2+
3+
ans = 0
4+
for i in range(1, n+1):
5+
if '7' not in str(i) and '7' not in str(oct(i))[2:]:
6+
ans += 1
7+
print(ans)

ABC/ABC186/D.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import bisect
2+
n = int(input())
3+
a = list(map(int, input().split()))
4+
a.sort()
5+
total = sum(a)
6+
ans = 0
7+
for o, i in enumerate(a, 1):
8+
total -= i
9+
ans += abs(i*(n-o)-total)
10+
11+
print(ans)
12+
13+
# total = sum(a)
14+
# div = [total]
15+
# a = [[i, idx] for idx, i in enumerate(a)]
16+
# new_a = sorted(a, key=lambda x: x[0])
17+
# su = 0
18+
# for i, j in new_a:
19+
# su += i
20+
# div.append(total-su)
21+
22+
# print(total)
23+
# print(new_a)
24+
# print(div)
25+
# ans = 0
26+
# new_a = sorted(new_a, key=lambda x: x[1], reverse=True)
27+
# off = 0
28+
# for i, j in new_a:
29+
# l = j-1
30+
# r = j
31+
# # l = bisect.bisect_left(new_a, i)
32+
# # r = bisect.bisect_right(new_a, i)
33+
# # print(l, r)
34+
# #print()
35+
# ans += l*i-(total-div[l]) + div[r]-off-(n-l)*i
36+
# off += div[l]
37+
# #print(div[bisect.bisect_left(new_a, i)])
38+
# #print()
39+
40+
# print(ans)

ABC/ABC187/A.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
a, b = map(str, input().split())
2+
3+
sum_a = 0
4+
for i in a:
5+
sum_a += int(i)
6+
7+
sum_b = 0
8+
for i in b:
9+
sum_b += int(i)
10+
11+
print(max(sum_a, sum_b))

ABC/ABC187/B.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
n = int(input())
2+
xy = [list(map(int, input().split())) for _ in range(n)]
3+
l = len(xy)
4+
ans = 0
5+
for i in range(l):
6+
xi, yi = xy[i][0], xy[i][1]
7+
for j in range(i+1, l):
8+
xj, yj = xy[j][0], xy[j][1]
9+
10+
a = abs((yi-yj)/(xi-xj))
11+
if a <= 1:
12+
ans += 1
13+
14+
print(ans)

ABC/ABC187/C.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
n = int(input())
2+
ss = [input() for _ in range(n)]
3+
4+
wo = dict()
5+
ex = dict()
6+
for s in ss:
7+
if s[0]== '!':
8+
ex[s[1:]] = True
9+
10+
else:
11+
wo[s] = True
12+
13+
keys = set(wo.keys()) & set(ex.keys())
14+
15+
if keys:
16+
print(list(keys)[0])
17+
else:
18+
print('satisfiable')

ABC/ABC187/D.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
n = int(input())
2+
diff = []
3+
result = 0
4+
for i in range(n):
5+
a, b = map(int, input().split())
6+
diff.append(2*a+b)
7+
result -= a
8+
9+
diff.sort(reverse=True)
10+
i = 0
11+
while result<=0:
12+
result += diff[i]
13+
i += 1
14+
print(i)

ARC/ARC024/A.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from collections import Counter
2+
l, r = map(int, input().split())
3+
ls = Counter(list(map(int, input().split())))
4+
rs = Counter(list(map(int, input().split())))
5+
6+
keys = set(ls.keys()) & set(rs.keys())
7+
8+
ans = 0
9+
for key in keys:
10+
ans += min(ls[key], rs[key])
11+
12+
print(ans)

0 commit comments

Comments
 (0)