LoginSignup
0
0

More than 3 years have passed since last update.

はじめに

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

#16

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

s = str(input())
s = ''.join(list(reversed(s)))

t = 0
while t <= len(s):
    if s[t:t+5] == 'maerd':
        t += 5
        continue
    elif s[t:t+7] == 'remaerd':
        t += 7
        continue
    elif s[t:t+5] == 'esare':
        t += 5
        continue
    elif s[t:t+6] == 'resare':
        t += 6
        continue
    elif t == len(s):
        print('YES')
        quit()
    else:
        break
print('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 _ in range(n)]

for i in range(n):
    t = l[i][0]
    x = l[i][1]
    y = l[i][2]
    d = x + y
    if d <= t and (d - t) % 2 == 0:
        continue
    else:
        print('No')
        quit()
print('Yes')

Python3 → 369ms
PyPy3 → 585ms

まとめ

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

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