Problem:


Score : 300 points

Problem Statement

AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.

If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1).
Note that he cannot stay at his place.
Determine whether he can carry out his plan.

Constraints

1 ≤ N ≤ 10^5

0 ≤ x_i ≤ 10^5

0 ≤ y_i ≤ 10^5

1 ≤ t_i ≤ 10^5

t_i < t_{i+1} (1 ≤ i ≤ N-1)

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
t_1 x_1 y_1
t_2 x_2 y_2
:
t_N x_N y_N

Output

If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

Sample Input 1

2
3 1 2
6 1 1

Sample Output 1

Yes

For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).

Sample Input 2

1
2 100 100

Sample Output 2

No

It is impossible to be at (100,100) two seconds after being at (0,0).

Sample Input 3

2
5 1 1
100 1 1

Sample Output 3

No



Sample input:
2
3 1 2
6 1 1


Sample output:
Yes

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def compare(x):
  return x[0]


def find(x, lst):
  for value in lst:
    if value[0] == x:
      return True
  return False


n = int(input())
lst = [[0, 0, 0]]
for i in range(n):
  lst.append(list(map(int, input().split())))
lst.sort(key=compare)
x = lst[len(lst) - 1][0]
for i in range(1, x):
  if not find(i, lst):
    lst.append([i, -1, -1])
lst.sort(key=compare)

points = [[0, 0]]
flg = False
try:
  for i in range(1, x + 1):
    fix = False
    wk = []
    for j in range(len(points)):
      wk.append((points[j][0] + 1, points[j][1]))
      wk.append((points[j][0] - 1, points[j][1]))
      wk.append((points[j][0], points[j][1] + 1))
      wk.append((points[j][0], points[j][1] - 1))

      ps = (lst[i][1], lst[i][2])
      x = points[j][0]
      y = points[j][1]
      if (i == lst[i][0]) and (x >= 0) and (y >= 0) and ((x + 1, y) == ps or (x - 1, y) == ps or (x, y + 1) == ps or (x, y - 1) == ps):
        flg = True
        wk = [ps]
        break
    points = list(set(wk))
    if (i == lst[i][0]) and (lst[i][1] >= 0) and (not flg):
      break
finally:
  print('Yes') if flg else print('No')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
TXY=[list(map(int,input().split())) for i in range(N)]

Next=TXY.pop(0)
Flag=1

for i in range(N):
#    print(Next)
    D=Next[0]-abs(Next[1])-abs(Next[2])
    if D<0 or D%2!=0:
        Flag=0
        break
    else:
        if TXY==[]:
            break
        else:
            Next2=TXY.pop(0)
            Next=[Next2[0]-Next[0],Next2[1]-Next[1],Next2[2]-Next[2]]

print(['No','Yes'][Flag])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
t = x = y = [0]
for i in range(N):
  tn,xn,yn = map(int,input().split())
  t = t+[tn]
  x = x+[xn]
  y = y+[yn]
  dt = t[i+1]-t[i]
  d = abs(x[i+1]-x[i])+abs(y[i+1]-y[i])
  if d <= dt and dt%2 == d%2:
    isValid = True
  else:
    isValid = False
    break
print("Yes" if isValid else "No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
txy = [list(map(int, input().split())) for _ in range(N)]

result = True

for pol in txy:
    
    if(abs(pol[1]) + abs(pol[2]) not in list(range(pol[0], -1, -2))):
        result = False

print(("No", "Yes")[result])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())

status = np.zeros((n + 1, 3), dtype=np.int)
for i in range(n):
    status[i + 1, :] = list(map(int, input().split()))

diffs = np.diff(status, axis=0)
answer = 'Yes'
for i in range(n):
    sum_step = np.sum(diffs[i, 1:])
    time = diffs[i, 0]
    if sum_step > time or sum_step % 2 != time % 2:
        answer = 'No'
        break
print(answer)

Submission status: Time Limit Exceeded

Solution code:

#入力受け取り
n = int(input())
tourList = []
for i in range(n):
    array = list(map(int, input().strip().split()))
    tourList.append(array)

#DebugPrint

currentTime = 0
currentX = 0
currentY = 0

loop=0

