AtCoder Regular Contest 031
はい。
https://atcoder.jp/contests/arc031
A - 名前
PyPy3
s=input() print("YES" if s==s[::-1] else "NO")
前から読んでも後ろから読んでもなので反転させて比較します。
B - 埋め立て
PyPy3
xy=[(1,0),(-1,0),(0,1),(0,-1)] w=[] for i in range(10): w.append(input()) l=set() cnt=0 for h in range(100): i=h//10 j=h%10 if w[i][j]=="o" and (i,j) not in l: cnt+=1 chk=set() m=set([(i,j)]) while len(m): y,x=m.pop() for a,b in xy: a,b=a+y,b+x if a<0 or a>9 or b<0 or b>9: continue elif w[a][b]=="o" and (a,b) not in l: m.add((a,b)) l.add((a,b)) elif w[a][b]=="x" and (a,b) not in chk: chk.add((a,b)) if cnt==1: ans=chk else: ans&=chk if cnt==1 or len(ans)>0: print("YES") else: print("NO")
座標0,0から見ていってoがあったら繋がっているoを全部調べる。それと1マス外をとりあえずset型に入れてメモ。また次のoがあったら繋がり全部と1マス外を調べる。繰り返し続けていってoが一繋がりしかない場合か、全てに共通する1マス外があればそのマスが1マスだけ陸地にして全体を1つになのでYESになる。そうでなければNOにしました。