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?

[ABC432] ABC 432(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

Posted at

[ABC432] ABC 432(Atcoder Beginner Contest)のA~C(A,B,C)問題をPythonで解説(復習)

合計回答時間:50分

A問題

自分の回答

かかった時間:5分

A,B,C = map(int,input().split())

lt = []

lt.append(A)
lt.append(B)
lt.append(C)

lt.sort(reverse=True)
new_lt = list(map(str,lt))

print(''.join(new_lt))

終了後考えた最適な回答

a, b, c = map(int,input().split())
v = sorted([a, b, c])
print(v[2] + v[1] + v[0])

B問題

自分の回答

かかった時間:15分

import itertools

X = int(input())

# 数字をリストに変換
lst = [int(d) for d in str(X)]


# intertoolsで順列全探索
all_lst = list(itertools.permutations(lst))

# 数字に戻す
ans = 10 ** 5
for i in range(len(all_lst)):
    num = int("".join(map(str, all_lst[i])))
# 先頭が0でない かつ 値が最小なものを出力
    if len(str(num)) == len(str(X)) and num < ans:
        ans = num

print(ans)

終了後考えた最適な回答

x = sorted(input())
for i in range(len(x)):
    if x[i] > '0':
        x[0], x[i] = x[i], x[0]
        break
print(''.join(x))

C問題

終了後考えた最適な回答

# 入力例1を例に具体的に考える
#  条件1 78 <= P <= 80
#  条件2 Pを2で割った余り = 6Aiを2で割った余り = r
#       (80-6*11)/2 = 7 余り 0
#       (80-6*10)/2 = 10 余り 0
#       (80-6*13)/2 = 1 余り 0
#  条件3 Pが大きくなるほどyiも大きくなる
#       つまりP = 78のときより、P = 80のときの方がyiは大きくなる

# 解法 
# 条件2を満たさない場合は-1を出力
# 2で割った余りがrである80以下の最大の整数をPとする
# ただし、Pが78未満となるならば条件を満たすPは存在しないため、-1を出力する

N,X,Y = map(int,input().split())
A = list(map(int,input().split()))

def floor(a, b):
    return a // b

m = min(A)
M = max(A)

D = Y - X

# 条件2: 合同条件
r = (X * A[0]) % D
for Ai in A:
    if (X * Ai) % D != r:
        print(-1)
        exit()

P_max = Y * m

P_min = X * M

# 条件3: P_max 以下で P ≡ r (mod D) の最大の P
P = D * floor(P_max - r, D) + r

if P < P_min:
    print(-1)
    exit()

ans = 0
for Ai in A:
    yi = (P - X * Ai) // D
    ans += yi

print(ans)

次に向けてやること

・C問題をひたすら解くこと

感想

今回のC問題は解けなくてもしょうがないと割り切る、でも解説を見た後は自分で入力例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?