for i in range(len(tourList)) :
    Time = tourList[i][0]
    X = tourList[i][1]
    Y = tourList[i][2]

    Time = Time - currentTime
    X = X - currentX
    Y = Y - currentY
    flag=False
    Z=0 #往復調整用    
    while (X+Y+Z) <= Time :
        if X+Y+Z == Time:
            flag=True
            break
        else:
            Z+=2
    
    #継続判定
    if flag == False:
        print("No")
        exit()
    
    currentTime = Time
    currentX = X
    currentY = Y

print("Yes")

    #最初の点がまず実現可能か

Submission status: Time Limit Exceeded

Solution code:
import sys

default_x = 0
default_y = 0

n = int(input())

a = []

#標準入力をN分読み込み
for i in range(n):
        a.append(list(map(int,input().split())))

times = 0
for i in range(n):
    for j in range(a[i][0]+times):
        if default_x < a[i][1]:
            default_x += 1
        elif default_x > a[i][1]:
            default_x -= 1

        elif default_y < a[i][2]:
            default_y += 1
        elif default_y > a[i][2]:
            default_y -= 1
        else:
            default_y -= 1

    if default_x != a[i][1] or default_y != a[i][2]:
        print('No')
        sys.exit()

    times  = a[i][0]

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())

for i in range(N):
	t, x, y = map(int, input().split(" "))
	if x > 0 and t >= x:
		t = t - x
		x = 0
		for j in range(t):
			if y >= 0:
				y -=1               
			else:
				y +=1
	elif x < 0 and t >= x * (-1):
		t = t -(-1 * x)
		x = 0      
		for j in range(t):
			if y >= 0:
				y -=1               
			else:
				y +=1
	else:
		for j in range(t):
			if y >= 0:
				y -=1               
			else:
				y +=1
	if x != 0 or y !=0:
		print("No")
		sys.exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys


# 最短で向かう、余ったら時間をつぶす
def is_possible(p_t, p_x, p_y, point):

    # まず最短で向かう
    while p_x != point[1]:
        if p_x < point[1]:
            p_x += 1
        if p_x > point[1]:
            p_x -= 1
        p_t +=1
        
    while p_y != point[2]:
        if p_y < point[2]:
            p_y += 1
        if p_y > point[2]:
            p_y -= 1
        p_t +=1

    # 時間が余ったら、暇をつぶす
    while p_t < point[0]:        
        if p_t % 2 == 0:
            p_x += 1
            p_t += 1
        else:
            p_x -= 1
            p_t += 1
            
    # pointに到着できたらTrue    
    if ((p_t == point[0]) &
        (p_x == point[1]) &
        (p_y == point[2])):
        return True
    else:
        return False

# main
size = int(input())
points = [0]*size
for i in range(0, size):
    points[i] = list(map(int, input().split()))

p_t = 0
p_x = 0
p_y = 0

for p in points:
    if is_possible(p_t, p_x, p_y, p):
        continue
    else:
        print('No')
        sys.exit()

print('Yes')
sys.exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
txy = [list(map(int,input().split())) for i in range(N)]
t = [txy[i][0] for i in range(N)]
x = [txy[i][1] for i in range(N)]
y = [txy[i][2] for i in range(N)]
ans = 0
cnt = 0
for i in range(t[N-1]+1):
    if i+1 in t:
        if (x[cnt]+y[cnt])%2 == (i+1)%2 and x[cnt]+y[cnt] <= i+1:
            ans += 1
        cnt += 1
