Problem:


Score : 700 points

Problem Statement

There is a circle with a circumference of L.
Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point.
On this circumference, there are N ants.
These ants are numbered 1 through N in order of increasing coordinate, and ant i is at coordinate X_i.

The N ants have just started walking.
For each ant i, you are given the initial direction W_i. Ant i is initially walking clockwise if W_i is 1; counterclockwise if W_i is 2.
Every ant walks at a constant speed of 1 per second.
Sometimes, two ants bump into each other.
Each of these two ants will then turn around and start walking in the opposite direction.

For each ant, find its position after T seconds.

Constraints

All input values are integers.

1 \leq N \leq 10^5

1 \leq L \leq 10^9

1 \leq T \leq 10^9

0 \leq X_1 < X_2 < ... < X_N \leq L - 1

1 \leq W_i \leq 2

Input

The input is given from Standard Input in the following format:

N L T
X_1 W_1
X_2 W_2
:
X_N W_N

Output

Print N lines.
The i-th line should contain the coordinate of ant i after T seconds. Here, each coordinate must be between 0 and L-1, inclusive.

Sample Input 1

3 8 3
0 1
3 2
6 1

Sample Output 1

1
3
0

1.5 seconds after the ants start walking, ant 1 and 2 bump into each other at coordinate 1.5.
1 second after that, ant 1 and 3 bump into each other at coordinate 0.5.
0.5 seconds after that, that is, 3 seconds after the ants start walking, ants 1, 2 and 3 are at coordinates 1, 3 and 0, respectively.

Sample Input 2

4 20 9
7 2
9 1
12 1
18 1

Sample Output 2

7
18
18
1



Sample input:
3 8 3
0 1
3 2
6 1


Sample output:
1
3
0

Submission status: Wrong Answer

Solution code:
import numpy as np
from numpy import inf
n,l,t = list(map(int,input().split()))
x_list = list()
w_list = list()
for i in range(n):
    x, w = list(map(int,input().split()))
    x_list.append(x)
    w_list.append(w)

d_list = list()
for i in range(len(x_list)-1):
    d_list.append(x_list[i+1]-x_list[i])
d_list.append(x_list[0]+l-x_list[-1])

w_list = [w if w == 1 else -1 for w in w_list]

x_array = np.array(x_list)
w_array = np.array(w_list)
d_array = np.array(d_list)

time = 0
while time < t:
    s_list = list()
    # さが縮まるかどうか。縮まるなら1
    for i in range(len(w_list)):
        if w_array[i%n] == 1 and w_array[(i+1)%n]==-1:
            s_list.append(1)
        elif w_array[i%n] == -1 and w_array[(i+1)%n]==1:
            s_list.append(-1)
        else:
            s_list.append(0)
    s_array = np.array(s_list)
    
    # d_arrayには差が入っている。
    butukaru_array = d_array / (s_array*2)
    butukaru_array[butukaru_array == inf] = 0
    
    next_time = butukaru_array.max()
    time += next_time
    if time >= t:
        next_time -= (time-t)
    
    x_array = x_array + w_array*next_time
    d_array = d_array - s_array*2*next_time
    
    butukatta_x = np.where(d_array == 0)
    
    for i in butukatta_x:
        w_array[i] *= -1
        w_array[(i+1)%n] *= -1
    
for x in x_array:

    while x<0:
        x += l
    while x >= l:
        x -= l
        
    print(int(x))

Submission status: Wrong Answer

Solution code:
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
	if XW[i][1]==1:
		XW[i][0]+=T
	else:
		XW[i][0]-=T
	count+=math.floor(XW[i][0]/L)
"""
if XW[0][1]==1:
	for i in range(1,N):
		if XW[i][0]<XW[0][0]:
			count+=int((XW[0][0]-XW[i][0])/L)+1
else:
	for i in range(1,N):
		if XW[i][0]>XW[0][0]:
			count+=int((XW[i][0]-XW[0][0])/L)+1
"""
#print(count)
#print(len())
newX=[]
for i in range(N):
	newX.append(XW[i][0]%L)
newX.sort()
print(newX)
for i in range(N):
	print(newX[(i+count)%N]%L)

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, raw_input().split())
A = [map(int, raw_input().split()) for _ in range(N)]

P = []
for x, w in A:
    if w == 1:
        v = (x + T) % L
    else:
        v = (x - T) % L
    P.append(v)

d = T / L
p = T % L

cnt = 0
x0, w0 = A[0]
for x, w in A[1:]:
    if w != w0:
        cnt += d
        if w0 == 1:
            l = x - x0
        else:
            l = L + x0 - x
        if l <= 2 * p:
            cnt += 1

if w0 == 1:
    cnt *= -1
