Problem: 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.

Submission attempts (in order):

ant_list = []   

N, L, T = list(map(int, input().split()))
for i in range(N):
    pos, direction = list(map(int, input().split()))
    ant_list.append(Ant(pos, direction))

for t in range(T):
    clide_ant_list = get_colide_ants(ant_list)
    for ant in colide_ant_list:
        ant.change_direction()

    for ant in ant_list:
        ant.move()

    clide_ant_list = get_colide_ants(ant_list)
    for ant in colide_ant_list:
        ant.change_direction()
        ant.move()

def get_colide_ants(ant_list):
    colide_ant_list = []
    sorted(ant_list, key=lambda ant: ant.pos)
    len_ant_list = len(ant_list)
    for i in range(len_ant_list-1):
        if ant_list[index].pos == ant_list[index+1].pos:
            colide_ant_list.append((ant_list[i], ant_list[i+1]))
            
    return colide_ant_list
    

class Ant:
    def __init__(self, pos, direction):
        self.pos = pos
        self.direction = direction

    def move():
        if direction == 1:
            self.pos += 1
        else:
            self.pos -= 1

        if self.pos >= L:
            self.pos = self.pos - L
        if self.pos < 0:
            self.pos += L + self.pos

    def change_direction():
        if direction == 1:
            direction = 2
        else:
            direction = 1
        


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

X = []
W = []
X_after = []
for _ in range(N):
    x, w = list(map(int, input().split()))
    if w == 1:
        x_after = (x + T) % L
    else:
        x_after = (x - T) % L

    if x_after < 0:
        x_after = L + x_after

    X.append(x)
    W.append(w)
    X_after.append(x_after)

n_colide = 0
for i in range(1, N):
    if W[0] == 1 and W[i] == 2:
        dist = X[i] - X[0]
        n_colide += 2 * (T - (dist / 2)) // L + 1
    elif W[0] == 2 and W[i] == 1:
        dist = (L + X[0]) - X[i]
        n_colide += 2 * (T - (dist / 2)) // L + 1

if W[0] == 1:
    num_after = W[0] + (n_colide % N)
else:
    num_after = W[0] - (n_colide % N)
    num_after = num_after if num_after >= 0 else L + num_after

num_after = int(num_after)

last_info = [
    {"X": X_after[0], "num": num_after}
]
x_after_first = X_after[0]
X_after = sorted(X_after)
i = X_after.index(x_after_first)
X_after = X_after[i:] + X_after[:i]

for i in range(1, N):
    num = num_after + i
    if num >= N:
        num = N - num
    last_info.append({
        "X": X_after[i],
        "num": num,
    })

sorted_info = sorted(last_info, key=lambda info: info["num"])

for info in sorted_info:
    print(info["X"])


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

X = []
W = []
X_after = []
for _ in range(N):
    x, w = list(map(int, input().split()))
    if w == 1:
        x_a = (x + T) % L
    else:
        x_a = (x - T) % L
        x_a = x_a if x_a >= 0 else L + x_a
    X.append(x)
    W.append(w)
    X_after.append(x_a)

n_colide = 0
for i in range(1, N):
    if W[0] == 1 and W[i] == 2:
        dist = X[i] - X[0]
        n_colide += 2 * (T - (dist / 2)) // L + 1
    elif W[0] == 2 and W[i] == 1:
        dist = (L + X[0]) - X[i]
        n_colide += 2 * (T - (dist / 2)) // L + 1

if W[0] == 1:
    num_a0 = n_colide % N
else:
    num_a0 = N - (n_colide % N)

num_a0 = int(num_a0)

x_a0 = X_after[0]
X_after = sorted(X_after)
i = X_after.index(x_a0)
if W[0] == 1 and X_after.count(x_a0) == 2:
    i += 1
X_after = X_after[i-num_a0:] + X_after[:i-num_a0]

for x_a in X_after:
    print(x_a)


Verdicts: Runtime Error

Wrong Answer

Accepted