LoginSignup
0
0

More than 3 years have passed since last update.

はじめに

前回
今日はABC140の問題を解きました。50分でA~Cでした。

A問題

問題 0diff

考えたこと
3桁のパスワードなので使える数字の3乗を出力すればいい。

n = int(input())
print(n**3)

B問題

問題 58diff

考えたこと
for文とif文で計算するだけ。リストの要素とindexが混ざらないように気を付ければいい

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
f = 10**9
for i in range(n):
    ans += b[a[i]-1]
    if a[i] - f == 1:
        ans += c[a[i-1]-1]
    f = a[i]
print(ans)

C問題

問題 136diff

考えたこと
$A$の要素の合計値が最大になるのは$B$から与えられる$A$の要素が最大になるときである。最大になるのは、$a[0]$が$b[0]$と同じ値、$a[-1]$が$b[-1]$と同じ値になるとき。それ以外の$A$はmin(b[i-1],b[i])で決定する。

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
f = 10**9
for i in range(n):
    ans += b[a[i]-1]
    if a[i] - f == 1:
        ans += c[a[i-1]-1]
    f = a[i]
print(ans)

まとめ

D(1110diff)は解けませんでした。Cもdiffの割に苦戦したのが悔しい。ではまた。おやすみなさい。

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