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?

AtCoderをPythonで取り組んだ振り返り(ABC429 A~B)

Posted at

どうもこんにちは!

今週のコンテストはBまで完答、振り返りもBまで。
4連続で2完です。。この2週間ほどはAIプラクティショナーの受験勉強に比重を置いてはいたんですが、残念な結果です。
Cは数字の個数を数えてリストにして、これを全探索するとTLEになりました。なので1個しかない数は○個のようにカウントしたのをリストにして計算すれば解けるのではと考えていたんですがWAを解消できずタイムアップとなりました。。

問題と公式の解説のリンク

問題は以下のリンクから。

A - Too Many Requests -

問題

整数n,mが与えられ、1から順番にm以下でればOK、それ以上であれば指定された文字列を出力するという問題。

考え方とコード

for文で1から順番にmとの大小を判定して出力するとしました。

n,m = map(int,input().split())

for i in range(1,n+1):
    if i <= m:
        print("OK")
    else:
        print("Too Many Requests")

B - N-1 -

問題

与えられた整数列Aから要素を1つ除去して、与えられた整数Mになるかどうかを判定する問題。

考え方とコード

整数列Aの合計をまず計算し、Aの要素を順番に1つピックアップして、合計から引いた値がMになるかを判定するようにしました。

n,m = map(int,input().split())
a = [int(x) for x in input().split()]
s = sum(a)
ans = False
for i in a:
    if s-i == m:
        ans = True
        break
    
print("Yes" if ans else "No")

ではでは。

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?