0
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?

ABC392をPythonで(A~D)

Posted at

日本レジストリサービス(JPRS)プログラミングコンテスト2025#1(AtCoder Beginner Contest 392)の解答等の速報的まとめ

A問題

小さい2つの積が一番大きいのと一致するかを判定すればいい

A
a = sorted(map(int, input().split()))
print("Yes" if a[0] * a[1] == a[2] else "No")

B問題

内包表記で入っていないものをリストアップした

B
n, m = map(int, input().split())
a = set(map(int, input().split()))

c = [i for i in range(1, n + 1) if i not in a]

print(len(c))
print(*c)

C問題

ゼッケン番号から何番目の人か逆検索できる辞書を作ればいい

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

d_q = {q_i:i for i, q_i in enumerate(q)}

ans = []
for i in range(1, n + 1):
    ind = d_q[i] # ゼッケンiを付けいている人
    p_i = p[ind] - 1 # indが見ている人
    ans.append(q[p_i])

print(*ans)

D問題

すべての組み合わせで期待値計算を行う
期待値はダイスA、ダイスBが各目iに対して
(ダイスAが目iを出す確率)$\times$(ダイスBが目iを出す確率)
で求まる

D
def calc(dice_i, dice_j):
    k_i, d_i = dice_i
    k_j, d_j = dice_j

    res = 0
    for key, val in d_i.items():
        if key in d_j:
            res += val / k_i * d_j[key] / k_j

    return res


n = int(input())
dice = []
for _ in range(n):
    k, *arg = map(int, input().split())
    dic = dict()
    for a_i in arg:
        if a_i not in dic:
            dic[a_i] = 0
        dic[a_i] += 1
    dice.append([k, dic])

print(max(calc(dice[i], dice[j]) for i in range(n) for j in range(i)))

E問題

切っても問題ない辺を調べて、それぞれをUnionFindで違うグループの頂点につなげればいい

と考えて実装していたが1時間以上費やしてもうまくいかなかった

0
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
0
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?