セイレンチュウ..

AtCoder ABC140

概要

AtCoderの記録です。全部Pythonで頑張ります。
E,Fは解いてないです。

この記事の対象

  • AtCoderについてある程度知っている人
  • Pythonがある程度読める人



本編

AtCoderとは

競技プログラミングコンテストを開催している会社です。 atcoder.jp

ABC140

院試が終わったので久しぶりの参加です。

A Password

f:id:alumi-tan:20190909012308p:plain

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

B Buffet

f:id:alumi-tan:20190909012414p:plain

Bにしては少しややこしい問題でした。

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

befo = -100
sat = 0
for i in range(N):
    index = A[i] - 1
    sat += B[index]
    if befo + 1 == index:
        sat += C[befo]
    befo = index

print(sat)

C Maximal Value

f:id:alumi-tan:20190909012511p:plain

合計が最大となるようにAを定めると、 A_i=\min(B_{i-1}, B_i)となります。

N = int(input())
B = list(map(int,input().split()))

A = []

for i in range(N):
    if i == 0:
        A.append(B[i])
    elif i == N-1:
        A.append(B[i-1])
    else:
        A.append(min(B[i-1],B[i]))

print(sum(A))

D Face Produces Unhappiness

f:id:alumi-tan:20190909013158p:plain

人の顔を見られないコミュ障の話(?)。
Lを←、Rを→としたとき、「…←|→…→|←…」のように仕切りを入れて反転させる部分を選ぶと、幸せな人が2人増えます。(←→、→←の順番はどちらでもいいです。)
「…←|→…→|←」「←|→…→|←…」のように一方が端っこにある場合は、幸せな人が1人増えます。

←→、→←の組はより内側から選んでいくことで他の←→、→←に干渉しません。

N,K = map(int,input().split())
S = input()

p1 = p2 = cnt = 0
for i in range(N-1):
    if S[i] == 'L' and S[i+1] == 'R':
        p1 += 1
    if S[i] == 'R' and S[i+1] == 'L':
        p2 += 1
    if S[i] == 'R' and S[i+1] == 'R':
        cnt += 1
    if S[i] == 'L' and S[i+1] == 'L':
        cnt += 1

a1 = min(p1,p2,K)
ans = a1*2 + cnt
if K > a1:
    a2 = min(max(p1,p2)-a1,K-a1)
    ans += a2

print(ans)

まとめ

院試も無事合格できて、いよいよこちらも頑張っていきたいですね! 水色くらいには載せたいなー。

f:id:alumi-tan:20190909013645p:plain