print("Yes" if ans == N else "No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        for b in range(t - pre_t + 1 - a):
            if pre_x + a - b == x:
                for c in range(t - pre_t + 1  - a - b):
                    d = t - pre_t - a - b - c
                    if pre_y + c - d == y:
                        count += 1
                        flag = True
                        break
            if flag:
                break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        for b in range(t- pre_t + 1 - a):
            for c in range(t - pre_t + 1  - a - b):
                d = t - pre_t - a - b - c
                if pre_x + a - b == x and pre_y + c - d == y:
                    count += 1
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import copy

class State():
    def __init__(self):
        self.t = 0
        self.pos = [0,0]

def search(player,plan):
    t = plan.t - player.t

    # print("player t:",player.t,", pos:",player.pos)
    # print("plan t:",plan.t,", pos:",plan.pos)
    # print("t: ",t)

    trials = []
    for i in range(t+1):
        for j in range(t+1-i):
            for k in range(t+1-i-j):
                l=t-i-j-k
                trial = [i,j,k,l]
                trials.append(trial)

    for trial in trials:
        tmp_pos = copy.deepcopy(player.pos)
        for i in range(trial[0]):
            tmp_pos[0] += 1
        for i in range(trial[1]):
            tmp_pos[0] -= 1
        for i in range(trial[2]):
            tmp_pos[1] += 1
        for i in range(trial[3]):
            tmp_pos[1] -= 1

        if tmp_pos == plan.pos:
            return True

    return False


if __name__ == '__main__':
    N = input()
    N = int(N)
    plans = []
    for i in range(N):
        plan = State()
        inData = input()
        t = int(inData.split()[0])
        x = int(inData.split()[1])
        y = int(inData.split()[2])
        plan.t = t
        plan.pos = [x,y]
        plans.append(plan)

    player = State()
    for plan in plans:
        if search(player,plan):
            player.t = plan.t
            player.pos = copy.deepcopy(plan.pos)
        else:
            print("No")
            break
    else:
        print("Yes")

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import copy

class State():
    def __init__(self):
        self.t = 0
        self.pos = [0,0]

def search(player,plan):
    t = plan.t - player.t

    # print("player t:",player.t,", pos:",player.pos)
    # print("plan t:",plan.t,", pos:",plan.pos)
    # print("t: ",t)

    trials = []
    for i in range(t+1):
        for j in range(t+1-i):
            for k in range(t+1-i-j):
                l=t-i-j-k
                trial = [i,j,k,l]
                trials.append(trial)

    for trial in trials:
        tmp_pos = copy.deepcopy(player.pos)
        for i in range(trial[0]):
            tmp_pos[0] += 1
        for i in range(trial[1]):
            tmp_pos[0] -= 1
        for i in range(trial[2]):
            tmp_pos[1] += 1
        for i in range(trial[3]):
            tmp_pos[1] -= 1

        if tmp_pos == plan.pos:
            return True

    return False


if __name__ == '__main__':
    N = input()
    N = int(N)
    plans = []
    for i in range(N):
        plan = State()
        inData = input()
        t = int(inData.split()[0])
        x = int(inData.split()[1])
        y = int(inData.split()[2])
        plan.t = t
        plan.pos = [x,y]
        plans.append(plan)

    player = State()
    for plan in plans:
        if search(player,plan):
            player.t = plan.t
            player.pos = copy.deepcopy(plan.pos)
        else:
            print("No")
            break
    else:
        print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import copy

N = int(input())
txy = {}
for i in range(N):
    t, x, y = list(map(int, input().split(' ')))
    txy[t] = [x, y]

src_t = 0
src_x = 0
src_y = 0

success = True

for t, xy in txy.items():
    dest_t = t
    dest_x = xy[0]
    dest_y = xy[1]

    before = [[src_x, src_y]]
    after = []
    for i in range(src_t, dest_t):
        after.clear()
        for before_x, before_y in before:
            after.append([before_x + 1, before_y])
            after.append([before_x - 1, before_y])
            after.append([before_x, before_y + 1])
            after.append([before_x, before_y - 1])
        before = copy.deepcopy(after)

    if [dest_x, dest_y] in after:
        src_t = dest_t
        src_x = dest_x
        src_y = dest_y
        continue
    else:
        success = False
        break

if success:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
t = [0] * n
x = [0] * n
y = [0] * n
for i in range(n):
    t[i],x[i],y[i] = map(int,input().split())

def travel(x,y,t):
    if t == t_st:
        if x == x_st and y == y_st:
            return True
        else:
            return False
    if travel(x-1,y,t-1) or travel(x,y-1,t-1) or travel(x+1,y,t-1) or travel(x,y+1,t-1):
        return True
    else:
        return False

t_st = 0
x_st = 0
y_st = 0

ans = travel(x[0],y[0],t[0])

for i in range(1,n):
    x_st = x[i-1]
    y_st = y[i-1]
    t_st = t[i-1]
    if travel(x[i],y[i],t[i]):
        pass
    else:
        ans = False

if ans:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
result = True

for _ in range(N):
    a = list(map(int, input().split()))
    
    if(abs(a[1]) + abs(a[2]) not in list(range(a[0] + 1))[a[0] % 2 == 1: : 2]):
        result = False
    
print(('No', 'Yes')[result])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
result = True

for a in A:
    
    if(a[0] % 2 == 0):
        
        if(abs(a[1]) + abs(a[2]) in list(range(a[0] + 1))[0: : 2]):
            result = result and True
        
        else:
            result = False
    
    else:
        if(abs(a[1]) + abs(a[2]) in list(range(a[0] + 1))[1: : 2]):
            result = result and True
        
        else:
            result = False

print(('No', 'Yes')[result])

Submission status: Time Limit Exceeded

Solution code:
def travel(x,y,t):
    for i in range(t):
        if x+y==t-2*i:
            return True
    return False
n=int(input())
for i in range(n):
    t, x, y = [int(j) for j in input().split() ]
    if not travel(x,y,t):
        print("No")
        exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())
