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:
def main():
    n, l, t = map(int, input().split())
    xs, ds = [], []
    for _ in range(n):
        x, w = [int(c) for c in input().split()]
        xs.append(x)
        ds.append(1 if w == 1 else -1)

    xs_thr = [(x + d * t )% l for x, d in zip(xs, ds)]

    x_groups = {
        -1: [x for i, x in enumerate(xs) if ds[i] == -1],
        1: [x for i, x in enumerate(xs) if ds[i] == 1],
    }

    def bin_count(arr, v):
        if len(arr) == 0 or v <= arr[0]:
            return 0
        p, q = 0, len(arr)
        while q - p > 1:
            m = (p + q) // 2
            if arr[m] < v:
                p = m
            else:
                q = m
        return q

    def collide(i):
        pos = xs[i] + t * ds[i] * 2
        itera = len(x_groups[-ds[i]]) * abs(pos // l)
        f_delta = bin_count(x_groups[-ds[i]], xs[i])
        b_delta = bin_count(x_groups[-ds[i]], pos % l)
        return itera + (b_delta - f_delta) * ds[i]

    for i in range(n):
        print(xs_thr[(i - collide(i) * ds[i] % n + n) % n])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
R=[0 for i in range(N)]
Z=0
for i in range(1,N):
    if W[i]==W[0]:
        R[i]=0
    else:
        R[i]=1+(2*L-(X[i]-X[0]))//T
    Z+=W[0]*R[i]
Z=(Z+2)%N
Q=[]
for i in range(Z,N):
    Q.append(Y[i])
for i in range(Z):
    Q.append(Y[i])
for i in range(N):
    print(Q[i])

Submission status: Wrong Answer

Solution code:
N,L,T=map(int,input().split())
X=[0 for i in range(N)]
W=[0 for i in range(N)]
for i in range(N):
    X[i],W[i]=map(int,input().split())
    W[i]=-2*W[i]+3
Y=sorted([((T*W[i])+X[i])%L for i in range(N)])
for i in range(N):
    print(Y[(i+1)%N])

Submission status: Wrong Answer

Solution code:
N, L, T = tuple(map(int, input().split(' ')))

ants = [list(map(int, input().split(' '))) for _ in range(0, N)]

for t in range(0, T): # time loop
    # 次の1秒間に衝突が発生する場合、蟻のインデックスを入れ替える
    for i in range(0, len(ants)):
        # 衝突が発生する条件
        next_idx = (i + 1) % N
        if (ants[next_idx][0] - ants[i][0]) * (ants[next_idx][1] - ants[i][1]) in [1, L-1]:
            ants[i], ants[next_idx] = ants[next_idx], ants[i]

    for ant in ants:
        ant[0] += (-1) ** ((ant[1] % 2) + 1)
        ant[0] %= L

    print(ants)

for x, o in ants:
    print(x)

Submission status: Wrong Answer

Solution code:
N,L,T = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

mem = []
for x,w in src:
    move = (-T if w == 2 else T)
    mem.append((x + move) % L)
first_x = mem[0]
mem.sort()

first_i = mem.index(first_x)
for i in range(first_i, first_i + N):
    print(mem[(i-1) % N])

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 = 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 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)

Submission status: Wrong Answer

Solution code:
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)
X_after = X_after[i-num_a0:] + X_after[:i-num_a0]

for x_a in X_after:
    print(x_a)

Submission status: Wrong Answer

Solution code:
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
        x_after = x_after if x_after >= 0 else 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 = n_colide % N
else:
    num_after = N - (n_colide % N)

num_after = int(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-num_after:] + X_after[:i-num_after]

for x_after in X_after:
    print(x_after)

Submission status: Wrong Answer

Solution code:
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
        x_after = x_after if x_after >= 0 else 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 = n_colide % N
else:
    num_after = N - (n_colide % N)

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"])

Submission status: Wrong Answer

