1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AtCoder Beginner Contest 154 に参加してみた

Last updated at Posted at 2020-02-11

はじめに

僕はpython初学者です。同じ初学者に馴染みやすい??簡単なコードを提供するとともにもっとこうした方がいいなど改善点があったら教えてほしいです。

ABC154A Remaining Balls


s, t = input().split()
a, b = map(int, input().split())
u = input()
if u == s:
    a -= 1
elif u == t:
    b -= 1
print("{} {}".format(a, b))

ABC154B I miss you...

listから.joinしなくても ”x”*a だけでいけるのか...


s = input()
a = len(s)

l = ["x"] * a
print("".join(l))

ABC154C Distinct or Not

この問題はset()使って一発だった...


n = int(input())
a = set(map(int, input().split()))
l = len(a)
if l == n:
    print("YES")
else:
    print("NO")

ABC154D Dice in Line

期待値の計算が (1+pi)/2 で求められることに気づかず、いちいち1からpiまでの合計を出してしまった


n, k = map(int, input().split())
p = list(map(int, input().split()))

sum1 = []
kitai_list = []
ans = 0
base = 0
a = 0

for i in range(max(p) + 1):
    a += i + 1
    sum1.append(a)

for i in range(k):
    kitai = sum1[p[i] - 1] / (p[i])
    kitai_list.append(kitai)
    base += kitai

ans = base

for i in range(1, n):
    if i + k - 1 >= n:
        break
    else:
        kitai = sum1[p[i + k - 1] - 1] / (p[i + k - 1])
        kitai_list.append(kitai)
        base = base - kitai_list[i - 1] + kitai
        if ans < base:
            ans = base

print(ans)

ABC154E Almost Everywhere Zero

これは諦め〜 どなたか解法を教えてください( ; ; )

ABC154F Many Many Paths

わかってたけどTLE.あと、なぜかREもでてた。なぜだろう?
AC出てた人はmodを使ってたけどよくわかりませんでした...
教えてください!!


r1, c1, r2, c2 = map(int, input().split())
r1 += 1
c1 += 1
r2 += 1
c2 += 1
m = [[1] * r2]
l=[1]
l1=[0]*(r2-1)
l.append(l1)
l = [[0] * r2 for _ in range(c2 - 1)]
m.extend(l)
for i in range(c2):
    m[i][0] = 1
ans = 0
for i in range(1, c2):
    for j in range(1, r2):
        m[i][j] = m[i][j - 1] + m[i - 1][j]
        if r1 - 1 <= j <= r2 - 1 and c1 - 1 <= i <= c2 - 1:
            ans += m[i][j]
print(ans % (10 ** 9 + 7))

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?