TXY = [
    tuple(map(int, sys.stdin.readline().split())) for _ in range(N)
]

def check(st, sx, sy, et, ex, ey):
    if abs(sx - ex) + abs(sy - ey) > et - st:
        return False
    points = [(sx, sy)]
    for _ in range(et - st):
        new_points = set()
        for px, py in points:
            new_points.add((px + 1, py))
            new_points.add((px - 1, py))
            new_points.add((px, py + 1))
            new_points.add((px, py - 1))
        points = list(new_points)
    if (ex, ey) in points:
        return True
    return False


def main():
    TXY.insert(0, (0, 0, 0))
    for i in range(len(TXY) - 1):
        args = TXY[i] + TXY[i + 1]
        if not check(*args):
            print('No')
            return
    print('Yes')

main()

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(sys.stdin.readline())
TXY = [
    tuple(map(int, sys.stdin.readline().split())) for _ in range(N)
]

def check(st, sx, sy, et, ex, ey):
    points = [(sx, sy)]
    for _ in range(et - st):
        new_points = set()
        for px, py in points:
            new_points.add((px + 1, py))
            new_points.add((px - 1, py))
            new_points.add((px, py + 1))
            new_points.add((px, py - 1))
        points = list(new_points)
    if (ex, ey) in points:
        return True
    return False


def main():
    TXY.insert(0, (0, 0, 0))
    for i in range(len(TXY) - 1):
        args = TXY[i] + TXY[i + 1]
        if not check(*args):
            print('No')
            return
    print('Yes')

main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tt = 0
xx = 0
yy = 0
flag = True
z = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
    t, x, y = z[i]
    s = [[xx, yy]]
    for j in range(t - tt):
        ss = []
        for k in range(len(s)):
            ss.append([s[k][0] + 1, s[k][1]])
            ss.append([s[k][0] - 1, s[k][1]])
            ss.append([s[k][0], s[k][1] + 1])
            ss.append([s[k][0], s[k][1] - 1])
        s = ss
    if [x, y] in s:
        tt = t
        xx = x
        yy = y
    else:
        print('No')
        exit()
print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = [0 for _ in range(n+1)]
x = [0 for _ in range(n+1)]
y = [0 for _ in range(n+1)]
for i in range(n):
    t[i+1], x[i+1], y[i+1] = [int(z) for z in input().split()]
    # print(t,x,y)
dt = [t[i+1] - t[i] for i in range(n)]
dist = [abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]) for i in range(n)]
# print(dt, dist)
result = True

while result:
    for i in range(n):
        if not dt > dist and (t[i] % 2 != (abs(x[i])+abs(y[i])) % 2):
            result = False

if result:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
def test():
    n = int(input())
    t = [0 for _ in range(n+1)]
    x = [0 for _ in range(n+1)]
    y = [0 for _ in range(n+1)]
    for i in range(n):
        t[i+1], x[i+1], y[i+1] = [int(z) for z in input().split()]
        # print(t,x,y)
    dt = [t[i+1] - t[i] for i in range(n)]
    dist = [abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]) for i in range(n)]
    # print(dt, dist)
    result = "Yes"

    for i in range(len(t)):
        if not t[i] % 2 == (abs(x[i])+abs(y[i])) % 2:
            result = "No"

    for i in range(len(dt)):
        if dt < dist:
            result = "No"

    print(result)