Solution code:
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
        x_after = x_after if x_after >= 0 else 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 = n_colide % N
else:
    num_after = N - (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"])

Submission status: Wrong Answer

Solution code:
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"])

Submission status: Wrong Answer

Solution code:
import bisect
from operator import add, sub

n, l, t = map(int, input().split())

ope = [None, add, sub]
ants = [tuple(map(int, input().split())) for _ in range(n)]
ants_pos = [ope[w](x, t) % l for x, w in ants]

if n == 1:
    print(ants_pos[0])
    exit()

x0, w0 = ants[0]
crash_cnt = 0
crash_check = (lambda x: t - (x - x0) / 2) if w0 == 1 else (lambda x: t - (l - x + x0) / 2)
for x, w in ants[1:]:
    if w == w0:
        continue
    d = crash_check(x)
    if d > 0:
        crash_cnt += 2 * d // l + 1

ant_alt0 = (0, 1, -1)[w0] * int(crash_cnt) % n
sorted_pos = sorted(ants_pos)
pos_i = bisect.bisect_left(sorted_pos, ants_pos[0])
if pos_i < n - 1 and sorted_pos[pos_i] == sorted_pos[pos_i + 1] and w0 == 2:
    pos_i += 1
pos0_i = (pos_i - ant_alt0) % n
for pos in sorted_pos[pos0_i:]:
    print(pos)
for pos in sorted_pos[:pos0_i]:
    print(pos)

Submission status: Wrong Answer

Solution code:
import bisect
from operator import add, sub

n, l, t = map(int, input().split())

ope = [None, add, sub]
ants = [tuple(map(int, input().split())) for _ in range(n)]
ants_pos = [ope[w](x, t) % l for x, w in ants]

if n == 1:
    print(ants_pos[0])
    exit()

x0, w0 = ants[0]
crash_cnt = 0
crash_check = (lambda x: t - (x - x0) / 2) if w0 == 1 else (lambda x: t - (l - x + x0) / 2)
for x, w in ants[1:]:
    if w == w0:
        continue
    d = crash_check(x)
    if d > 0:
        crash_cnt += d // l + 1

ant_alt0 = (0, 1, -1)[w0] * int(crash_cnt) % n
sorted_pos = sorted(ants_pos)
pos_i = bisect.bisect_left(sorted_pos, ants_pos[0])
if pos_i < n - 1 and sorted_pos[pos_i] == sorted_pos[pos_i + 1] and w0 == 2:
    pos_i += 1
pos0_i = (pos_i - ant_alt0) % n
for pos in sorted_pos[pos0_i:]:
    print(pos)
for pos in sorted_pos[:pos0_i]:
    print(pos)

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
start=-1
for i in xrange(n):
    if w[i]==1:
        start=i
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t)%l)
if start==-1:
    for i in xrange(n):
        print pos[i]/2
    exit()
 
ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(n,2*n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=nokori/(l/2)+1
idx=(start+cnt)%n
ans[idx]=pos[start]
pos.sort()
for i in xrange(n):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(1,idx+1):
    ans[(idx-i)%n]=pos[(now-i)%n]
for i in xrange(1,n-idx):
    ans[(idx+i)%n]=pos[(now+i)%n]
for i in xrange(n):
    print ans[i]/2

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
start=-1
check=False
for i in xrange(n):
    if w[i]==1:
        check=True
        start=i
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t+l)%l)
if not check:
    for i in xrange(n):
        print pos[i]/2
    exit()
"""
for i in xrange(len(w1)):
    if pos.count(pos[w1[i]])==1:
        start=w1[i]
        break
"""
#print start
ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(start,start+n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=2*nokori/l+1
        if nokori%l>=l/2:
            cnt+=1
idx=(start+cnt)%n
#print idx
ans[idx]=pos[start]
pos.sort()
for i in xrange(n-1,-1,-1):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(idx+1,idx+n):
    ans[i%n]=pos[(now+i-idx)%n]
for i in xrange(n):
    print ans[i]/2

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
w1=[]
check=False
for i in xrange(n):
    if w[i]==1:
        check=True
        w1.append(i)
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t)%l)
if not check:
    for i in xrange(n):
        print pos[i]/2
    exit()