z = cnt % N
ans = P[z:] + P[:z]
for x in ans:
    print x

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[0 for i in range(n+1)]

for i in range(1,n+1):
    x[i],w[i]=map(int,input().split())
    if w[i]==1: ans[i]=(x[i]+t)%l
    if w[i]==2: ans[i]=(x[i]-t+l)%l

ans[0]=ans[n]
ans.pop(n)

for i in range(n): print(ans[i])

Submission status: Wrong Answer

Solution code:
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
	if XW[i][1]==1:
		XW[i][0]+=T
	else:
		XW[i][0]-=T
	count+=math.floor(XW[i][0]/L)
if XW[0][1]==1:
	for i in range(1,N):
		if XW[i][0]<XW[0][0]:
			count+=int((XW[0][0]-XW[i][0])/L)+1
else:
	for i in range(1,N):
		if XW[i][0]>XW[0][0]:
			count+=int((XW[i][0]-XW[0][0])/L)+1
#print(count)
#print(len())
for i in range(N):
	print(XW[(i+count)%N][0]%L)

Submission status: Wrong Answer

Solution code:
import math
temp=input().split()
N=int(temp[0])
L=int(temp[1])
T=int(temp[2])
XW=[[int(j) for j in input().split()] for i in range(N)]
count=0
for i in range(N):
	if XW[i][1]==1:
		XW[i][0]+=T
	else:
		XW[i][0]-=T
	count+=math.floor(XW[i][0]/L)
if XW[0][1]==1:
	for i in range(1,N):
		if XW[i][0]<XW[0][0]:
			count+=int((XW[0][0]-XW[i][0])/L)+1
else:
	for i in range(1,N):
		if XW[i][0]>XW[0][0]:
			count+=int((XW[i][0]-XW[0][0])/L)+1
print(count)
for i in range(N):
	print(XW[(i+count)%N][0]%L)

Submission status: Wrong Answer

Solution code:
import sys 
def turn(wise):
    if wise ==1 :
        return 2
    else:
        return 1
def calculate_index(n, N): 
    if n < 0:
        return n+N 
    if n > N:
        return n-N 
    return n
def min_step(Ants,N,L):
    ret = sys.maxint
    for i in xrange(N):
        j = (i+N-1) % N 
        if Ants[j][1] == 1 and Ants[i][1] == 2:
            ret = min( calculate_index(Ants[i][0] - Ants[j][0],L)/2 , ret) 
    return ret 
def runAnts(Ants,t,N,L):
    for a in Ants:
        if a[1] == 1:
            a[0] = calculate_index(a[0] + t, L)
        else:
            a[0] = calculate_index(a[0] - t, L)  
    for i in xrange(N):
        j = (i+N-1) % N 
        k = (i+1) % N 
        if Ants[i][0] == Ants[k][0] or Ants[i][0] == Ants[j][0]:
            Ants[i][1] = turn(Ants[i][1])
    return Ants

N,L,T = map(int, sys.stdin.readline().strip().split())
T = float(T)
Ants = []
for i in xrange(N):
    tmp= sys.stdin.readline().strip().split()
    Ants.append([float(tmp[0]),int(tmp[1])])
clock = float(0)
while clock < T:
    ms = min_step(Ants, N,L) #
    if T > clock + ms :
        Ants = runAnts(Ants,ms, N,L) #
        clock += ms
    else:
        Ants = runAnts(Ants,T - clock,N,L)
        clock = T 
    sys.stdin.read(1)
for i in map(lambda x: x[0], Ants):
    print int(i)

Submission status: Wrong Answer

Solution code:
N, L, T = map(int, raw_input().split(" "))
ants = []
for i in range(N):
    ants.append(map(int, raw_input().split(" ")))

for ant in ants:
    if ant[1] == 1:
        w = 1
    else:
        w = -1
    print (ant[0] + w*T) % L

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,L_in,T=[ int(r) for r in input().split(' ') if r != '' ]
data_in=np.array([[ int(r) for r in input().split(' ') if r != '' ] for _ in range(N) ])

L=L_in-1
IDX_CUR_POS=0
IDX_DIR=1
IDX_NEXT_POS=2


data=np.zeros((data_in.shape[0],3))
data[:,[IDX_CUR_POS,IDX_DIR]]=data_in
data[:,IDX_DIR]=np.where(data[:,IDX_DIR]==2,-1,1)
data[:,IDX_NEXT_POS]=data[:,IDX_CUR_POS]

def adjust_pos(d):
    return np.where(d<0,L,np.where(d>L,0,d))

