Quantcast
Channel: 初心者タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 21105

Pythonで毎日AtCoder #16

$
0
0

はじめに

前回
今日もCです。今日で例題は終わりです。

#16

考えたこと
ABC049-C
ぜんぜん分からなかったので、解説を見ました。ふむふむ、文字列を逆にすればerの区別しなくていいのか。
文字列を逆にしたあとは、ひたすらif文にしてます。

s=str(input())s=''.join(list(reversed(s)))t=0whilet<=len(s):ifs[t:t+5]=='maerd':t+=5continueelifs[t:t+7]=='remaerd':t+=7continueelifs[t:t+5]=='esare':t+=5continueelifs[t:t+6]=='resare':t+=6continueelift==len(s):print('YES')quit()else:breakprint('NO')

Python3 → 33ms
PyPy3 → 189ms
スライス処理はPyPyよりもPythonの方が早い?


ABC086-C
(0,0)から(x,y)に移動するときに必要なマンハッタン距離?をdとすると、t>=dなら時間内に到着できます。また、(d - t) % 2 == 0ならば、t未満で到着しても隣りのマスと目的のマスを往復できるので、t時に到着可能です。

n=int(input())l=[list(map(int,input().split()))for_inrange(n)]foriinrange(n):t=l[i][0]x=l[i][1]y=l[i][2]d=x+yifd<=tand(d-t)%2==0:continueelse:print('No')quit()print('Yes')

Python3 → 369ms
PyPy3 → 585ms

まとめ

今回で例題は全部解いたので、次回からは類題を解いていきます!
では、また


Viewing all articles
Browse latest Browse all 21105

Trending Articles