AtCoder Beginner Contest 082/AtCoder Regular Contest 087
はい。
https://atcoder.jp/contests/abc082
A - Round Up the Mean
PyPy3
a,b=map(int,input().split()) print((a+b+1)//2)
a+b繰り上げになるように割り算、(a+b+2-1) が (a+b+1) になってます。
B - Two Anagrams
PyPy3
s=list(input()) t=list(input()) s.sort() t.sort(reverse=True) w="".join(s) v="".join(t) ans=[w,v] ans.sort() print("Yes" if (ans[0]==w and w!=v) else "No")
ソートできるようにlist()する。sは昇順、tは降順ソートして、join()で文字列にして調べる。文字列が辞書順で比較できることを祈ります。
C - Good Sequence
PyPy3
import collections n=int(input()) a=[int(i) for i in input().split()] x=collections.Counter(a) ans=0 for i in x: if x[i]!=i: ans+=[x[i],x[i]-i][x[i]>i] print(ans)
Counter()で個数を数えました。個数を数えたら丁度x個より多いものはx個になるように、少ないものは全て除きます。
D - FT Robot
PyPy3
s=input() x,y=map(int,input().split()) xx,yy=[],[] w=[0,0] ans=chk=f=0 for i in s: if f==1 and i=='F': chk+=1 elif f==1 and i=='T': yy.append(chk) f=0 elif f==0 and i=='F': chk+=1 elif f==0 and i=='T': xx.append(chk) f=1 if i=='T': chk=0 if chk and f==1: yy.append(chk) elif chk and f==0: xx.append(chk) if s[0]=='F': w[0]+=xx[0] xx[0]=0 xx.sort() yy.sort() for i in xx[::-1]: if w[0]<x: w[0]+=i else: w[0]-=i for i in yy[::-1]: if w[1]<y: w[1]+=i else: w[1]-=i print("Yes" if w[0]==x and w[1]==y else "No")
なんか嘘解法くさい気がします。T区切りでX方向の移動か、Y方向の移動のFであるかが変わります。
T区切りで連続したFの個数を数えてX用とY用のそれぞれのリストに入れておきます。
文字列sがF始まりの場合は最初のFの分だけ初期位置をずらします。ずらしたらX用に入れてある値も0にしておきます。
X用とY用をそれぞれソートして大きい値から使います。
ゴールより現在の座標が小さければ足す、大きければ引く。等しい時は足す引くどちらでACになるっぽいです。
公式解説でも検索で見つかるblogでもDPで求める解法らしいので上記のコレは嘘くさい気がします。よくわかりませぬ。