def get_dup_pos(d):
    pos2idx={}
    dup_pos_p=set()
    for j,p in enumerate(d):
        if p not in pos2idx.keys():
            pos2idx[p]=[j]
        else:
            pos2idx[p].append(j)
            dup_pos_p.add(p)
    dup_pos=[]
    for p in dup_pos_p:
        dup_pos.extend(pos2idx[p])
    return dup_pos

def adj_next(d,dup_pos):
    cnt=len(dup_pos)
    if cnt>0:
        d[dup_pos,IDX_NEXT_POS]=d[dup_pos,IDX_CUR_POS]
        d[dup_pos,IDX_DIR]=-1*d[dup_pos,IDX_DIR]

    return d,cnt


for i in range(T):
    data[:,IDX_NEXT_POS]=adjust_pos(data[:,IDX_CUR_POS]+data[:,IDX_DIR])
    while True:
        # 同じ位置にいるのは良いらしい。次に動くタイミングでチェック
        dup_pos=get_dup_pos(data[:,IDX_CUR_POS])
        data,cnt0=adj_next(data,dup_pos)
        dup_pos=get_dup_pos(data[:,IDX_NEXT_POS]+data[:,IDX_CUR_POS])
        data,cnt1=adj_next(data,dup_pos)
        if (cnt0==0) and (cnt1==0):
            break
    
    data[:,IDX_CUR_POS]=data[:,IDX_NEXT_POS]

for d in data[:,IDX_CUR_POS]:
    print(int(d))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,L_in,T=[ int(r) for r in input().split(' ') if r != '' ]
data_in=np.array([[ int(r) for r in input().split(' ') if r != '' ] for _ in range(N) ])
# N,L_in,T=3,8,3
# data_in=np.array([
#     [0,1],
#     [3,2],
#     [6,1],
# ])
L=L_in-1
IDX_CUR_POS=0
IDX_DIR=1
IDX_NEXT_POS=2


data=np.zeros((data_in.shape[0],3))
data[:,[IDX_CUR_POS,IDX_DIR]]=data_in
data[:,IDX_DIR]=np.where(data[:,IDX_DIR]==2,-1,1)
data[:,IDX_NEXT_POS]=data[:,IDX_CUR_POS]

def adjust_pos(d):
    return np.where(d<0,L,np.where(d>L,0,d))

def get_pos2idx(d):
    pos2idx={}
    for j,p in enumerate(d):
        if p not in pos2idx.keys():
            pos2idx[p]=[j]
        else:
            pos2idx[p].append(j)
    return pos2idx

def adj_next(d,pos2idx):
    cnt=0
    for p in pos2idx.keys():
        if len(pos2idx[p]) > 1:
            for j in pos2idx[p]:
                d[j,IDX_NEXT_POS]=d[j,IDX_CUR_POS]
                d[j,IDX_DIR]=-1*d[j,IDX_DIR]
                cnt+=1
    return d,cnt


for i in range(T):
    data[:,IDX_NEXT_POS]=adjust_pos(data[:,IDX_CUR_POS]+data[:,IDX_DIR])
    while True:
        # 同じ位置にいるのは良いらしい。次に動くタイミングでチェック
        pos2idx=get_pos2idx(data[:,IDX_CUR_POS])
        data,cnt0=adj_next(data,pos2idx)
        pos2idx=get_pos2idx(data[:,IDX_NEXT_POS]+data[:,IDX_CUR_POS])
        data,cnt1=adj_next(data,pos2idx)
        if (cnt0==0) and (cnt1==0):
            break
    
    data[:,IDX_CUR_POS]=data[:,IDX_NEXT_POS]

for d in data[:,IDX_CUR_POS]:
    print(int(d))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, L, T = map(int, input().split())
xw_list = []
for n in range(N):
    xw_list.append(list(map(int, input().split())))

dic = {k : v for k, v in enumerate(xw_list)}
sort_dic = sorted(dic.items(), key=lambda x:x[1])
    
# 1 : 時計回り、2 : 反時計回り
for t in range(T):
    for n in range(N):
        t_xw = sort_dic[n][1]    # 対象アリ
        # 移動
        if t_xw[1]==1:
            t_xw[0] += 1
        else:
            t_xw[0] -= 1
        # 周回した時の変換
        if t_xw[0]<0:
            t_xw[0] = L + t_xw[0]
        elif t_xw[0]>L:
            t_xw[0] = t_xw[0] - L
    
    # 衝突
    for n in range(N):
        # 座標前後のみで検索
        t_xw = sort_dic[n][1]    # 対象アリ
        if n==N-1:
            next_xw = sort_dic[0][1]    # 後のアリ
        else:    
            next_xw = sort_dic[n+1][1]    # 後のアリ
        
        # １秒後に同じ場所　→　方向転換
        if t_xw[0]==next_xw[0]:
            t_xw[1] = next_xw[1]
            next_xw[1] = t_xw[1]
        # 0.5秒後にすれ違う
        if np.abs(t_xw[0]-next_xw[0])==1 and t_xw[1]!=next_xw[1]:
            if (t_xw[0]>next_xw[0] or (t_xw[0]==0 and next_xw[0]==L-1)) and t_xw[1]==1:
                t_xw[0] -= 1
                t_xw[1] = 2
                next_xw[0] += 1
                next_xw[1] = 1
            elif (next_xw[0]>t_xw[0] or (next_xw[0]==0 and t_xw[0]==L-1)) and next_xw[1]==1:
                t_xw[0] += 1
                t_xw[1] = 1
                next_xw[0] -= 1
                next_xw[1] = 2