for i in xrange(len(w1)):
    if pos.count(pos[w1[i]])==1:
        start=w1[i]
        break
#print start
ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(start,start+n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=2*nokori/l+1
        if nokori%l>=l/2:
            cnt+=1
idx=(start+cnt)%n
#print idx
ans[idx]=pos[start]
pos.sort()
for i in xrange(n):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(idx+1,idx+n):
    ans[i%n]=pos[(now+i-idx)%n]
for i in xrange(n):
    print ans[i]/2

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
w1=[]
check=False
for i in xrange(n):
    if w[i]==1:
        check=True
        w1.append(i)
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t)%l)
if not check:
    for i in xrange(n):
        print pos[i]/2
    exit()
for i in xrange(len(w1)):
    if pos.count(pos[w1[i]])==1:
        start=w1[i]
        break
#print start
ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(start,start+n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=2*nokori/l+1
        if nokori%l>=l/2:
            cnt+=1

idx=(start+cnt)%n
#print idx
ans[idx]=pos[start]
pos.sort()
for i in xrange(n):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(1,idx+1):
    ans[(idx-i)%n]=pos[(now-i)%n]
for i in xrange(1,n-idx):
    ans[(idx+i)%n]=pos[(now+i)%n]
for i in xrange(n):
    print ans[i]/2

Submission status: Wrong Answer

Solution code:
n,l,t=map(int,raw_input().split())
l*=2
t*=2
x=[None]*(2*n)
w=[None]*(2*n)
for i in xrange(n):
    ex,ew=map(int,raw_input().split())
    x[i]=ex*2;x[i+n]=ex*2+l
    w[i]=ew;w[i+n]=ew
pos=[]
start=-1
for i in xrange(n):
    if w[i]==1:
        start=i
        pos.append((x[i]+t)%l)
    else:
        pos.append((x[i]-t)%l)
if start==-1:
    for i in xrange(n):
        print pos[i]/2
    exit()

ans=[-1]*n
cnt=0
sx=x[start]
for i in xrange(n,2*n):
    if w[i]==2:
        nokori=t-(x[i]-sx)/2
        if nokori<0:continue
        cnt+=2*nokori/l+1
        if nokori%l>=l/2:
            cnt+=1
idx=(start+cnt)%n
ans[idx]=pos[start]
pos.sort()
for i in xrange(n):
    if pos[i]==ans[idx]:
        now=i
        break
for i in xrange(1,idx+1):
    ans[(idx-i)%n]=pos[(now-i)%n]
for i in xrange(1,n-idx):
    ans[(idx+i)%n]=pos[(now+i)%n]
for i in xrange(n):
    print ans[i]/2

Submission status: Wrong Answer

Solution code:

# アリ１からNまでの前後関係は不変。つまり、アリ１からNまでの順番は保たれる。
# アリの最終座標の昇順リストを用意して、アリ１からNに対応させればよい。

n,l,t=map(int,input().split())
x=[]
w=[]
ans=[]

crash=0
for i in range(n):
    xx,ww=map(int,input().split())
    x.append(xx); w.append(ww)
    if w[i]==1: anss=(x[i]+t)%l
    else: anss=(x[i]-t+l)%l
    ans.append(anss)
    if i!=0 and w[i] != w[0]:
        if w[0] == 1: crash += (t-((x[i]-x[0])/2)) // (l/2) + 1
        else: crash += (t-(l-(x[i]-x[0]))/2) // (l/2) + 1

# あり１の現在のゼッケン番号num0
if w[0]==1: num0 =int(crash)%n
else: num0 =int(-crash)%n
# あり１の現在地点に対応する昇順リストの番号num
nowplace = ans[0]
ans.sort()
num = ans.index(nowplace)
if w[0]==1 and ans.count(nowplace)==2: num += 1 # ２つ該当する場合の処理
# numがnum0の位置であるように調整したい
gap = num0-num
for i in range(n):
    i = (i+gap)%n
    print(ans[i])
print(ans)

Submission status: Wrong Answer

Solution code:

# アリ１からNまでの前後関係は不変。つまり、アリ１からNまでの順番は保たれる。
# アリの最終座標の昇順リストを用意して、アリ１からNに対応させればよい。

n,l,t=map(int,input().split())
x=[]
w=[]
ans=[]

crash=0
for i in range(n):
    xx,ww=map(int,input().split())
    x.append(xx); w.append(ww)
    if w[i]==1: anss=(x[i]+t)%l
    else: anss=(x[i]-t+l)%l
    ans.append(anss)
    if i!=0 and w[i] != w[0]:
        if w[0] == 1: crash += (t-((x[i]-x[0])/2)) // (l/2) + 1
        else: crash += (t-(l-(x[i]-x[0]))/2) // (l/2) + 1

# あり１の現在のゼッケン番号num0
if w[0]==1: num0 =int(crash)%n
else: num0 =int(-crash)%n
# あり１の現在地点に対応する昇順リストの番号num
nowplace = ans[0]
ans.sort()
num = ans.index(nowplace)
if w[0]==1 and ans.count(nowplace)==2: num += 1 # ２つ該当する場合の処理
# numがnum0の位置であるように調整したい
gap = num0-num
for i in range(n):
    i = (i-gap)%n
    print(ans[i])
print(ans)

Submission status: Wrong Answer

Solution code:

# アリ１からNまでの前後関係は不変。つまり、アリ１からNまでの順番は保たれる。
# アリの最終座標の昇順リストを用意して、アリ１からNに対応させればよい。

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

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

# 衝突回数crashを求める
crash=0
for i in range(2,n+1):
    if w[i] != w[1]:
        if w[1] == 1:
            crash += (t-((x[i]-x[1])/2)) // (l/2) + 1
        else:
            crash += (t-(l-(x[i]-x[1]))/2) // (l/2) + 1

# ansをソートしてcrash分だけ円順列的にずらす
ans.sort()
crash = int(crash)
for i in range(n):
    i = (i-crash)%n
    print(ans[i])
print(ans,crash)

Submission status: Wrong Answer

Solution code:

# アリ１からNまでの前後関係は不変。つまり、アリ１からNまでの順番は保たれる。
# アリの最終座標の昇順リストを用意して、アリ１からNに対応させればよい。

n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[]
w1=[] # w=1の初期座標リスト
w2=[] # w=2の初期座標リスト

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

# 衝突回数crashを求める
crash=0
for i in range(1, n):
    if w[1] != w[i]:
        if w[1] == 1:
            crash += (t - ((x[i] - x[1]) / 2)) // (l / 2) + 1
        else:
            crash += (t - (l - (x[i] - x[1])) / 2) // (l / 2) + 1

# ansをソートしてcrash分だけ円順列的にずらす
ans.sort()
crash = int(crash)
for i in range(n):
    i = (i+crash)%n
    print(ans[i])

Submission status: Wrong Answer

Solution code:

# アリ１からNまでの前後関係は不変。つまり、アリ１からNまでの順番は保たれる。
# アリの最終座標の昇順リストを用意して、アリ１からNに対応させればよい。

n,l,t=map(int,input().split())
x=[0 for i in range(n+1)]
w=[0 for i in range(n+1)]
ans=[]
w1=[] # w=1の初期座標リスト
w2=[] # w=2の初期座標リスト

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

# kはアリ同士がすれ違った数
k=0
for i in range(n):
    if w[i]==1: # もしw=1のアリがいないならk=0のままで問題なし。
        if (x[i]+2*t)>=l:
            for j in range(x[i],x[i]+2*t+1): k+=w2.count(j)
            for j in range((x[i]+2*t+1)%l,x[i]): k+=w2.count(j)
        else:
            for j in range(x[i],x[i]+2*t+1): k+=w2.count(j)
        break # １つw=1のアリ見つけたらそこで終了。

# ansをソートしてkだけ円順列的にずらして出力
ans.sort()
for i in range(n): print(ans[(i+k)%n])

Submission status: Wrong Answer

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

import sys
import os

DEBUG = False

N, L, T = map(int, input().split())
# N あり
# L 長さ
# T 時間

X = []
W = [] # list of 1 or -1
for n in range(N):
    x, w = map(int, input().split())
    X.append(x)
    if w == 1:
        W.append(1)
    else:
        W.append(-1)

if DEBUG:
    print('アリの数', N)
    print('長さ', L)
    print('時間', T)
    print('位置', X)
    print('向き', W)

# 0番目のアリがT秒後にどこにいるか
x = (X[0] + W[0] * T) % L
if x < 0:
    x += L

# T秒後のすれ違い回数
cross_num = 0
for i in range(1, N):
    # direction
    if W[0] != W[i]:
        # diffの取り方に注意
        if W[0] == 1:
            x_diff = X[i] - X[0]
        else:
            x_diff = X[0] - X[i]
        if x_diff < 0:
            x_diff += L

        if x_diff // 2 <= T:
            cross_num += 1

            rest_time = T - x_diff // 2
            num = rest_time // (L/2)
            cross_num += num

if DEBUG:
    print('すれ違い回数', int(cross_num))

# ゼッケン番号が衝突回数だけ増える
number = int(0 + W[0] * cross_num)
number = number % N

if DEBUG:
    print('アリ[0] 位置', x, 'ゼッケン番号', number)

# T秒後のアリの位置リスト
Y = []
if DEBUG:
    print('初期位置リスト', X)
for i, initial_x in enumerate(X):
    future_x = (initial_x + W[i] * T) % L
    Y.append(future_x)
if DEBUG:
    print('T秒後の位置リスト', Y)
Y.sort()

# 0番目のアリはソートされたYでどこ
if Y.count(x) == 1:
    zero_ant_index = Y.index(x)
elif Y.count(x) == 2:
    if W[0] == 1:
        zero_ant_index = Y.index(x) + 1
    else:
        zero_ant_index = Y.index(x)

#print('zero ant index', zero_ant_index)
crop = zero_ant_index - number
#print('crop', crop)
Z = Y[crop:] + Y[:crop]

for v in Z:
    print(v)

Submission status: Wrong Answer

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

import sys
import os


DEBUG = False

N, L, T = map(int, input().split())
# N あり
# L 長さ
# T 時間

X = []
W = [] # list of 1 or -1
for n in range(N):
    x, w = map(int, input().split())
    X.append(x)
    if w == 1:
        W.append(1)
    else:
        W.append(-1)

if DEBUG:
    print('アリの数', N)
    print('長さ', L)
    print('時間', T)
    print('位置', X)
    print('向き', W)

# 0番目のアリがT秒後にどこにいるか
x = (X[0] + W[0] * T) % L
if x < 0:
    x += L

# T秒後のすれ違い回数
cross_num = 0
for i in range(1, N):
    # direction
    if W[0] != W[i]:
        x_diff = X[0] - X[i]
        if x_diff < 0:
            x_diff += L

        # 少なくとも1回はすれ違う
        if x_diff / 2 <= T:
            cross_num += 1

            # あと何回すれ違うか
            rest = T - x_diff / 2
            num = rest // T
            cross_num += num

            # 時刻Tでピッタリスレ違いのときはゼッケンを交換しない
            # if rest // T == rest / T:
            #     print('ピッタリ')
            #     cross_num -= 1

if DEBUG:
    print('すれ違い回数', int(cross_num))

# ゼッケン番号が衝突回数だけ増える
number = int(0 + W[0] * cross_num)
number = number % N

if DEBUG:
    print('アリ[0] 位置', x, 'ゼッケン番号', number)

# T秒後のアリの位置リスト
Y = []
if DEBUG:
    print('初期位置リスト', X)
for i, initial_x in enumerate(X):
    future_x = (initial_x + W[i] * T) % L
    Y.append(future_x)
if DEBUG:
    print('T秒後の位置リスト', Y)
Y.sort()

# 0番目のアリはソートされたYでどこ
zero_ant_index = Y.index(x)
crop = zero_ant_index - number
Z = Y[crop:] + Y[:crop]

for v in Z:
    print(v)

Submission status: Wrong Answer

Solution code:
import sys
# sys.stdin = open('c1.in')

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

n_intersections = 0
x0, w0, dest0, i0 = ants[0]
for x, w, dest, i in ants:
    if w != w0:
        d = (w0 * (x - x0) + l) % l
        intersections = 0
        if 2 * t >= d:
            intersections = (2 * t - d) // l + 1
        n_intersections += intersections

res = [0] * n
shift = n_intersections
for i in range(n):
    res[ants[(i+w0*shift)%n][3]] = ants[i][2]

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

Submission status: Wrong Answer

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

import sys
import os


DEBUG = False

N, L, T = map(int, input().split())
# N あり
# L 長さ
# T 時間

X = []
W = [] # list of 1 or -1
for n in range(N):
    x, w = map(int, input().split())
    X.append(x)
    if w == 1:
        W.append(1)
    else:
        W.append(-1)

if DEBUG:
    print('アリの数', N)
    print('長さ', L)
    print('時間', T)
    print('位置', X)
    print('向き', W)

# 0番目のアリがT秒後にどこにいるか
x = (X[0] + W[0] * T) % L
if x < 0:
    x += L

# T秒後のすれ違い回数
cross_num = 0
for i in range(1, N):
    # direction
    if W[0] != W[i]:
        x_diff = X[0] - X[i]
        if x_diff < 0:
            x_diff += L

        # 少なくとも1回はすれ違う
        if x_diff / 2 <= T:
            cross_num += 1

            # あと何回すれ違うか
            rest = T - x_diff / 2
            num = rest // T
            cross_num += num

            # 時刻Tでピッタリスレ違いのときはゼッケンを交換しない
            # if rest // T == rest / T:
            #     print('ピッタリ')
            #     cross_num -= 1

if DEBUG:
    print('すれ違い回数', int(cross_num))

# ゼッケン番号が衝突回数だけ増える
number = int(0 + W[0] * cross_num)
number = number % N

if DEBUG:
    print('アリ[0] 位置', x, 'ゼッケン番号', number)

# T秒後のアリの位置リスト
Y = []
if DEBUG:
    print('初期位置リスト', X)
for i, initial_x in enumerate(X):
    future_x = (initial_x + W[i] * T) % L
    Y.append(future_x)
if DEBUG:
    print('T秒後の位置リスト', Y)

dct = {}
for i, pos in enumerate(Y):
    zekken = (number + i) % N
    if DEBUG:
        print('ant i', i, 'pos', pos, 'zekken', zekken)
    dct[zekken] = pos

for i in range(N):
    print(dct[i])

Submission status: Wrong Answer

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

import sys
import os

DEBUG = False

N, L, T = map(int, input().split())
# N あり
# L 長さ
# T 時間

X = []
W = [] # list of 1 or -1
for n in range(N):
    x, w = map(int, input().split())
    X.append(x)
    if w == 1:
        W.append(1)
    else:
        W.append(-1)

if DEBUG:
    print('アリの数', N)
    print('長さ', L)
    print('時間', T)
    print('位置', X)
    print('向き', W)

# 0番目のアリがT秒後にどこにいるか
x = (X[0] + W[0] * T) % L
if x < 0:
    x += L

# T秒後のすれ違い回数
cross_num = 0
for i in range(1, N):
    # direction
    if W[0] != W[i]:
        x_diff = X[0] - X[i]
        if x_diff < 0:
            x_diff += L

        # 少なくとも1回はすれ違う
        if x_diff / 2 <= T:
            cross_num += 1

            # あと何回すれ違うか
            rest = T - x_diff / 2
            num = rest // T
            cross_num += num

            # 時刻Tでピッタリスレ違いのときはゼッケンを交換しない
            # if rest // T == rest / T:
            #     print('ピッタリ')
            #     cross_num -= 1

if DEBUG:
    print('すれ違い回数', int(cross_num))

# ゼッケン番号が衝突回数だけ増える
number = int(0 + W[0] * cross_num)
number = number % N

if DEBUG:
    print('アリ[0] 位置', x, 'ゼッケン番号', number)

# T秒後のアリの位置リスト
Y = []
if DEBUG:
    print('初期位置リスト', X)
for i, initial_x in enumerate(X):
    future_x = (initial_x + W[i] * T) % L
    Y.append(future_x)
if DEBUG:
    print('T秒後の位置リスト', Y)

# ゼッケン番号0のアリはどこにいる
zekken_0_ant_pos = Y[-number]
zero_ant_index = Y.index(zekken_0_ant_pos)
Z = Y[zero_ant_index:] + Y[:zero_ant_index]
if DEBUG:
    print('Z', Z)

for i, pos in enumerate(Z):
    if DEBUG:
        print('zekken', i, 'pos', pos)
    print(pos)

Submission status: Wrong Answer

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

import sys
import os

DEBUG = False

N, L, T = map(int, input().split())
# N あり
# L 長さ
# T 時間

X = []
W = [] # list of 1 or -1
for n in range(N):
    x, w = map(int, input().split())
    X.append(x)
    if w == 1:
        W.append(1)
    else:
        W.append(-1)

if DEBUG:
    print('アリの数', N)
    print('長さ', L)
    print('時間', T)
    print('位置', X)
    print('向き', W)

# 0番目のアリがT秒後にどこにいるか
x = (X[0] + W[0] * T) % L
if x < 0:
    x += L

# T秒後のすれ違い回数
cross_num = 0
for i in range(1, N):
    # direction
    if W[0] != W[i]:
        x_diff = X[0] - X[i]
        if x_diff < 0:
            x_diff += L

        # 少なくとも1回はすれ違う
        if x_diff / 2 <= T:
            cross_num += 1

            # あと何回すれ違うか
            rest = T - x_diff / 2
            num = rest // T
            cross_num += num

            # 時刻Tでピッタリスレ違いのときはゼッケンを交換しない
            # if rest // T == rest / T:
            #     print('ピッタリ')
            #     cross_num -= 1

if DEBUG:
    print('すれ違い回数', int(cross_num))

# ゼッケン番号が衝突回数だけ増える
number = int(0 + W[0] * cross_num)
while number < 0:
    number += N
number = number % N

if DEBUG:
    print('アリ[0] 位置', x, 'ゼッケン番号', number)

# T秒後のアリの位置リスト
Y = []
if DEBUG:
    print('初期位置リスト', X)
for i, initial_x in enumerate(X):
    future_x = (initial_x + W[i] * T) % L
    Y.append(future_x)
if DEBUG:
    print('T秒後の位置リスト', Y)

zero_ant_index = Y.index(x)
Z = Y[zero_ant_index:] + Y[:zero_ant_index]

answer = [None] * N
for i, pos in enumerate(Z):
    zekken = (number + W[i] * i)
    if zekken < 0:
        zekken += N
    zekken = zekken % N
    if DEBUG:
        print(i, '番目のアリが位置', pos % L, 'に、ゼッケン番号', zekken, 'でいます')
    answer[zekken] = pos % L

for v in answer:
    print(v)