test()

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
travel = [map(int, raw_input().split()) for i in range(n)]

accessible_now = [(0,0)]
limit = 1e5 + 1

stroke = 0
for target in travel:
  t, x, y = target
  while (stroke<t):
    stroke += 1
    accessible_next = [] 
    for loc in accessible_now:
      for step in [(1,0),(0,1),(-1,0),(0,-1)]:
        loc_next = (loc[0]+step[0],loc[1]+step[1])
        if ((-1 in loc_next) or (limit in loc_next)):
          continue
        if (loc_next in accessible_next):
          continue
        accessible_next.append(loc_next)
    accessible_now = accessible_next
    #print stroke, t, accessible_now
    if (stroke == t):
      if ((x,y) in accessible_now):
        accessible_now = [(x,y)]
        continue
      else:
        print 'No'
        exit(0) 
res = 'Yes' if (stroke==t) else 'No'
print res

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
travel = [map(int, raw_input().split()) for i in range(n)]

accessible_now = [(0,0)]
limit = 1e5 + 1

stroke = 0
for target in travel:
  t, x, y = target
  while (stroke<t):
    stroke += 1
    accessible_next = [] 
    for loc in accessible_now:
      for step in [(1,0),(0,1),(-1,0),(0,-1)]:
        loc_next = (loc[0]+step[0],loc[1]+step[1])
        if ((-1 in loc_next) or (limit in loc_next)):
          continue
        if (loc_next in accessible_next):
          continue
        accessible_next.append(loc_next)
    accessible_now = accessible_next
    #print stroke, t, accessible_now
    if (stroke == t):
      if ((x,y) in accessible_now):
        continue
      else:
        print 'No'
        exit(0) 
res = 'Yes' if (stroke==t) else 'No'
print res

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
G=[None for i in range(n)]
res = True

def dps(d):
    global res
    P=[0,0,0]   
    for i in range(d):
        if G[i] != None:
            gt,gx,gy = G[i]
            pt,px, py = P
            if (gt-pt) >= (gx-px + gy-py):
                if (gt-pt - (gx-px + gy-py))%2 == 0:
                    res &=  True
                else:
                    res = False
                    break
            else:
                res = False
                break
            P=G[i]
        else:
            res &= True

for i in range(n):
    G[i] = list(map(int,input().split()))
    dps(i+1)
    if res == False:
        break

        
print('Yes' if res==True else 'No')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
G=[None for i in range(n)]
res = True

def dps(d):
    global res
    P=[0,0,0]   #Pはt,x,yのリスト
    for i in range(d):
        if G[i] != None:
            gt,gx,gy = G[i]
            pt,px, py = P
            if (gt-pt) >= (gx-px + gy-py):
                if (gt-pt - (gx-px + gy-py))%2 == 0:
                    res &=  True
                else:
                    res = False
                    break
            else:
                res = False
                break
            P=G[i]
        else:
            res &= True
            
    

for i in range(n):
    t,x,y = map(int,input().split())
    if G[i]==None:
        G[i] = []
        G[i].append(t)
        G[i].append(x)
        G[i].append(y)
        dps(i+1)
    elif G[i]==[t,x,y]:
        dps(i+1)
    else:
        res == False
        break
    if res == False:
        break

        
print('Yes' if res==True else 'No')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
G=[None for i in range(n)]
res = True

def dps(d):
    global res
    P=[0,0,0]   #Pはt,x,yのリスト
    for i in range(d):
        if G[i] != None:
            gt,gx,gy = G[i]
            pt,px, py = P
            if (gt-pt) >= (gx-px + gy-py):
                if (gt-pt - (gx-px + gy-py))%2 == 0:
                    res &=  True
                else:
                    res = False
                    break
            else:
                res = False
                break
            P=G[i]
        else:
            res &= True
            
    

for i in range(n):
    t,x,y = map(int,input().split())
    if G[i]==None:
        G[i] = []
        G[i].append(t)
        G[i].append(x)
        G[i].append(y)
        dps(i+1)
    elif G[i]==[t,x,y]:
        dps(i+1)
    else:
        res == False
        break

        