for tup in sorted(sort_dic):
    print(tup[1][0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, L, T = map(int, input().split())
xw_list = []
for n in range(N):
    xw_list.append(list(map(int, input().split())))

dic = {k : v for k, v in enumerate(xw_list)}
sort_dic = sorted(dic.items(), key=lambda x:x[1])
    
# 1 : 時計回り、2 : 反時計回り
for t in range(T):
    for n in range(N):
        t_xw = sort_dic[n][1]    # 対象アリ
        # 移動
        if t_xw[1]==1:
            t_xw[0] += 1
        else:
            t_xw[0] -= 1
        # 周回した時の変換
        if t_xw[0]<0:
            t_xw[0] = L + t_xw[0]
        elif t_xw[0]>L:
            t_xw[0] = t_xw[0] - L
    
    # 衝突
    for n in range(N):
        # 座標前後のみで検索
        t_xw = sort_dic[n][1]    # 対象アリ
        if n==0:
            next_xw = sort_dic[-1][1]    # 前のアリ
#             ato_xw = sort_dic[n+1][1]    # 後のアリ
        elif n==N-1:
            next_xw = sort_dic[n-1][1]    # 前のアリ
#             ato_xw = sort_dic[0][1]    # 後のアリ
        else:    
            next_xw = sort_dic[n-1][1]    # 前のアリ
#             ato_xw = sort_dic[n+1][1]    # 後のアリ
        
#         for next_xw in [mae_xw]:
#                         , ato_xw]:
        # １秒後に同じ場所　→　方向転換
        if t_xw[0]==next_xw[0]:
            t_xw[1] = next_xw[1]
            next_xw[1] = t_xw[1]
        # 0.5秒後にすれ違う
        if np.abs(t_xw[0]-next_xw[0])==1 and t_xw[1]!=next_xw[1]:
            if (t_xw[0]>next_xw[0] or (t_xw[0]==0 and next_xw[0]==L-1)) and t_xw[1]==1:
                t_xw[0] -= 1
                t_xw[1] = 2
                next_xw[0] += 1
                next_xw[1] = 1
            elif (next_xw[0]>t_xw[0] or (next_xw[0]==0 and t_xw[0]==L-1)) and next_xw[1]==1:
                t_xw[0] += 1
                t_xw[1] = 1
                next_xw[0] -= 1
                next_xw[1] = 2

for tup in sorted(sort_dic):
    print(tup[1][0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, L, T = map(int, input().split())
xw_list = []
for n in range(N):
    xw_list.append(list(map(int, input().split())))

dic = {k : v for k, v in enumerate(xw_list)}
sort_dic = sorted(dic.items(), key=lambda x:x[1])
    
# 1 : 時計回り、2 : 反時計回り
for t in range(T):
    for n in range(N):
        t_xw = sort_dic[n][1]    # 対象アリ
        # 移動
        if t_xw[1]==1:
            t_xw[0] += 1
        else:
            t_xw[0] -= 1
        # 周回した時の変換
        if t_xw[0]<0:
            t_xw[0] = L + t_xw[0]
        elif t_xw[0]>L:
            t_xw[0] = t_xw[0] - L
    
    # 衝突
    for n in range(N):
        # 座標前後のみで検索
        t_xw = sort_dic[n][1]    # 対象アリ
        if n==0:
            mae_xw = sort_dic[-1][1]    # 前のアリ
#             ato_xw = sort_dic[n+1][1]    # 後のアリ
        elif n==N-1:
            mae_xw = sort_dic[n-1][1]    # 前のアリ
#             ato_xw = sort_dic[0][1]    # 後のアリ
        else:    
            mae_xw = sort_dic[n-1][1]    # 前のアリ
#             ato_xw = sort_dic[n+1][1]    # 後のアリ
        
        for next_xw in [mae_xw]:
#                         , ato_xw]:
            # １秒後に同じ場所　→　方向転換
            if t_xw[0]==next_xw[0]:
                t_xw[1] = next_xw[1]
                next_xw[1] = t_xw[1]
            # 0.5秒後にすれ違う
            if np.abs(t_xw[0]-next_xw[0])==1 and t_xw[1]!=next_xw[1]:
                if (t_xw[0]>next_xw[0] or (t_xw[0]==0 and next_xw[0]==L-1)) and t_xw[1]==1:
                    t_xw[0] -= 1
                    t_xw[1] = 2
                    next_xw[0] += 1
                    next_xw[1] = 1
                elif (next_xw[0]>t_xw[0] or (next_xw[0]==0 and t_xw[0]==L-1)) and next_xw[1]==1:
                    t_xw[0] += 1
                    t_xw[1] = 1
                    next_xw[0] -= 1
                    next_xw[1] = 2

for tup in sorted(sort_dic):
    print(tup[1][0])

Submission status: Time Limit Exceeded

Solution code:
n, l, t =map(int, input().split())
x=[]
w=[]
for i in range(n):
  a, b=map(int, input().split())
  x.append(a)
  if b==2:
    w.append(-1)
  else:
    w.append(1)
for fn in range(t*2):
  x=[d+0.5*e for (d, e) in zip(x, w)]
  for f in range(n):
    if x[f]>=l:
      x[f]-=l
    elif x[f]<0:
      x[f]+=l
  for p in range(n):
    if p==n-1:
      if x[p]==x[0]:
        w[p]=w[p]*(-1)
        w[0]=w[0]*(-1)
    else:
      if x[p]==x[p+1]:
        w[p]=w[p]*(-1)
        w[p+1]=w[p+1]*(-1)
for i in range(n):
  print(int(x[i]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, L, T = map(int, input().split())
xw_list = []
for n in range(N):
    xw_list.append(list(map(int, input().split())))

# 1 : 時計回り、2 : 反時計回り
for t in range(T):
    for n in range(N):
        # 移動
        if xw_list[n][1]==1:
            xw_list[n][0] += 1
        else:
            xw_list[n][0] -= 1
        # 周回した時の変換
        if xw_list[n][0]<0:
            xw_list[n][0] = L + xw_list[n][0]
        elif xw_list[n][0]>L:
            xw_list[n][0] = xw_list[n][0] - L
    
    # 衝突
    for n in range(N):
        for m in range(n+1, N):
            # １秒後に同じ場所　→　方向転換
            if xw_list[n][0]==xw_list[m][0]:
                xw_list[n][1] = xw_list[m][1]
                xw_list[m][1] = xw_list[n][1]
            # 0.5秒後にすれ違う
            if np.abs(xw_list[n][0]-xw_list[m][0])==1 and xw_list[n][1]!=xw_list[m][1]:
                if (xw_list[n][0]>xw_list[m][0] or (xw_list[n][0]==0 and xw_list[m][0]==L-1)) and xw_list[n][1]==1:
                    xw_list[n][0] -= 1
                    xw_list[n][1] = 2
                    xw_list[m][0] += 1
                    xw_list[m][1] = 1
                elif (xw_list[m][0]>xw_list[n][0] or (xw_list[m][0]==0 and xw_list[n][0]==L-1)) and xw_list[m][1]==1:
                    xw_list[n][0] += 1
                    xw_list[n][1] = 1
                    xw_list[m][0] -= 1
                    xw_list[m][1] = 2

for n in range(N):
    print(xw_list[n][0])

Submission status: Time Limit Exceeded

Solution code:
n, l, t = map(int, input().split())
ants = [tuple(map(int, input().split())) for _ in range(n)]
place = []
clock = []
anticlock = []
for i, (x, w) in enumerate(ants):
    if w == 1:
        place.append((x + t) % l)
        clock.append((i, x))
    else:
        place.append((x - t) % l)
        anticlock.append((i, x))

def dist(x, y):
    if x < y: return y - x
    else: return y - x + l

swap = []
for i, x in clock:
    for j, y in anticlock:
        tmp = t * 2
        d = dist(x, y)
        if tmp > d:
            tmp -= d
            swap.append((d, i, j))
            for c in range(1, tmp // l):
                swap.append((d + c * l, i, j))

swap.sort(reverse=True)
for d, i, j in swap:
    place[i], place[j] = place[j], place[i]
for p in place:
    print(p)

Submission status: Time Limit Exceeded

Solution code:
import copy

(N, L, T) = list(map(int, input().split()))

def normalize(x):
    return (x + L) % L


def prepare():
    cw_list = []
    ccw_list = []
    ants_map = {}
    for no in range(1, N + 1):
        (x, w) = list(map(int, input().split()))
        if w == 1:
            cw_list.append(no)
        else:
            ccw_list.append(no)
            w = -1
        move = []
        for t in range(T + 1):
            move.append(normalize(x + w * t))
        ants_map[no] = move
    return cw_list, ccw_list, ants_map


def get_combi_list(cw_list, ccw_list):
    combi = []
    for cw in cw_list:
        for ccw in ccw_list:
            combi.append((cw, ccw))
    return combi

def get_cross_point():
    cross_point_list = []
    for t in range(1, T + 1):
        between_points = []
        points = []
        for a, b in combi_list:
            prev_a = ants_map[a][t - 1]
            curr_a = ants_map[a][t]
            prev_b = ants_map[b][t - 1]
            curr_b = ants_map[b][t]
            if prev_a == curr_b and prev_b == curr_a:
                between_points.append((t - 0.5, a, b))
            if curr_a == curr_b:
                points.append((t, a, b))
        if len(between_points) > 0:
            cross_point_list.append(between_points)
        if len(points) > 0:
            cross_point_list.append(points)            
            
    return cross_point_list


def get_dst_list(ants_map):
    dst = []
    for no in sorted(ants_map.keys()):
        dst.append(ants_map[no][-1])
    return dst


def exchange(dst_list, ia, ib):
    prev_a = dst_list[ia]
    prev_b = dst_list[ib]
    dst_list[ia] = prev_b
    dst_list[ib] = prev_a

    
cw_list, ccw_list, ants_map = prepare()
combi_list = get_combi_list(cw_list, ccw_list)
cross_points_list = get_cross_point()
dst_list = get_dst_list(ants_map)

#print(ants_map)

#print(cross_points_list)

#print(dst_list)

for cross_points in sorted(cross_points_list, reverse=True):
    for t, a, b in cross_points:
        exchange(dst_list, a - 1, b - 1)

for d in dst_list:
    print(d)

Submission status: Time Limit Exceeded

Solution code:
import copy

(N, L, T) = list(map(int, input().split()))

snapshot = []
for no in range(1, N + 1):
    (x, w) = list(map(int, input().split()))
    snapshot.append({
        'i': no - 1,
        'no': no,
        'x': x,
        'w': 1 if w == 1 else -1
    })


def normalize(x):
    return (x + L) % L


def find_neighbor(ant):
    x = ant['x']
    for neighbor in snapshot:
        if ant['no'] == neighbor['no']:
            continue
        _x = neighbor['x']
        if _x == normalize(x - 1) and (ant['w'] == -1 and neighbor['w'] == 1):
            return neighbor
        if _x == normalize(x + 1) and (ant['w'] == 1 and neighbor['w'] == -1):
            return neighbor
        if _x == x:
            return neighbor
    return None


def move():
    results = {}
    for ant in copy.deepcopy(snapshot):
        x = ant['x']        
        no = ant['no']
        if no in results:
            continue
        neighbor = find_neighbor(ant)
        if neighbor is None:
            ant['x'] = normalize(ant['x'] + ant['w'])
            results[ant['no']] = ant
            continue
        if x == neighbor['x']:
            ant['w'] *= -1
            ant['x'] = normalize(ant['x'] + ant['w'])
            if neighbor['no'] not in results:            
                neighbor['w'] *= -1
                neighbor['x'] = normalize(neighbor['x'] + neighbor['w'])
                results[neighbor['no']] = neighbor
        else:
            ant['w'] *= -1
            results[ant['no']] = ant
            if neighbor['no'] not in results:
                neighbor['w'] *= -1
                results[neighbor['no']] = neighbor
    ret = []
    for k in sorted(results.keys()):
        ret.append(results[k])
    return ret

        
t = 0
for i in range(T):
    t += 1
    snapshot = move()
for s in snapshot:
    print(s['x'])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, l, t = map(int, input().split())
x = np.zeros([n])
w = np.zeros([n])
next_position = np.zeros([n])
distance = np.zeros([n])
distance_prev = np.zeros([n])
index = np.arange(0, n)
index = np.append(index, int(0))
for i in range(n):
    x[i], w[i] = map(int, input().split())
    if w[i] == 2:
        w[i] = -1
x_2 = np.roll(x, -1)
distance_prev = np.abs(x_2 - x)

for i in range(t):
    next_position = x + w
    for j in range(n):
        if next_position[j] == l:
            next_position[j] = 0
        elif next_position[j] == -1:
            next_position[j] = l - 1
    for j in range(n):
        next_position_2 = np.roll(next_position, -1)
        distance = np.abs(next_position_2 - next_position)
        if (distance_prev[j] == 1 and distance[j] == 1) or (distance_prev[j] == l - 1 and distance[j] == l - 1):
            w[index[j]] *= -1
            w[index[j + 1]] *= -1
            next_position[index[j]] = x[index[j]]
            next_position[index[j + 1]] = x[index[j + 1]]
        elif distance[j] == 0 or distance[j] == l:
            w[index[j]] *= -1
            w[index[j + 1]] *= -1
    x = next_position
    distance_prev[:] = distance[:]

for i in range(n):
    print(int(x[i]))

Submission status: Time Limit Exceeded

Solution code:
N, L, T = map(int, input().split())
ant = []
for i in range(N):
  a = list(map(int, input().split()))
  a[0] = 2*a[0]
  ant.append(a)
for _ in range(2*T):  
  for i in range(N):
    if ant[i][1] == 1:
      ant[i][0] += 1
      if ant[i][0] == 2*L:
        ant[i][0] = 0
    else:
      ant[i][0] -= 1
      if ant[i][0] == -1:
        ant[i][0] = 2*L - 1
  for j in range(N):
    if ant[j][0] == ant[j-1][0]:
      ant[j], ant[j-1] = ant[j-1], ant[j]
for i in range(N):
  print(ant[i][0]//2)

Submission status: Time Limit Exceeded

Solution code:
N, L, T = [int(item) for item in input().split()]
pos_list = [[int(item) for item in input().split()] for _ in range(N)]

num = 0
next_list = []

for i, item in enumerate(pos_list):
    a, b = item
    next_list.append([a, b, i])

while T >= 1:
    pos_list, next_list = next_list, []
    # print(pos_list)
    for pos, direction, num in pos_list:
        if direction == 1:
            pos = (pos + 1) % L
            next_list.append([pos, direction, num])

        else:
            pos = (pos -1) % L
            if pos < 0:
                pos += 8
            next_list.append([pos, direction, num])
        
        num += 1

    for i in range(N):
        
        is_contact = False

        if next_list[i][1] == 1:
            if next_list[i][0] == (next_list[(i+1)%N][0] + 1) % L:
                next_list[i][1], next_list[(i+1)%N][1] = next_list[(i+1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i+1)%N][0] = next_list[(i+1)%N][0], next_list[i][0]
        else:
            if next_list[i][0] == (next_list[(i-1)%N][0] - 1) % L:
                next_list[i][1], next_list[(i-1)%N][1] = next_list[(i-1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i-1)%N][0] = next_list[(i-1)%N][0], next_list[i][0]

    T -= 1

# print(next_list)

for item in next_list:
    print(item[0])

Submission status: Time Limit Exceeded

Solution code:
N, L, T = [int(item) for item in input().split()]
pos_list = [[int(item) for item in input().split()] for _ in range(N)]

num = 0
next_list = []

for i, item in enumerate(pos_list):
    a, b = item
    next_list.append([a, b, i])

while T >= 1:
    pos_list, next_list = next_list, []
    # print(pos_list)
    for pos, direction, num in pos_list:
        if direction == 1:
            pos = (pos + 1) % L
            next_list.append([pos, direction, num])

        else:
            pos = (pos -1) % L
            if pos < 0:
                pos += 8
            next_list.append([pos, direction, num])
        
        num += 1

    for i in range(N):
        
        is_contact = False

        if next_list[i][1] == 1:
            if next_list[i][0] == (next_list[(i+1)%N][0] + 1) % L:
                next_list[i][1], next_list[(i+1)%N][1] = next_list[(i+1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i+1)%N][0] = next_list[(i+1)%N][0], next_list[i][0]
        else:
            if next_list[i][0] == (next_list[(i-1)%N][0] - 1) % L:
                next_list[i][1], next_list[(i-1)%N][1] = next_list[(i-1)%N][1], next_list[i][1]
                next_list[i][0], next_list[(i-1)%N][0] = next_list[(i-1)%N][0], next_list[i][0]

    T -= 1

# print(next_list)

for item in next_list:
    print(item[0])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def hoge(x):
    if x == 1:
        return 1
    elif x == 2:
        return -1
    else:
        return 0


def main():
    N, L, T = map(int, input().split())

    p = np.zeros([3, N])

    for i in range(N):
        x, w = map(int, input().split())
        p[0, i] = i + 1
        p[1, i] = x
        p[2, i] = hoge(w)

    for _ in range(0, 2*T):  # 0.5秒間隔で動かす
        for i in range(N):
            p[1, i] += p[2, i] / 2.0

        p[1, :] = np.where(p[1, :] < 0, p[1, :] + L, p[1, :])
        p[1, :] = np.where(p[1, :] >= L, p[1, :] - L, p[1, :])

        p = p[:, np.argsort(p[1])]

        for i in range(N-1):
            if p[1, i] == p[1, i+1]:
                ii = p[0, i]
                p[0, i] = p[0, i+1]
                p[0, i+1] = ii

    ans = p[1, np.argsort(p[0])]
    for i in range(N):
        print(int(ans[i]))


main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,L,T = map(int,input().split())

X = np.zeros(100000)
W = np.zeros(100000)

for i in range(N):
	X[i],W[i] = map(int,input().split())
	
T = T % L
	
for i in range(T*2):
	for j in range(N):
		if W[j] == 1:
			X[j] = X[j] + 0.5
		else:
			X[j] = X[j] - 0.5		
		for k in range(j):
			if X[j] % L == X[k] % L:
				W[j],W[k] = W[k],W[j]
		
		if X[j] == 0 and W[j] == 2:
			X[j] = L
		elif X[j] == L and W[j] == 1:
			X[j] = 0
		
		if X[j] == L:
			X[j] = 0

for i in range(N):
	print(int(X[i]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

#N:蟻の数
#L:円周の長さ
#T:時間

N,L,T = map(int,input().split())

X = np.zeros(100000)
W = np.zeros(100000)

for i in range(N):
	X[i],W[i] = map(int,input().split())
	
#0.5秒毎の位置確認
for i in range(T*2):
	#それぞれの蟻に関して
	for j in range(N):
		if W[j] == 1:
			X[j] = X[j] + 0.5
		else:
			X[j] = X[j] - 0.5		
		#衝突時の反転判定
		for k in range(j):
			if X[j] % L == X[k] % L:
				W[j],W[k] = W[k],W[j]
		
		#座標の修正(一周した場合)
		if X[j] == 0 and W[j] == 2:
			X[j] = L
		elif X[j] == L and W[j] == 1:
			X[j] = 0
		
		if X[j] == L:
			X[j] = 0

for i in range(N):
	print(int(X[i]))

Submission status: Time Limit Exceeded

Solution code:
def next_ants(r_ants, l_ants, r_ants_cord, l_ants_cord):
    for i,c in enumerate(r_ants_cord[::]):
        r_ants_cord[i] = (c + 0.5) % L
    for i,c in enumerate(l_ants_cord[::]):
        l_ants_cord[i] = (c - 0.5) % L
    for i,r_cord in enumerate(r_ants_cord):
        for j,l_cord in enumerate(l_ants_cord):
            if r_cord == l_cord:
                r_ant = r_ants[i]
                l_ant = l_ants[j]
                r_ants[i] = l_ant
                l_ants[j] = r_ant
    return (r_ants, l_ants, r_ants_cord, l_ants_cord)
N,L,T = [int(x) for x in input().split()]
r_ants = []
r_ants_cord = []
l_ants = []
l_ants_cord = []
for i in range(N):
    x,w = [int(x) for x in input().split()]
    if w == 1:
        r_ants.append(i)
        r_ants_cord.append(x)
    else:
        l_ants.append(i)
        l_ants_cord.append(x)
for _ in range(2 * T):
    r_ants, l_ants, r_ants_cord, l_ants_cord = next_ants(r_ants, l_ants, r_ants_cord, l_ants_cord)
for i in range(N):
    if i in r_ants:
        print(int(r_ants_cord[r_ants.index(i)]))
    else:
        print(int(l_ants_cord[l_ants.index(i)]))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n, l, t = map(int, input().split())
    lx, lw = [], []
    while True:
        try:
            x, w = map(int, input().split())
            lx.append(x*2)
            lw.append(w-1)
        except EOFError:
            break
    l *= 2
    t *= 2
    for i in range(t):
        for j in range(n):
            if lw[j] == 0:
                lx[j] = (lx[j]+1)%l
            else:
                lx[j] = (lx[j]-1)%l
        for j in range(n):
            for k in range(j+1, n):
                if lx[j] == lx[k]:
                    lw[j] = (lw[j]+1)%2
                    lw[k] = (lw[k]+1)%2
    for x in lx:
        print(x//2)
resolve()

Submission status: Time Limit Exceeded

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
def main():
    N, L, T = map(int, input().split())  # アリの数、外周、時間
    P = [0]*N  # アリの位置: 0から2L-1まで
    D = [0]*N  # アリの方向: 1か2
    for n in range(N):
        t1, t2 = map(int, input().split())
        P[n] = t1 * 2
        D[n] = t2
    for t in range(T * 2):
        P = [(P[n] - D[n] * 2 + 3) % (L * 2) for n in range(N)]
        mycount = P.count
        for n in range(N):
            if mycount(P[n]) == 2:
                D[n] = D[n] % 2 + 1
    for n in range(N):
        print(str(P[n]//2))


main()