1
0

ABC345をPythonで(A~C+α)

Posted at

モノグサプログラミングコンテスト2024(AtCoder Beginner Contest 345)の解答等のまとめ

A問題

問題の通りに書けばいい

A
s = input()

print("Yes" if s[0] == "<" and s[-1] == ">" and s[1:-1] == "=" * (len(s) - 2) else "No")

B問題

Pythonで切り上げ演算すればいい

B
print((int(input())+9)//10)

C問題

同じ文字を入れ替えても最初と変わらないので、最初と同じものを計算すればいい

コードは

  1. 選ぶパターンをansとして計算する
  2. 重複するパターン分ansから引く
  3. 重複することがあったら最後に1足す
C
from collections import defaultdict

s = input()

ans = len(s) * (len(s) - 1) // 2

d = defaultdict(int)
same_start = 0
for s_i in s:
    ans -= d[s_i]
    if d[s_i] > 0:
        same_start = 1
    d[s_i] += 1

print(ans + same_start)

D問題

  • 全探索してもギリギリ間に合う設定なのはすぐに分かった
  • ただPythonだからか、どう書いてもTLEする(たぶんコードが悪いだけ)

E問題

  • dpなら$O(NK)$でやれると判断してやってた
  • ただPythonだからか、どう書いてもTLEする(たぶんコードが悪いだけ)
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