print('Yes' if res==True else 'No')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    N = int(input())
    dic = {}
    queue = [(0,0)]
    time = 0
    maxTime = float('-inf')
    flag = True
    for tmp in range(N):
        t, x, y = map(int, input().split())
        dic[t] = (x, y)
        maxTime = max(maxTime, t)

    while time < maxTime and flag:
        time += 1
        factor = []

        for tmp in queue:
            x = tmp[0]
            y = tmp[1]
            if time in dic:
                if dic[time] == (x+1,y) or dic[time] == (x-1,y) or dic[time] == (x,y+1) or dic[time] == (x,y-1):
                    factor.append(dic[time])
            else:
                factor.append((x+1,y))
                factor.append((x-1,y))
                factor.append((x,y+1))
                factor.append((x,y-1))
        else:
            factor = list(set(factor))

        if time in dic and len(factor) == 0:
            flag = False

        queue = factor
    else:
        if flag:
            print("Yes")
        else:
            print("No")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-

if __name__ == "__main__":
    N = int(input())
    dic = {}
    queue = [(0,0)]
    time = 0
    maxTime = float('-inf')
    flag = True
    for tmp in range(N):
        t, x, y = map(int, input().split())
        dic[t] = (x, y)
        maxTime = max(maxTime, t)

    while time < maxTime and flag:
        time += 1
        factor = []

        for tmp in queue:
            x = tmp[0]
            y = tmp[1]
            factor.append((x+1,y))
            factor.append((x-1,y))
            factor.append((x,y+1))
            factor.append((x,y-1))
        else:
            factor = list(set(factor))

        if time in dic and dic[time] not in factor:
            flag = False

        queue = factor
    else:
        if flag:
            print("Yes")
        else:
            print("No")

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

option = {(0, 0)}


def main():
    global option
    last_list = [0, 0, 0]
    N = int(input())
    for i in range(N):
        this_list = list(map(int, input().split()))
        add_option(this_list[0] - last_list[0], (this_list[1], this_list[2]))
        if (this_list[1], this_list[2]) not in option:
            print('No')
            return
        option = {(this_list[1], this_list[2])}
        last_list = this_list
    print('Yes')


def add_option(step, this_postion):
    global option
    xi, yi = this_postion
    for i in range(step):
        temp_option = set()
        rest = step - i
        for position in option:
            x, y = position
            diff = abs(x - xi) + abs(y - yi)
            if rest % 2 != diff % 2:
                continue
            if diff > rest:
                continue
            if x < 100000:
                temp_option.add((x + 1, y))
            if y < 100000:
                temp_option.add((x, y + 1))
            if x > 0:
                temp_option.add((x - 1, y))
            if y > 0:
                temp_option.add((x, y - 1))
        option = temp_option


main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

option = {(0, 0)}


def main():
    global option
    last_list = [0, 0, 0]
    N = int(input())
    for i in range(N):
        this_list = list(map(int, input().split()))
        add_option(this_list[0] - last_list[0], (this_list[1], this_list[2]))
        if (this_list[1], this_list[2]) not in option:
            print('No')
            return
        option = {(this_list[1], this_list[2])}
        last_list = this_list
    print('Yes')


def add_option(step, this_postion):
    global option
    xi, yi = this_postion
    for i in range(step):
        temp_option = set()
        for position in option:
            x, y = position
            diff = abs(x - xi) + abs(y - yi)
            rest = step - i
            if diff > rest:
                continue
            if x < 100000:
                temp_option.add((x + 1, y))
            if y < 100000:
                temp_option.add((x, y + 1))
            if x > 0:
                temp_option.add((x - 1, y))
            if y > 0:
                temp_option.add((x, y - 1))
        option = temp_option


main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

option = {(0, 0)}


def main():
    global option
    last_list = [0, 0, 0]
    N = int(input())
    for i in range(N):
        this_list = list(map(int, input().split()))
        add_option(this_list[0] - last_list[0])
        if (this_list[1], this_list[2]) not in option:
            print('No')
            return
        option = {(this_list[1], this_list[2])}
        last_list = this_list
    print('Yes')


def add_option(step):
    global option
    for i in range(step):
        temp_option = set()
        for position in option:
            x, y = position
            if x < 100000:
                temp_option.add((x + 1, y))
            if y < 100000:
                temp_option.add((x, y + 1))
            if x > 0:
                temp_option.add((x - 1, y))
            if y > 0:
                temp_option.add((x, y - 1))
        option = temp_option


main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

option = {(0, 0)}


def main():
    global option
    last_list = [0, 0, 0]
    N = int(input())
    for i in range(N):
        this_list = list(map(int, input().split()))
        add_option(this_list[0] - last_list[0])
        if (this_list[1], this_list[2]) not in option:
            print('No')
            return
        option = {(this_list[1], this_list[2])}
        last_list = this_list
    print('Yes')


def add_option(step):
    global option
    for i in range(step):
        temp_option = set()
        for position in option:
            x, y = position
            temp_option.add((x + 1, y))
            temp_option.add((x, y + 1))
            if x > 0:
                temp_option.add((x - 1, y))
            if y > 0:
                temp_option.add((x, y - 1))
        option = temp_option


main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

option = {(0, 0)}


def main():
    global option
    last_list = [0, 0, 0]
    N = int(input())
    for i in range(N):
        this_list = list(map(int, input().split()))
        add_option(this_list[0] - last_list[0])
        if (this_list[1], this_list[2]) not in option:
            print('No')
            return
        last_list = this_list
    print('Yes')


def add_option(step):
    global option
    for i in range(step):
        temp_option = set()
        for position in option:
            x, y = position
            temp_option.add((x + 1, y))
            temp_option.add((x, y + 1))
            if x > 0:
                temp_option.add((x - 1, y))
            if y > 0:
                temp_option.add((x, y - 1))
        option = temp_option


main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def check(t,x,y,nt,nx,ny):
    # print(t)
    # print(x)
    # print(y)
    tempt = nt
    tempx = nx
    tempy = ny
    judge = True
    if (x+y) > (nx+ny+t):
        print("No")
        sys.exit()
    #x方向の移動
    while x != tempx:
        if (x>tempx):
            tempx += 1
            tempt += 1
        elif(x<tempx):
            tempx -= 1
            tempt += 1
    #y方向の移動
    if tempt<=t:
        while y != tempy:
            if (y>tempy):
                tempy += 1
                tempt += 1
            elif(x<tempy):
                tempy -= 1
                tempt += 1
    else:
        print("No")
        sys.exit()
    if (t-tempt)%2 != 0:
        print("No")
        sys.exit()     

    return tempt,tempx,tempy
N = int(input())
nt = 0
nx = 0
ny = 0
t = []
x = []
y = []
#入力
for i in range(N):
    temp = input().split(" ")
    t.append(temp[0])
    x.append(temp[1])
    y.append(temp[2])

for i in range(N):
    nt,nx,ny = check(int(t[i]), int(x[i]), int(y[i]),nt,nx,ny)

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
def check(t,x,y,nt,nx,ny):
    # print(t)
    # print(x)
    # print(y)
    tempt = nt
    tempx = nx
    tempy = ny
    judge = True
    if (x+y) > (nx+ny+t):
        print("No")
        sys.exit()
    #x方向の移動
    while x != tempx:
        if (x>tempx):
            tempx += 1
            tempt += 1
        elif(x<tempx):
            tempx -= 1
            tempt += 1
    #y方向の移動
    if tempt<=t:
        while y != tempy:
            if (y>tempy):
                tempy += 1
                tempt += 1
            elif(x<tempy):
                tempy -= 1
                tempt += 1
    else:
        print("No")
        sys.exit()
    if (t-tempt)%2 != 0:
        print("No")
        sys.exit()     

    return tempt,tempx,tempy
N = int(input())
nt = 0
nx = 0
ny = 0
t = []
x = []
y = []
#入力
for i in range(N):
    temp = input().split(" ")
    t.append(temp[0])
    x.append(temp[1])
    y.append(temp[2])

for i in range(N):
    na,nb,nc = check(int(t[i]), int(x[i]), int(y[i]),nt,nx,ny)

print("Yes")