s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s004423164
p03746
u619631862
1546099859
Python
PyPy3 (2.4.0)
py
Runtime Error
1384
77088
654
def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] [n,m]=i2() e=[[] for i in range(n+1)] for i in range(m): [a,b]=i2() e[a].append(b) e[b].append(a) import sys sys.setrecursionlimit(10000) d=[0 for i in range(n+1)] dd=[] def dfs1(v): d[v]=1 for i in range(len(e[v])): if d[e[v][i]]==0: dd.append(e[v][i]) dfs1(e[v][i]) break ddd=[] def dfs2(v): d[v]=1 for i in range(len(e[v])): if d[e[v][i]]==0: ddd.append(e[v][i]) dfs2(e[v][i]) break dfs1(1) dfs2(1) l=ddd[::-1]+[1]+dd s="" for i in l: s+=str(i)+" " print(len(s.split(" "))-1) print(s)
s410868635
p03746
u619631862
1546098457
Python
Python (3.4.3)
py
Runtime Error
520
31072
649
def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] [n,m]=i2() e=[[] for i in range(n+1)] for i in range(m): [a,b]=i2() e[a].append(b) e[b].append(a) import sys sys.setrecursionlimit(10000) d=[0 for i in range(n+1)] dd=[] def dfs1(v): d[v]=1 for i in range(len(e[v])): if d[e[v][i]]==0: dd.append(e[v][i]) dfs1(e[v][i]) break ddd=[] def dfs2(v): d[v]=1 for i in range(len(e[v])): if d[e[v][i]]==0: ddd.append(e[v][i]) dfs2(e[v][i]) break dfs1(1) dfs2(1) print(len(dd)+len(ddd)+1) s="" for i in ddd[::-1]+[1]+dd: s+=str(i)+" " print(s)
s081533847
p03746
u619631862
1546096523
Python
PyPy3 (2.4.0)
py
Runtime Error
1297
77216
649
def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] [n,m]=i2() e=[[] for i in range(n+1)] for i in range(m): [a,b]=i2() e[a].append(b) e[b].append(a) import sys sys.setrecursionlimit(10000) d=[0 for i in range(n+1)] dd=[] def dfs1(v): d[v]=1 for i in range(len(e[v])): if d[e[v][i]]==0: dd.append(e[v][i]) dfs1(e[v][i]) break ddd=[] def dfs2(v): d[v]=1 for i in range(len(e[v])): if d[e[v][i]]==0: ddd.append(e[v][i]) dfs2(e[v][i]) break dfs1(1) dfs2(1) print(len(dd)+len(ddd)+1) s="" for i in ddd[::-1]+[1]+dd: s+=str(i)+" " print(s)
s693684281
p03746
u846150137
1537641188
Python
Python (3.4.3)
py
Runtime Error
617
70832
358
import sys sys.setrecursionlimit(50000) I=lambda:map(int,input().split()) n,m=I() g=[[]for _ in range(n+1)] v=[1 for _ in range(n+1)] v[1]=0 for _ in range(m): a,b=I() g[a]+=[b] g[b]+=[a] def dfs(x): for j in g[x]: if v[j]: v[j]=0 return [j]+dfs(j) break else: return [] z=dfs(1)[::-1]+[1]+dfs(1) print(len(z)) print(*z)
s954940645
p03746
u846150137
1537640608
Python
Python (3.4.3)
py
Runtime Error
496
22900
310
I=lambda:map(int,input().split()) n,m=I() g=[[]for _ in range(n+1)] v=[1 for _ in range(n+1)] v[1]=0 for _ in range(m): a,b=I() g[a]+=[b] g[b]+=[a] def D(x): for j in g[x]: if v[j]: v[j]=0 return [j]+D(j) break else: return [] z=D(1)[::-1]+[1]+D(1) print(len(z)) print(*z)
s987056506
p03746
u846150137
1537639287
Python
Python (3.4.3)
py
Runtime Error
493
22896
323
I=lambda:map(int,input().split()) n,m=I() g=[[]for _ in range(n+1)] v=[0 for _ in range(n+1)] v[1]=1 for _ in range(m): a,b=I() g[a]+=[b] g[b]+=[a] def dfs(x): for j in g[x]: if v[j]==0: v[j]=1 return [j]+dfs(j) break else: return [] z=dfs(1)[::-1]+[1]+dfs(1) print(len(z)) print(*z)
s860188218
p03746
u846150137
1537637876
Python
Python (3.4.3)
py
Runtime Error
484
22904
335
I=lambda:map(int,input().split()) n,m=I() n+=1 g=[[] for _ in range(n)] v=[0 for _ in range(n)] for _ in range(m): a,b=I() g[a]+=[b] g[b]+=[a] l=[] v[1]=1 def bfs(x,l): for j in g[x]: if v[j]==0: v[j]=1 return [j]+bfs(j,l) break else: return l z=bfs(1,l)[::-1]+[1]+bfs(1,l) print(len(z)) print(*z)
s152049073
p03746
u846150137
1537637638
Python
Python (3.4.3)
py
Runtime Error
493
22900
320
I=lambda:map(int,input().split()) n,m=I() n+=1 g=[[] for _ in range(n)] v=[0 for _ in range(n)] for _ in range(m): a,b=I() g[a]+=[b] g[b]+=[a] l=[] v[1]=1 def bfs(x,l): for j in g[x]: if v[j]==0: v[j]=1 return [j]+bfs(j,l) break else: return l z=[1]+bfs(1,l) print(len(z)) print(*z)
s031445642
p03746
u391475811
1532025566
Python
Python (3.4.3)
py
Runtime Error
575
42944
473
from collections import defaultdict ans=[] V=defaultdict(set) N,M=map(int,input().split()) a,b=map(int,input().split()) V[a].add(b) V[b].add(a) ans.append(a) ans.append(b) for i in range(1,M): a,b=map(int,input().split()) V[a].add(b) V[b].add(a) def solve(li): s=li[0] e=li[-1] for v in V[s]: if not(v in li): return solve([v]+li) for v in V[e]: if not(v in li): return solve(li+[v]) print(len(li)) print(*li) return solve(ans)
s830908928
p03746
u455638863
1521083434
Python
Python (3.4.3)
py
Runtime Error
2105
31824
1621
def search(v, A, B, flg, p, c): # if c > 2: # print("v=", v, "flg=", flg, "p=", p, "cnt=", c) if flg[v-1] == 1: # Finish searching and determine if path is found or not. for idx in range(len(A)): if p[0] == A[idx] and flg[B[idx-1]] != 1: return 0 # Start vertex doesn't satisfy the condition. for idx in range(len(B)): if p[0] == B[idx] and flg[A[idx-1]] != 1: return 0 # Start vertex doesn't satisfy the condition. return c # Path is found! flg[v-1] = 1 p.append(v) c += 1 cnt = 0 for idx in range(len(A)): if v == A[idx]: # print("#A", idx, A[idx], B[idx]) cnt = search(B[idx], A, B, flg, p, c) if cnt != 0: break if cnt != 0: return cnt cnt = 0 for idx in range(len(B)): if v == B[idx]: # print("#B", idx, B[idx], A[idx]) cnt = search(A[idx], A, B, flg, p, c) if cnt != 0: break if cnt != 0: return cnt flg[v-1] = 0 p.pop(c-1) return 0 # # Main Routine # st = input() NM = list(map(int,st.split())) #print(NM) ANS = 1 AB = [] C = [] A = [] B = [] cnt = 0 for i in range(0,int(NM[1])): st = input() AB.append(list(map(int,st.split()))) A.append(AB[i][0]) B.append(AB[i][1]) # print("A=", A, "B=", B) # # Start path finding # for i in range(0,int(NM[0])): # Choose start vertex flg = [] # Clear the flag list for j in range(0,int(NM[0])): flg.append(0) v = i+1 # current vertex p = [] cnt = search(v, A, B, flg, p, 0) if cnt != 0: print(cnt) # If all the conditions are met, output the result and stop. print(' '.join([str(x) for x in p])) break
s799869732
p03746
u455638863
1521029105
Python
Python (3.4.3)
py
Runtime Error
2105
31460
1471
def search(v, A, B, flg, p, c, s): #if c > 2: # print("v=", v, "flg=", flg, "p=", p, "cnt=", c) if flg[v-1] == 1: return c flg[v-1] = 1 p.append(v) c += 1 for idx in range(len(A)): if v == A[idx]: cnt = search(B[idx], A, B, flg, p, c, s) if cnt == 0: flg[idx] = 0 return 0 for idx in range(len(B)): if v == B[idx]: cnt = search(A[idx], A, B, flg, p, c, s) if cnt == 0: flg[idx] = 0 return 0 return c # # Main Routine # st = input() NM = list(map(int,st.split())) #print(NM) ANS = 1 AB = [] C = [] A = [] B = [] for i in range(0,int(NM[1])): st = input() AB.append(list(map(int,st.split()))) A.append(AB[i][0]) B.append(AB[i][1]) # print("A=", A, "B=", B) # # Start path finding # for i in range(0,int(NM[1])): # Choose start vertex flg = [] # Clear the flag list for j in range(0,int(NM[0])): flg.append(0) v = AB[i][0] # current vertex s = v # start vertex p = [] cnt = search(v, A, B, flg, p, 0, s) for idx in range(len(A)): if s == A[idx] and B[idx] == 1: cnt = 0 # Start vertex doesn't satisfy the condition. for idx in range(len(B)): if s == B[idx] and A[idx] == 1: cnt = 0 # Start vertex doesn't satisfy the condition. if cnt != 0: print(cnt) # If all the conditions are met, output the result and stop. # print(str(p).replace(',',' ').replace('[','').replace(']','')) print(' '.join([str(x) for x in p])) break
s774838786
p03746
u226155577
1519444502
Python
Python (3.4.3)
py
Runtime Error
17
3064
663
import sys sys.setrecursionlimit(10**6) N, M = map(int, input().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, input().split()) G[a-1].append(b-1) G[b-1].append(a-1) used = [0]*N Q1 = [] Q2 = [] def dfs(v, Q): if used[v]: return 0 used[v] = 1 Q.append(v+1) for w in G[v]: if dfs(w, Q): return 1 return 1 if len(G[0]) == 1: dfs(0, Q1) print(len(Q1)) print(*Q1) else: used[0] = 1 for v in G[0]: if dfs(v, Q1): break for v in G[0]: if dfs(v, Q2): break print(len(Q1) + len(Q2) + 1) print(*Q1[::-1], 1, *Q2)
s415956679
p03746
u602860891
1493249720
Python
Python (3.4.3)
py
Runtime Error
379
11056
853
N, M = list(map(int, input().split())) A = list() B = list() for _ in range(M): a, b = list(map(int, input().split())) A.append(a) B.append(b) index = None for i in range(M): if A.count(A[i]) >= 2 or B.count(A[i]) >= 2 or\ A.count(B[i]) >= 2 or B.count(B[i]) >= 2: index = i break path_points = [ A[index], B[index] ] for i in range(0, M): line = A[i], B[i] if i == index: continue if path_points[0] in line and path_points[-1] not in line: new_point = line[0] if line[1] == path_points[0] else line[1] path_points.insert(0, new_point) elif path_points[-1] in line and path_points[0] not in line: new_point = line[0] if line[1] == path_points[-1] else line[1] path_points.append(new_point) print(len(path_points)) print(" ".join(map(str, path_points)))
s833444124
p03746
u602860891
1493249678
Python
Python (3.4.3)
py
Runtime Error
377
11056
853
N, M = list(map(int, input().split())) A = list() B = list() for _ in range(M): a, b = list(map(int, input().split())) A.append(a) B.append(b) index = None for i in range(M): if A.count(A[i]) >= 2 or B.count(A[i]) >= 2 or\ A.count(B[i]) >= 2 or B.count(B[i]) >= 2: index = i break path_points = [ A[index], B[index] ] for i in range(1, M): line = A[i], B[i] if i == index: continue if path_points[0] in line and path_points[-1] not in line: new_point = line[0] if line[1] == path_points[0] else line[1] path_points.insert(0, new_point) elif path_points[-1] in line and path_points[0] not in line: new_point = line[0] if line[1] == path_points[-1] else line[1] path_points.append(new_point) print(len(path_points)) print(" ".join(map(str, path_points)))
s047325574
p03746
u602860891
1493249362
Python
Python (3.4.3)
py
Runtime Error
390
11064
927
N, M = list(map(int, input().split())) A = list() B = list() for _ in range(M): a, b = list(map(int, input().split())) A.append(a) B.append(b) index = None for i in range(M): if A.count(A[i]) >= 2 or B.count(A[i]) >= 2 or\ A.count(B[i]) >= 2 or B.count(B[i]) >= 2: index = i break path_points = [ A[index], B[index] ] for i in range(1, M): line = A[i], B[i] if i == index: continue if path_points[0] in line and path_points[-1] in line: break elif path_points[0] in line and path_points[-1] not in line: new_point = line[0] if line[1] == path_points[0] else line[1] path_points.insert(0, new_point) elif path_points[-1] in line and path_points[0] not in line: new_point = line[0] if line[1] == path_points[-1] else line[1] path_points.append(new_point) print(len(path_points)) print(" ".join(map(str, path_points)))
s960590052
p03746
u602860891
1493249267
Python
Python (3.4.3)
py
Runtime Error
2104
11064
930
N, M = list(map(int, input().split())) A = list() B = list() for _ in range(M): a, b = list(map(int, input().split())) A.append(a) B.append(b) index = None for i in range(M): if A.count(A[i]) >= 2 and B.count(A[i]) >= 2 or\ A.count(B[i]) >= 2 and B.count(B[i]) >= 2: index = i break path_points = [ A[index], B[index] ] for i in range(1, M): line = A[i], B[i] if i == index: continue if path_points[0] in line and path_points[-1] in line: break elif path_points[0] in line and path_points[-1] not in line: new_point = line[0] if line[1] == path_points[0] else line[1] path_points.insert(0, new_point) elif path_points[-1] in line and path_points[0] not in line: new_point = line[0] if line[1] == path_points[-1] else line[1] path_points.append(new_point) print(len(path_points)) print(" ".join(map(str, path_points)))
s726775468
p03746
u602860891
1493249119
Python
Python (3.4.3)
py
Runtime Error
385
11060
854
N, M = list(map(int, input().split())) A = list() B = list() for _ in range(M): a, b = list(map(int, input().split())) A.append(a) B.append(b) index = None for i in range(M): if A.count(A[i]) >= 2: index = 0 break path_points = [ A[index], B[index] ] for i in range(1, M): line = A[i], B[i] if i == index: continue if path_points[0] in line and path_points[-1] in line: break elif path_points[0] in line and path_points[-1] not in line: new_point = line[0] if line[1] == path_points[0] else line[1] path_points.insert(0, new_point) elif path_points[-1] in line and path_points[0] not in line: new_point = line[0] if line[1] == path_points[-1] else line[1] path_points.append(new_point) print(len(path_points)) print(" ".join(map(str, path_points)))
s802232253
p03746
u602860891
1493248999
Python
Python (3.4.3)
py
Runtime Error
381
11020
817
N, M = list(map(int, input().split())) A = list() B = list() for _ in range(M): a, b = list(map(int, input().split())) A.append(a) B.append(b) index = None for i in range(M): if A.count(A[i]) >= 2: index = 0 break path_points = [ A[index], B[index] ] for i in range(1, M): line = A[i], B[i] if path_points[0] in line and path_points[-1] in line: break elif path_points[0] in line and path_points[-1] not in line: new_point = line[0] if line[1] == path_points[0] else line[1] path_points.insert(0, new_point) elif path_points[-1] in line and path_points[0] not in line: new_point = line[0] if line[1] == path_points[-1] else line[1] path_points.append(new_point) print(len(path_points)) print(" ".join(map(str, path_points)))
s362654382
p03746
u362829196
1492719322
Python
Python (3.4.3)
py
Runtime Error
493
33860
1201
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def checkPath(_path): set_unused = set(allLinked0) - set(_path) unused = list(set_unused) if len(unused) == 0: print(str(len(_path))) out = "" for v in _path: out += str(v) + " " out = out[:-1] print(out) return -1 allLinked = linkage[_path[len(_path) - 1]] set_unused = set(allLinked) - set(_path) unused = list(set_unused) if len(unused) == 0: print(str(len(_path))) out = "" for v in _path: out += str(v) + " " out = out[:-1] print(out) return -1 _path.append(unused[0]) return checkPath(_path[:]) input_line = sys.stdin.readline() n, m = [int(v) for v in input_line.split()] ai = [0] * m bi = [0] * m linkage = {} for i in range(m): input_line = sys.stdin.readline() ai[i] = int(input_line.split()[0]) bi[i] = int(input_line.split()[1]) if not ai[i] in linkage: linkage[ai[i]] = [] if not bi[i] in linkage: linkage[bi[i]] = [] if not bi[i] in linkage[ai[i]]: linkage[ai[i]].append(bi[i]) if not ai[i] in linkage[bi[i]]: linkage[bi[i]].append(ai[i]) for i in range(1, n + 1) : path = [] path.append(i) allLinked0 = linkage[path[0]] if checkPath(path[:]) == -1: quit()
s268599541
p03746
u362829196
1492716659
Python
Python (3.4.3)
py
Runtime Error
660
35180
1606
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def search() : min = m candidate = -1 linked = linkage[path[len(path) - 1]] # print("linked:" + str(linked)) for l in linked: if l in path: continue if counter[l] < min: min = counter[l] candidate = l if candidate == -1: # print("next") return -1 # print("candidate = " + str(candidate)) path.append(candidate) # print("path:" + str(path)) if candidate in allLinked: allLinked.remove(candidate) # print("allLinked2:" + str(allLinked)) if len(allLinked) == 0: print(str(len(path))) out = "" for v in path: out += str(v) + " " out = out[:-1] print(out) quit() return search() input_line = sys.stdin.readline() n, m = [int(v) for v in input_line.split()] ai = [0] * m bi = [0] * m # for i in range(m): # input_line = sys.stdin.readline() # ai[i], bi[i] = [int(v) for v in input_line.split()] counter = {} linkage = {} for i in range(m): input_line = sys.stdin.readline() ai[i] = int(input_line.split()[0]) if not ai[i] in counter: counter[ai[i]] = 0 counter[ai[i]] += 1 bi[i] = int(input_line.split()[1]) if not bi[i] in counter: counter[bi[i]] = 0 counter[bi[i]] += 1 if not ai[i] in linkage: linkage[ai[i]] = [] if not bi[i] in linkage: linkage[bi[i]] = [] if not bi[i] in linkage[ai[i]]: linkage[ai[i]].append(bi[i]) if not ai[i] in linkage[bi[i]]: linkage[bi[i]].append(ai[i]) # print("counter:" + str(counter)) for i in range(n) : path = [] path.append(i + 1) allLinked = sorted(linkage[path[0]]) # print("allLinked:" + str(allLinked)) x = search()
s995642354
p03746
u942033906
1492575520
Python
Python (3.4.3)
py
Runtime Error
809
40052
1165
N,M = map(int,input().split()) edges = [[] for i in range(N)] degrees = [(0,i) for i in range(N)] for i in range(M): a,b = map(int, input().split()) edges[a-1].append(b-1) edges[b-1].append(a-1) degrees[a-1] = (degrees[a-1][0] + 1, a-1) degrees[b-1] = (degrees[b-1][0] + 1, b-1) sdegrees = sorted(degrees) path = [] next = sdegrees[0][1] firstNeighbor = edges[next] rev = False while True: path.append(str(next+1)) if next in firstNeighbor: firstNeighbor.remove(next) choose = [] for node in edges[next]: edges[node].remove(next) tup = (degrees[node][0]-1, node) degrees[node] = tup choose.append(tup) sdegrees = sorted(choose) next, degree = sdegrees[0][1], sdegrees[0][0] if degree == 0: path.append(str(next+1)) first = int(path[0]) - 1 if not rev and len(firstNeighbor) != 0: rev = True path.reverse() choose = [] for node in firstNeighbor: tup = (degrees[node][0]-1, node) degrees[node] = tup choose.append(tup) sdegrees = sorted(choose) next, degree = sdegrees[0][1], sdegrees[0][0] if degree != 0: continue else: path.append(str(next+1)) break print(len(path)) print(" ".join(path))
s452645613
p03746
u942033906
1492574441
Python
Python (3.4.3)
py
Runtime Error
825
40068
1037
def rm(nodes, i): if i in nodes: nodes.remove(i) return nodes N,M = map(int,input().split()) edges = [[] for i in range(N)] degrees = [(0,i) for i in range(N)] for i in range(M): a,b = map(int, input().split()) edges[a-1].append(b-1) edges[b-1].append(a-1) degrees[a-1] = (degrees[a-1][0] + 1, a-1) degrees[b-1] = (degrees[b-1][0] + 1, b-1) sdegrees = sorted(degrees) path = [] next = sdegrees[0][1] degrees[next] = (degrees[next][0]-1, next) firstNeighbor = edges[next] rev = False while True: path.append(str(next+1)) if next in firstNeighbor: firstNeighbor.remove(next) choose = [] for node in edges[next]: edges[node].remove(next) tup = (degrees[node][0]-1, node) degrees[node] = tup choose.append(tup) sdegrees = sorted(choose) next, degree = sdegrees[0][1], sdegrees[0][0] if degree == 0: path.append(str(next+1)) first = int(path[0]) - 1 if len(firstNeighbor) != 0 and not rev: path.reverse() next = firstNeighbor[0] rev = True continue break print(len(path)) print(" ".join(path))
s811617573
p03746
u942033906
1492574161
Python
Python (3.4.3)
py
Runtime Error
846
40068
1021
def rm(nodes, i): if i in nodes: nodes.remove(i) return nodes N,M = map(int,input().split()) edges = [[] for i in range(N)] degrees = [(0,i) for i in range(N)] for i in range(M): a,b = map(int, input().split()) edges[a-1].append(b-1) edges[b-1].append(a-1) degrees[a-1] = (degrees[a-1][0] + 1, a-1) degrees[b-1] = (degrees[b-1][0] + 1, b-1) sdegrees = sorted(degrees) path = [] next = sdegrees[0][1] degrees[next] = (degrees[next][0]-1, next) firstNeighbor = edges[next] while True: path.append(str(next+1)) if next in firstNeighbor: firstNeighbor.remove(next) choose = [] for node in edges[next]: edges[node].remove(next) tup = (degrees[node][0]-1, node) degrees[node] = tup choose.append(tup) sdegrees = sorted(choose) next, degree = sdegrees[0][1], sdegrees[0][0] if degree == 0: path.append(str(next+1)) first = int(path[0]) - 1 if len(firstNeighbor) != 0: path.reverse() next = firstNeighbor[0] firstNeighbor = [] continue break print(len(path)) print(" ".join(path))
s864592030
p03746
u942033906
1492573732
Python
Python (3.4.3)
py
Runtime Error
828
40068
998
def rm(nodes, i): if i in nodes: nodes.remove(i) return nodes N,M = map(int,input().split()) edges = [[] for i in range(N)] degrees = [(0,i) for i in range(N)] for i in range(M): a,b = map(int, input().split()) edges[a-1].append(b-1) edges[b-1].append(a-1) degrees[a-1] = (degrees[a-1][0] + 1, a-1) degrees[b-1] = (degrees[b-1][0] + 1, b-1) sdegrees = sorted(degrees) path = [] next = sdegrees[0][1] degrees[next] = (degrees[next][0]-1, next) firstNeighbor = edges[next] while True: path.append(str(next+1)) if next in firstNeighbor: firstNeighbor.remove(next) choose = [] for node in edges[next]: edges[node].remove(next) tup = (degrees[node][0]-1, node) degrees[node] = tup choose.append(tup) sdegrees = sorted(choose) next, degree = sdegrees[0][1], sdegrees[0][0] if degree == 0: path.append(str(next+1)) first = int(path[0]) - 1 if degrees[first][0] != 0: path.reverse() next = firstNeighbor[0] continue break print(len(path)) print(" ".join(path))
s021149552
p03746
u272028993
1492568580
Python
Python (2.7.6)
py
Runtime Error
352
21860
733
from collections import deque def dfs1(now,visited,ans): visited[now]=True for nx in g[now]: if not visited[nx]: ans.appendleft(nx) dfs1(nx,visited,ans) break def dfs2(now,visited,ans): visited[now]=True for nx in g[now]: if not visited[nx]: ans.append(nx) dfs2(nx,visited,ans) break n,m=map(int,raw_input().split()) g=[[] for _ in xrange(n)] for i in xrange(m): a,b=map(int,raw_input().split()) a-=1;b-=1 g[a].append(b) g[b].append(a) ans=deque([a,b]) visited=[False]*n visited[a]=True visited[b]=True dfs1(a,visited,ans) dfs2(b,visited,ans) print len(ans) for i in xrange(len(ans)): print ans[i]+1, print
s485875393
p03746
u332385682
1492311161
Python
Python (3.4.3)
py
Runtime Error
294
23396
1534
import sys from collections import deque def solve(): def dfs1(u, path, visited): for w in Adj[u]: if not visited[w]: path.append(w) visited[w] = True dfs1(w, path, visited) return def dfs2(u, path, visited): for w in Adj[u]: if not visited[w]: path.appendleft(w) visited[w] = True dfs2(w, path, visited) return N, M = map(int, sys.stdin.readline().split()) Adj = [[] for i in range(N)] for i in range(M): a, b = map(int, sys.stdin.readline().split()) a, b = a-1, b-1 Adj[a].append(b) Adj[b].append(a) if any(len(v) == 1 for v in Adj): for i, v in enumerate(Adj): if len(v) == 1: s = i break path = [s] visited = [False] * N visited[s] = True dfs1(s, path, visited) path = [i + 1 for i in path] print(len(path)) print(*path) else: s = 0 path = deque([0]) visited = [False] * N visited[s] = True dfs1(s, path, visited) dfs2(s, path, visited) path = [i + 1 for i in path] print(len(path)) print(*path) def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None if __name__ == '__main__': solve()
s929462499
p03746
u777923818
1492310061
Python
Python (3.4.3)
py
Runtime Error
465
32728
993
# -*- coding: utf-8 -*- from queue import Queue N, M = [int(n) for n in input().split()] graph = {n: [] for n in range(1, N+1)} for m in range(M): A, B = [int(n) for n in input().split()] graph[A].append(B) graph[B].append(A) starts_ = sorted(graph.keys(), key=lambda x: len(graph[x])) starts = iter(starts_) result_path = [] for start in starts: q = Queue() needs_start = graph[start] q.put([start]) while not q.empty(): path = q.get() for t in graph[path[-1]]: if t in path: continue if len(set(needs_start + graph[t]) - set(path + [t])) == 0: result_path = path + [t] q = Queue() break else: if len(path + t) < N: q.put(path+[t]) if len(result_path) > 0: break print(len(result_path)) result = "" for r in result_path: result += " {}".format(r) print(result[1:])
s235596753
p03746
u402629484
1492310003
Python
Python (3.4.3)
py
Runtime Error
2105
21296
405
N, M = map(int, input().split()) s = [[] for i in range(M)] for i in range(M): a, b = map(int, input().split()) s[a - 1].append(b) s[b - 1].append(a) def go(path): node = path[-1] for next in s[node - 1]: if next not in path: path.append(next) return True return False path = [1] while go(path): pass print(len(path)) print(*path, sep=' ')
s846284699
p03746
u402629484
1492309878
Python
Python (3.4.3)
py
Runtime Error
2106
37424
402
N, M = map(int, input().split()) s = [set() for i in range(M)] for i in range(M): a, b = map(int, input().split()) s[a - 1].add(b) s[b - 1].add(a) def go(path): node = path[-1] for next in s[node - 1]: if next not in path: path.append(next) return True return False path = [1] while go(path): pass print(len(path)) print(*path, sep=' ')
s884371400
p03746
u872191059
1492309820
Python
Python (3.4.3)
py
Runtime Error
575
30212
808
N, M = map(int, input().split()) As = [] Bs = [] Gr = {} for _ in range(M): A, B = map(int, input().split()) As.append(A) Bs.append(B) if A in Gr: Gr[A].append(B) else: Gr[A] = [B] if B in Gr: Gr[B].append(A) else: Gr[B] = [A] def check(path): return set(Gr[path[0]]) & set(path) == set(Gr[path[0]]) and set(Gr[path[-1]]) & set(path) == set(Gr[path[-1]]) def forward(path): tmp = path if check(path): return path else: for v in Gr[path[-1]]: if v not in path: tmp.append(v) return forward(tmp) return [] for i in range(M): path = forward([As[i], Bs[i]]) if 1 <= len(path): print(len(path)) print(' '.join(map(str, path))) break
s424950115
p03746
u402629484
1492309716
Python
Python (3.4.3)
py
Runtime Error
487
37432
385
N, M = map(int, input().split()) s = [set() for i in range(M)] for i in range(M): a, b = map(int, input().split()) s[a - 1].add(b) s[b - 1].add(a) def go(path): node = path[-1] for next in s[node - 1]: if next not in path: path.append(next) go(path) return path = [1] go(path) print(len(path)) print(*path, sep=' ')
s113743818
p03746
u039623862
1492309052
Python
PyPy3 (2.4.0)
py
Runtime Error
983
85280
1556
def dijkstra_path(V, source, target): import heapq visited = [False] * V prev = [-1 for i in range(V)] dist = [float('inf')] * V dist[source] = 0 h = [(0, source)] while h: c, v = heapq.heappop(h) if visited[v]: continue visited[v] = True for i in range(len(graph[v])): t = graph[v][i] nc = c + 1 if dist[t] > nc: dist[t] = nc heapq.heappush(h, (nc, t)) prev[t] = v path = [target] while path[-1] != source and path[-1] != -1: path.append(prev[path[-1]]) return path[::-1] def all_contains(s, a): return all([x in s for x in a]) n,m=map(int, input().split()) graph = [[] for i in range(n)] cnt = [0 for i in range(n)] for i in range(m): a,b = map(int, input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) cnt[a-1] += 1 cnt[b-1] += 1 start = 0 end = 1 for i in range(n): if cnt[i]<=cnt[start]: end = start start = i def main(): q = [] q.append((start, -1)) while q: v, path = q.pop() path.append(v) if all_contains(path, graph[v]) and all_contains(path, graph[path[0]]): return path for nv in graph[v]: if nv not in path: q.append((nv, path[:])) if __name__ == '__main__': if cnt[end] == 1: res = dijkstra_path(n, start, end) else: res = main() print(len(res)) print(' '.join([str(x+1) for x in res]))
s723371124
p03746
u402629484
1492308709
Python
Python (3.4.3)
py
Runtime Error
529
37416
430
N, M = map(int, input().split()) s = [set() for i in range(M)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 s[a].add(b) s[b].add(a) def go(path): node = path[-1] for next in s[node]: if next not in path: path.append(next) go(path) return path = [0] go(path) for i in range(len(path)): path[i] += 1 print(path[-1]) print(*path)
s570188732
p03746
u402629484
1492308207
Python
Python (3.4.3)
py
Runtime Error
610
37456
431
N, M = map(int, input().split()) s = [set() for i in range(M)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 s[a].add(b) s[b].add(a) def go(path): node = path[-1] for next in s[node]: if next not in path: path.append(next) go(path) return path = [0] go(path) print(len(path)) for i in range(len(path)): path[i] += 1 print(*path)
s370936819
p03746
u104282757
1492308199
Python
Python (3.4.3)
py
Runtime Error
408
30180
1032
# B from collections import deque # input N, M = map(int, input().split()) G = dict() for n in range(1, N+1): G[n] = [] for _ in range(M): A, B = map(int, input().split()) G[A].append(B) G[B].append(A) # find minimum degree s = np.argmin(np.array([len(G[k]) for k in range(1, N+1)])) + 1 targets = dict() for a in G[s]: targets[a] = 1 # BFS t = G[s][0] pt = [s, t] del targets[t] while len(targets) > 0: ques = deque() visited = [0]*(N+1) for a in pt: visited[a] = 1 ques.append([t, pt]) end = 0 while len(ques) > 0 and end == 0: q = ques.popleft() s = q[0] pt = q[1] for t in G[s]: if visited[t] == 1: pass elif t in targets.keys(): pt.append(t) end = 1 del targets[t] break else: visited[t] = 1 ques.append([t, pt+[t]]) print(len(pt)) print(" ".join([str(a) for a in pt]))
s162688386
p03746
u402629484
1492308061
Python
Python (3.4.3)
py
Runtime Error
541
37396
414
N, M = map(int, input().split()) s = [set() for i in range(M)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 s[a].add(b) s[b].add(a) def go(path): node = path[-1] for next in s[node]: if next not in path: path.append(next) go(path) return path = [0] go(path) print(len(path)) for n in path: print(n + 1, end=' ')
s860491737
p03746
u945080461
1492306811
Python
Python (2.7.6)
py
Runtime Error
103
20100
2076
from sys import stdin from itertools import repeat def main(): n, m = map(int, stdin.readline().split()) dat = map(int, stdin.read().split(), repeat(10, 2 * m)) la = [None] * (n + 1) xt = [None] * len(dat) j = 0 for i in xrange(m): x, y = dat[j:j+2] xt[j] = la[y] xt[j+1] = la[x] la[y] = j la[x] = j + 1 j += 2 done = [None] * (n + 1) x = 1 po = [] while 1: po.append(x) done[x] = 1 y = la[x] while y is not None: z = dat[y] if done[z] is None: x = z break y = xt[y] else: break pa = [] while 1: pa.append(x) done[x] = 1 y = la[x] while y is not None: z = dat[y] if done[z] is None: x = z break y = xt[y] else: break po = po[::-1] + pa[1:] print len(po) print ' '.join(map(str, po)) main() from sys import stdin from itertools import repeat def main(): n, m = map(int, stdin.readline().split()) dat = map(int, stdin.read().split(), repeat(10, 2 * m)) la = [None] * (n + 1) xt = [None] * len(dat) j = 0 for i in xrange(m): x, y = dat[j:j+2] xt[j] = la[y] xt[j+1] = la[x] la[y] = j la[x] = j + 1 j += 2 done = [None] * (n + 1) x = 1 po = [] while 1: po.append(x) done[x] = 1 y = la[x] while y is not None: z = dat[y] if done[z] is None: x = z break y = xt[y] else: break pa = [] while 1: pa.append(x) done[x] = 1 y = la[x] while y is not None: z = dat[y] if done[z] is None: x = z break y = xt[y] else: break po = po[::-1] + pa[1:] print len(po) print ' '.join(map(str, po)) main()
s790915624
p03746
u237316771
1492306293
Python
Python (2.7.6)
py
Runtime Error
405
29940
672
n, m = [int(x) for x in raw_input().split()] t = [[] for i in xrange(m)] for i in xrange(m): a, b = [int(x) - 1 for x in raw_input().split()] t[a].append(b) t[b].append(a) pre = [a] pos = [b] visited = {a, b} while 1: for ne in t[pre[-1]]: if ne not in visited: visited.add(ne) pre.append(ne) break else: break while 1: for ne in t[pos[-1]]: if ne not in visited: visited.add(ne) pos.append(ne) break else: break print(len(pre) + len(pos)) print(" ".join(str(x + 1) for x in reversed(pre)) + " " + " ".join(str(x + 1) for x in pos))
s902989626
p03747
u842170774
1599190640
Python
PyPy3 (7.3.0)
py
Runtime Error
258
92296
610
# AGC C Ants on a Circle f=lambda:map(int,input().split()) N,L,T=f() X,W=[],[] for _ in [0]*N: x,w=f() X.append(x) W.append(w) if W[0]==2: X[0]+=L col=0 for j in range(N): if W[j]==W[0]: continue else: if W[0]>0: if 2*T-(X[j]-X[0])>=0: col+=1+(2*T-(X[j]-X[0]))//L else: col+=0 else: col-=max((2*T-X[j]+X[0])//L,0) col=col%N X2=[(X[i]+(3-2*W[i])*(T-0.01)) % L for i in range(N)] ant0=(X2[0],col) X2.sort() x=X2.index(ant0[0]) for i in range(x-col-N,x-col): print(round(X2[i]))
s364083343
p03747
u892251744
1593222391
Python
PyPy3 (7.3.0)
py
Runtime Error
205
87020
1850
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, L, T = map(int, input().split()) M, T = divmod(T, L) X = [] W = [] for _ in range(N): x, w = map(int, input().split()) X.append(x) W.append(w) if N == 1: if W[0] == 1: print((X[0] + T)%L) else: print((X[0] - T)%L) exit() Y = [] for i in range(N): if W[i] == 1: Y.append(((X[i] + T)%L, 1)) else: Y.append(((X[i] - T)%L, 2)) Y.sort(key=lambda p: p[0]) if W[0] == 1: y0 = (X[0] + T)%L for i in range(N): if Y[i][0] == y0: i0 = i break S = 0 i = 0 idx = (M * W.count(2) * 2)%N while True: i = (i+1)%N if i: S += X[i] - X[i-1] else: S += L - (X[-1] - X[0]) if S >= T*2: break if W[i] == 2: idx = (idx+1)%N ans = [0] * N for i in range(N): ans[(idx+i)%N] = Y[(i0+i)%N][0] else: assert False y0 = (X[0] - T) % L for i in range(N-1, -1, -1): if Y[i][0] == y0: i0 = i break S = 0 i = 0 idx = (M * W.count(1) * 2)%N while True: i = (i - 1) % N if i != N-1: S += X[i+1] - X[i] else: S += L - (X[-1] - X[0]) if S >= T * 2: break if W[i] == 1: idx = (idx - 1)%N ans = [0] * N for i in range(0, -N, -1): ans[(idx + i) % N] = Y[(i0+i)%N][0] for a in ans: print(a) if __name__ == '__main__': main()
s283982169
p03747
u892251744
1593220738
Python
PyPy3 (7.3.0)
py
Runtime Error
193
87576
1793
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, L, T = map(int, input().split()) T %= L X = [] W = [] for _ in range(N): x, w = map(int, input().split()) X.append(x) W.append(w) if N == 1: if W[0] == 1: print((X[0] + T)%L) else: print((X[0] - T)%L) exit() Y = [] for i in range(N): if W[i] == 1: Y.append(((X[i] + T)%L, 1)) else: Y.append(((X[i] - T)%L, 2)) Y.sort(key=lambda p: p[0]) if W[0] == 1: y0 = (X[0] + T)%L for i in range(N): if Y[i][0] == y0: i0 = i break S = 0 i = 0 idx = 0 while True: i = (i+1)%N if i: S += X[i] - X[0] else: S += L - (X[0] - X[-1]) if S >= T*2: break if W[i] == 2: idx = (idx+1)%N ans = [0] * N for i in range(N): ans[(idx+i)%N] = Y[(i0+i)%N][0] else: assert False y0 = (X[0] - T) % L for i in range(N-1, -1, -1): if Y[i][0] == y0: i0 = i break S = 0 i = 0 idx = 0 while True: i = (i - 1) % N if i != N-1: S += X[i+1] - X[i] else: S += L - (X[-1] - X[0]) if S >= T * 2: break if W[i] == 1: idx = (idx - 1)%N ans = [0] * N for i in range(0, -N, -1): ans[(idx + i) % N] = Y[(i0+i)%N][0] for a in ans: print(a) if __name__ == '__main__': main()
s478886573
p03747
u892251744
1593219370
Python
PyPy3 (7.3.0)
py
Runtime Error
197
85396
1644
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, L, T = map(int, input().split()) T %= L X = [] W = [] for _ in range(N): x, w = map(int, input().split()) X.append(x) W.append(w) if N == 1: if W[0] == 1: print((X[0] + T)%L) else: print((X[0] - T)%L) exit() Y = [] for i in range(N): if W[i] == 1: Y.append(((X[i] + T)%L, 1)) else: Y.append(((X[i] - T)%L, 2)) Y.sort(key=lambda p: p[0]) if W[0] == 1: y0 = (X[0] + T)%L for i in range(N): if Y[i][0] == y0: i0 = i break S = 0 i = i0 idx = 0 while True: i = (i+1)%N S += (Y[i][0] - Y[i-1][0])%L if S > T*2: break if W[i] == 2: idx = (idx+1)%N ans = [0] * N for i in range(N): ans[(idx+i)%N] = Y[(i0+i)%N][0] else: assert False y0 = (X[0] - T) % L for i in range(N-1, -1, -1): if Y[i][0] == y0: i0 = i break S = 0 i = i0 idx = 0 while True: i = (i - 1) % N S += (Y[i][0] - Y[(i+1)%N][0])%L if S > T * 2: break if W[i] == 1: idx = (idx - 1)%N ans = [0] * N for i in range(N): ans[(idx + i) % N] = Y[(i0+i)%N][0] for a in ans: print(a) if __name__ == '__main__': main()
s406678594
p03747
u146346223
1592165358
Python
Python (3.4.3)
py
Runtime Error
17
3064
323
n, l, t = map(int, input().split()) arr = [] for i in range(n): x, w = map(int, input().split()) if w == 1: arr.append((x+t) % l) s += (x+t) // l else: # W == 2: arr.append((x-t) % l) s += (x-t) // l arr.sort() s %= n arr = arr[s:] + arr[:s] print(*[i for i in arr], sep='\n')
s077684191
p03747
u868982936
1591308763
Python
Python (3.4.3)
py
Runtime Error
17
2940
584
import sys readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N, L, T = map(int, readline().split()) position = [] count = 0 for i in range(N): x,w = map(int, readline().split()) if w==1: count += (x+T)//L position.append((x+T)%L) else: if x-T<0: count += (x-T)//L position.append((x-T)%L) position.sort() count %= N ans = position[count:] + position[:count] for i in range(N): print(ans[i])
s422088433
p03747
u868982936
1591308568
Python
Python (3.4.3)
py
Runtime Error
17
2940
573
import sys readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N, L, T = map(int, readline().split()) position = [] cnt = 0 for i in range(N): x,w = map(int, readline().split()) if w==1: cnt += (x+T)//L position.append((x+T)%L) else: if x-T<0: cnt += (x-T)//L position.append((x-T)%L) position.sort() cnt %= N ans = position[cnt:] + position[:cnt] for i in range(N): print(ans[i])
s178927960
p03747
u868982936
1591308525
Python
Python (3.4.3)
py
Runtime Error
18
2940
576
import sys readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N, L, T = map(int, readline().split()) position = [] cnt = 0 for i in range(N): x,w = map(int, readline().split()) if w==1: cnt += (x+T)//L position.append((x+T)%L) else: if x-T<0: cnt += (x-T)//L position.append((x-T)%L) position.sort() cnt %= N ans = position[count:] + position[:count] for i in range(N): print(ans[i])
s337756552
p03747
u868982936
1591307957
Python
Python (3.4.3)
py
Runtime Error
17
3064
578
import sys readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N, L, T = map(int, readline().split()) position = [] cnt = 0 for i in range(N): x, w = map(int, input().split()) if w == 1: cnt += (x - T)//L position.append((x-T)%L) else: if x-T < 0: cnt += (x - T)//L position.append((x - T)%L) position.sort() cnt %= N ans = position[cnt:] + position[:cnt] for i in range(N): print(ans[i])
s809504843
p03747
u193264896
1591281637
Python
Python (3.4.3)
py
Runtime Error
236
8944
751
import sys readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N, L, T = map(int, readline().split()) position = [] #0をL-1からーに時計回りに超える場合は+1 #0からL-1に反時計回りに超える場合は-1 count = 0 for i in range(N): x,w = map(int, readline().split()) if w==1: count += (x+T)//L position.append((x+T)%L) else: if x-T<0: count += (x-T+1)//L position.append((x-T)%L) position.sort() if count>=0: ans = position[count:] + position[:count] for i in range(N): print(ans[i]) if __name__ == '__main__': main()
s723042914
p03747
u193264896
1591281517
Python
Python (3.4.3)
py
Runtime Error
186
11756
721
import sys readline = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 8) INF = float('inf') MOD = 10 ** 9 + 7 def main(): N, L, T = map(int, readline().split()) position = [] #0をL-1からーに時計回りに超える場合は+1 #0からL-1に反時計回りに超える場合は-1 count = 0 for i in range(N): x,w = map(int, readline().split()) if w==1: count += (x+T)//L position.append((x+T)%L) else: if x-T<0: count += (x-T+1)//L position.append((x-T)%L) position.sort() if count>=0: ans = position[count:] + position[:count] print(ans) if __name__ == '__main__': main()
s947765033
p03747
u754022296
1591091543
Python
Python (3.4.3)
py
Runtime Error
251
29088
550
import sys input = sys.stdin.readline n, l, t = map(int, input().split()) XW = [list(map(int, input().split())) for _ in range(n)] L = [] for i, xw in enumerate(XW): x, w = xw if w == 1: L.append((x+t)%l) else: L.append((x-t)%l) L.sort() x_0, w_0 = XW[0] b = 0 for x, w in XW[1:]: if w_0 == w: continue if w_0 == 1: if x-x_0 > 2*t: continue b += 1 + (2*t - (x-x_0)) // l else: if l-(x-x_0) > 2*t: continue b -= 1 + (2*t - (l-(x-x_0))) // l m = L.index(L[b]) for i in range(m, m+n): print(L[i%n])
s466364551
p03747
u105290050
1590031540
Python
Python (3.4.3)
py
Runtime Error
2104
11020
521
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 x: print(int(x[i]))
s601032053
p03747
u151820863
1588804997
Python
Python (3.4.3)
py
Runtime Error
17
3064
2096
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 def print_snapshot(): for ant in snapshot: no = ant['no'] x = ant['x'] w = ant['w'] print(f'{no}: x={x}, w={w}') t = 0 #print(f'----- t = {t} -----') #print_snapshot() for i in range(T): t += 1 snapshot = move() #print(f'----- t = {t} -----') #print_snapshot() for s in snapshot: print(s['x'])
s111823716
p03747
u591524911
1588422650
Python
Python (3.4.3)
py
Runtime Error
452
18192
805
N, L, T = map(int, input().split()) lst = [tuple(map(int, input().split())) for i in range(N)] lst2 = [] count = 0 a = T % L base = None for tpl in lst: if tpl[1] == 1: lst2.append(tpl[0]+T) elif tpl[1] == 2: lst2.append(tpl[0]-T) if base == None: base = tpl elif tpl[1] != base[1]: if (tpl[0]-base[0]) <= a and base[1] ==1: count += 1 elif a < (tpl[0]-base[0]) <= 2*a and base[1] ==1: count += 2 elif (L-tpl[0]+base[0]) <= a and base[1] == 2: count -= 1 elif a < (L-tpl[0]+base[0]) <= 2*a and base[1] == 2: count -= 2 print(count) count = count % N for i in range(N): lst2[i] = lst2[i] % L #print(lst2) #print(count) for i in range(lst2): print(lst2[(i+count) % N])
s305176970
p03747
u719181921
1587263623
Python
Python (3.4.3)
py
Runtime Error
2104
11924
210
s = input() n = len(s) f = '' for i in range(2**(n-1)): b = format(i, 'b').zfill(n) for j in range(n): if b[j] == '1': f += '+' + s[j] else: f += s[j] f+= '+' print(eval(f[:len(f)-1]))
s524258781
p03747
u719181921
1587263556
Python
Python (3.4.3)
py
Runtime Error
2104
11940
210
s = input() n = len(s) f = '' for i in range(2**(n-1)): b = format(i, 'b').zfill(n) for j in range(n): if b[j] == '1': f += '+' + s[j] else: f += s[j] f+= '+' print(eval(f[:len(f)-1]))
s511303391
p03747
u095021077
1586660081
Python
Python (3.4.3)
py
Runtime Error
462
31052
700
N, L, T=map(int, input().split()) XW=[list(map(int, input().split())) for _ in range(N)] X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)] X_.sort() A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L P0_=X_.index(A0_) if P0_>0: X_=X_[P0_:]+X_[:P0_] if XW[0][1]==1: C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N) else: C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N) if X_[0]==X_[1] and XW[0][1]==1: C0_=round((C0_-1)%N) ''' if C0_>0: X_=X_[N-C0_:]+X_[:N-C0_] ''' print(*X_, sep='\n')
s104324515
p03747
u095021077
1586659935
Python
Python (3.4.3)
py
Runtime Error
463
31660
695
N, L, T=map(int, input().split()) XW=[list(map(int, input().split())) for _ in range(N)] X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)] X_.sort() A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L P0_=X_.index(A0_) if P0_>0: X_=X_[P0_:]+X_[:P0_] if XW[0][1]==1: C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N) else: C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N) if X_[0]==X_[1] and XW[0][1]==1: C0_=round((C0_-1)%N) if C0_>0: X_=X_[N-C0_:]+X_[:N-C0_] print(*X_, sep='\n')
s981330529
p03747
u095021077
1586659810
Python
Python (3.4.3)
py
Runtime Error
459
31548
688
N, L, T=map(int, input().split()) XW=[list(map(int, input().split())) for _ in range(N)] X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)] X_.sort() A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L P0_=X_.index(A0_) if P0_>0: X_=X_[P0_:]+X_[:P0_] if XW[0][1]==1: C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N) else: C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N) if X_[0]==X_[1] and XW[0][1]==1: C0_=(C0_-1)%N if C0_>0: X_=X_[N-C0_:]+X_[:N-C0_] print(*X_, sep='\n')
s974995608
p03747
u095021077
1586659726
Python
Python (3.4.3)
py
Runtime Error
452
31548
702
N, L, T=map(int, input().split()) XW=[list(map(int, input().split())) for _ in range(N)] X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)] X_.sort() A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L P0_=X_.index(A0_) if P0_>0: X_=X_[P0_:]+X_[:P0_] if XW[0][1]==1: C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N) else: C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N) if X_[0]==X_[1] and XW[0][1]==1: if C0_>0: C0_=(C0_-1)%N if C0_>0: X_=X_[N-C0_:]+X_[:N-C0_] print(*X_, sep='\n')
s043250135
p03747
u095021077
1586659492
Python
Python (3.4.3)
py
Runtime Error
446
31660
681
N, L, T=map(int, input().split()) XW=[list(map(int, input().split())) for _ in range(N)] X_=[(XW[i][0]+T)%L if XW[i][1]==1 else (XW[i][0]-T)%L for i in range(N)] X_.sort() A0_=(XW[0][0]+T)%L if XW[0][1]==1 else (XW[0][0]-T)%L P0_=X_.index(A0_) if P0_>0: X_=X_[P0_:]+X_[:P0_] if XW[0][1]==1: C0_=round(sum([(T-(XW[i][0]-XW[0][0])/2)//(L/2)+1 if XW[i][1]!=1 and (XW[i][0]-XW[0][0])/2<=T else 0 for i in range(1, N)])%N) else: C0_=round(N-sum([(T-(XW[0][0]+L-XW[i][0])/2)//(L/2)+1 if XW[i][1]!=2 and (XW[0][0]+L-XW[i][0])/2<=T else 0 for i in range(1, N)])%N) if X_[0]==X_[1] and XW[0][1]==1: C0_-=1 if C0_>0: X_=X_[N-C0_:]+X_[:N-C0_] print(*X_, sep='\n')
s647719166
p03747
u106778233
1586020733
Python
Python (3.4.3)
py
Runtime Error
17
2940
447
n,l,T=map(int,input().split()) from collections import deque a=deque() b=deque() for i in range(n): q,ww=map(int,input().spilt()) w=3-2*ww a.append([(j*w*2+2*q)%(2*l) for j in range(1,2*T+1)] b.append(i) for k in range(2*T): for i in range(n): for j in range(i+1,n): if a[i][k]=a[j][k]: b[i]=b[k] for i in range(n) print(a[b[i]][-1]//2 if a[b[i]][-1]//2 else n)
s104048814
p03747
u278183305
1584915747
Python
Python (3.4.3)
py
Runtime Error
2123
211956
1641
# input n,l,time = map(int, input().split()) ant = [0] * n v = [0] * n for i in range(n): ant[i],v[i] = map(int, input().split()) # plus def plus(point): if l <= point+1: res = 0 else: res = point+1 return res # minus def minus(point): if 0 > point-1: res = l-1 else: res = point-1 return res def swap(i): if v[i] == 1: v[i] = 2 else: v[i] = 1 # process for time in range(time): # flg flgCollision = [{0:0}] * l # coliision for i in range(n): # collide at same point. if flgCollision[ant[i]] != {0:0}: swap(i) swap([k for k in flgCollision[ant[i]].keys()][0]) # memo flg num:vec flgCollision[ant[i]] = {i:v[i]} aa = ant.copy() # walk for i in range(n): if v[i] == 1: ant[i] = plus(ant[i]) else: ant[i] = minus(ant[i]) for i in range(n): if aa[i] < l-1: if v[i] == 1 and [vv for vv in flgCollision[aa[i]+1].values()][0] == 2: swap(i) swap([k for k in flgCollision[aa[i]+1].keys()][0]) ant[i], ant[[k for k in flgCollision[aa[i]+1].keys()][0]] = ant[[k for k in flgCollision[aa[i]+1].keys()][0]], ant[i] else: if v[i] == 1 and [vv for vv in flgCollision[0].values()][0] == 2: swap(i) swap([k for k in flgCollision[0].keys()][0]) ant[i], ant[[k for k in flgCollision[0].keys()][0]] = ant[[k for k in flgCollision[0].keys()][0]], ant[i] for ants in ant: print(ants)
s346712766
p03747
u638795007
1584554598
Python
Python (3.4.3)
py
Runtime Error
838
61524
3943
def examA(): N = I() A = LI() ans = 1 flag = None for i in range(N-1): cur = A[i+1] - A[i] if not flag: if cur<0: flag = "d" elif cur>0: flag = "u" else: if cur<0 and flag=="u": flag = None ans += 1 elif cur>0 and flag=="d": flag = None ans += 1 print(ans) return def examB(): def bfs(n,V): W = [inf] * n W[0] = 0 que = deque() que.append(0) while (que): now = que.popleft() nowW = W[now] if nowW==0: judge = 0 elif nowW>0: judge = 1 else: judge = -1 if judge<0: cur = -1 else: cur = 1 for ne in V[now]: #print(now,ne) if cur+1<judge: break if W[ne]!=inf: continue W[ne] = nowW + cur que.append(ne) cur -= 2 return W N, M = LI() V = [[]for _ in range(N)] for _ in range(M): a, b = LI() a -= 1; b -= 1 V[a].append(b) V[b].append(a) L = bfs(N,V) D = defaultdict(int) minA = 0; maxA = 0 for i,a in enumerate(L,start=1): if a!=inf: D[a] = i if a<minA: minA = a if a>maxA: maxA = a ans = [] for i in range(minA,maxA+1): ans.append(D[i]) print(len(ans)) print(" ".join(map(str,ans))) return def examC(): N, L, T = LI() X = [[]for _ in range(N)] for i in range(N): cur = LI() cur.append(i) X[i] = cur #print(X) X.sort() ans_num = defaultdict(int) for j,[x,w,i] in enumerate(X): ans_num[j] = i X_R = [] X_L = [] #flag_R = False for x,w,i in X: if w==1: if i==0: flag_R = True X_R.append([x,i]) else: X_L.append([x,i]) V = [] for i in range(N): now = T if X[i][1]==1 else -T cur = (X[i][0] + now)%L cur = (cur+L)%L V.append(cur) change = 0 if flag_R: stand = X_R[0][0] else: stand = X_L[0][0] for x,i in X_L if flag_R else X_R: cur = (2*T)//L if flag_R: if (x - stand) > 0 and x - stand <= (2 * T) % L: cur += 1 elif (x - stand) <= 0 and L - (x - stand) <= (2 * T) % L: cur += 1 else: if (x - stand) < 0 and x - stand <= (2 * T) % L: cur += 1 elif (x - stand) >= 0 and L - (x - stand) <= (2 * T) % L: cur += 1 #print(cur,x,i) change += cur to = change % N #print(change,to) import numpy as np if flag_R: V = np.roll(V, to) else: V = np.roll(V, -to) ans = [0]*N for i in range(N): ans[ans_num[i]] = V[i] for v in ans: print(v) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,copy,bisect,itertools,heapq,math,random from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] if __name__ == '__main__': examC() """ """
s369110788
p03747
u638795007
1584510048
Python
PyPy3 (2.4.0)
py
Runtime Error
392
81832
3552
def examA(): N = I() A = LI() ans = 1 flag = None for i in range(N-1): cur = A[i+1] - A[i] if not flag: if cur<0: flag = "d" elif cur>0: flag = "u" else: if cur<0 and flag=="u": flag = None ans += 1 elif cur>0 and flag=="d": flag = None ans += 1 print(ans) return def examB(): def bfs(n,V): W = [inf] * n W[0] = 0 que = deque() que.append(0) while (que): now = que.popleft() nowW = W[now] if nowW==0: judge = 0 elif nowW>0: judge = 1 else: judge = -1 if judge<0: cur = -1 else: cur = 1 for ne in V[now]: #print(now,ne) if cur+1<judge: break if W[ne]!=inf: continue W[ne] = nowW + cur que.append(ne) cur -= 2 return W N, M = LI() V = [[]for _ in range(N)] for _ in range(M): a, b = LI() a -= 1; b -= 1 V[a].append(b) V[b].append(a) L = bfs(N,V) D = defaultdict(int) minA = 0; maxA = 0 for i,a in enumerate(L,start=1): if a!=inf: D[a] = i if a<minA: minA = a if a>maxA: maxA = a ans = [] for i in range(minA,maxA+1): ans.append(D[i]) print(len(ans)) print(" ".join(map(str,ans))) return def examC(): N, L, T = LI() X = [[]for _ in range(N)] for i in range(N): cur = LI() cur.append(i) X[i] = cur #print(X) X.sort() conn = defaultdict(int) for j,[x,w,i] in enumerate(X): conn[i] = j X_R = [] X_L = [] flag_R = False for x,w,i in X: if w==1: if i==0: flag_R = True X_R.append([x,i]) else: X_L.append([x,i]) V = [] for i in range(N): now = T if X[i][1]==1 else -T cur = (X[i][0] + now)%L cur = (cur+L)%L V.append(cur) change = 0 if flag_R: stand = X_R[0][0] else: stand = X_L[0][0] for x,i in X_L if flag_R else X_R: cur = T//L if x>stand and x-stand>=T%L: cur += 1 elif x<=stand and L+x-stand>=T%L: cur += 1 change += cur to = change % N import numpy as np V = np.roll(V, to) ans = [0]*N for i in range(N): ans[i] = V[conn[i]] for v in ans: print(v) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,copy,bisect,itertools,heapq,math,random from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10**(-12) alphabet = [chr(ord('a') + i) for i in range(26)] if __name__ == '__main__': examC() """ """
s788820091
p03747
u235783479
1583398064
Python
Python (3.4.3)
py
Runtime Error
2105
31528
2230
n, l, total_t = map(int, input().split()) pos_nt = {i:[] for i in range(n)} xl = [] wl = [] rrp = [] lrp = [] for i in range(n): x, w = map(int, input().split()) xl.append(x) wl.append(w) if w ==1: rrp.append(x) else:lrp.append(x) for i in range(n): if wl[i] == 1: orig_idx = i break is_rr = True rhead = 0 lhead = 0 for i, p in enumerate(lrp): if p > rrp[rhead]: lhead = i # todo: len(lrp) == 0 の場合 current_pos = rrp[rhead] t = 0 while(True): if is_rr: lp = (lrp[lhead]-t)%l rp = (rrp[rhead]+t)%l if rp >lp: rp = rp-l elapsed = (lp-rp)/2 if(elapsed <0): print("oops") exit() if(t + elapsed > total_t): break current_pos = lp-elapsed t += elapsed is_rr = False rhead = (rhead-1)%len(rrp) else: lp = (lrp[lhead]-t)%l rp = (rrp[rhead]+t)%l if rp >lp: rp = rp-l elapsed = (lp-rp)/2 if(elapsed < 0): print("oops2") exit() if(t + elapsed > total_t): break current_pos = lp-elapsed t += elapsed is_rr = True lhead = (lhead +1)%len(lrp) # rhead = (rhead-1)%len(rrp) remain_t = total_t - t is_rr = not is_rr # print(rrp[rhead]) # print(lrp[lhead]) # exit() if is_rr: current_pos = (current_pos + remain_t)%l else: current_pos = (current_pos - remain_t)%l if is_rr: pos = (rrp[rhead]-t) res_list = [] for i in range(n): if wl[i] == 1: sl = xl[i] + total_t else: sl = xl[i] - total_t res_list.append(sl%l) # print(res_list) # exit() mod_res_list = [] for i in range(n): if res_list[i] == current_pos: hoge = i break shift_d = hoge-orig_idx shift_idx = shift_d%n for i in range(shift_idx, n): mod_res_list.append(res_list[i]) for i in range(0, shift_idx): mod_res_list.append(res_list[i]) # print(mod_res_list) for r in mod_res_list: print(r) # for i in range(hoge, n): # print(res_list[i]) # for i in range(0, hoge): # print(res_list[i])
s290392388
p03747
u314050667
1579635413
Python
Python (3.4.3)
py
Runtime Error
550
17692
850
import numpy as np N,L,T = map(int, input().split()) x,w = [],[] for _ in range(N): tx,tw = map(int, input().split()) if tw == 2: tw = -1 x.append(tx) w.append(tw) x = np.array(x) w = np.array(w) f = x+(w*T) f %= L if w[0] == 1: ghost = T*2 s,t = divmod(ghost,L) cnt = s*np.count_nonzero(w == -1) dist = x[0] + t for i in range(1,N): if w[i] == -1 and x[i] <= dist: cnt += 1 ind = N-(cnt%N) else: ghost = T*2 s,t = divmod(ghost, L) num_w1 = np.count_nonzero(w == 1) cnt = s*num_w1 dist = x[0] + (L-t) un_cnt = 0 for i in range(1,N): if w[i] == 1 and x[i] <= dist: un_cnt += 1 cnt += (num_w1-un_cnt) ind = (cnt%N)+1 IND = np.arange(N) F = np.stack([f,IND],1) F = F[np.argsort(F[:,0])] for i in range(N): if F[i][1] == ind: ind = i break F = np.concatenate((F[ind:], F[:ind])) F = F[:,0] for A in F: print(A)
s852841193
p03747
u747220349
1578783295
Python
PyPy3 (2.4.0)
py
Runtime Error
174
38256
224
n,l,t=map(int,input().split()) inf=[] s=0 for _ in range(n): x,y=map(int,input().split()) if y==1: x+=t else: x-=t inf.append(x%l) s+=x//l inf.sort() s%n for i in range(n): print(inf[(i+s)%n])
s764723895
p03747
u747220349
1578783247
Python
PyPy3 (2.4.0)
py
Runtime Error
163
38384
224
n,l,t=map(int,input().split()) inf=[] s=0 for _ in range(n): x,y=map(int,input().split()) if y==1: x+=t else: x-=t inf.append(x%l) s+=x//l inf.sort() s%n for i in range(n): print(inf[(i+p)%n])
s662020202
p03747
u747220349
1578783202
Python
PyPy3 (2.4.0)
py
Runtime Error
163
38384
223
n,l,t=map(int,input().split()) inf=[] s=0 for _ in range(n) x,y=map(int,input().split()) if y==1: x+=t else: x-=t inf.append(x%l) s+=x//l inf.sort() s%n for i in range(n): print(inf[(i+p)%n])
s716415467
p03747
u381635950
1577270753
Python
PyPy3 (2.4.0)
py
Runtime Error
748
66648
1056
# coding: utf-8 # Your code here! CLOCKWISE = 1 COUNTERCLOCKWISE = -1 class Ant: def __init__(self, x, w): self.x = x self.w = w nums=list(map(int,input().split())) N = nums[0] L = nums[1] T = nums[2] ants = [] for i in range(N): nums=list(map(int,input().split())) if nums[1] == 1: ants.append(Ant(nums[0], CLOCKWISE)) else: ants.append(Ant(nums[0], COUNTERCLOCKWISE)) lower = ants[0].x upper = (ants[0].x + T) % L cnt_neg = -1 cnt_pos = 0 for i in range(N): if ants[0].w == ants[i].w and ((ants[0].x - ants[i].x) * ants[0].w) % L < T: cnt_neg += 1 elif ants[0].w != ants[i].w and ((ants[i].x - ants[0].x) * ants[0].w) % L < 2 * T: cnt_pos += 1 result = [] for i in range(N): result.append((ants[i].x + T * ants[i].w) % L) if cnt_pos % 2 == 1: cnt_neg += 1 if ants[0].w == CLOCKWISE: for i in range(- cnt_neg + 1 , N - cnt_neg + 1): print(result[i]) else: for i in range(- cnt_neg, N - cnt_neg): print(result[i])
s487425103
p03747
u381635950
1577269510
Python
PyPy3 (2.4.0)
py
Runtime Error
692
66648
1028
# coding: utf-8 # Your code here! CLOCKWISE = 1 COUNTERCLOCKWISE = -1 class Ant: def __init__(self, x, w): self.x = x self.w = w nums=list(map(int,input().split())) N = nums[0] L = nums[1] T = nums[2] ants = [] for i in range(N): nums=list(map(int,input().split())) if nums[1] == 1: ants.append(Ant(nums[0], CLOCKWISE)) else: ants.append(Ant(nums[0], COUNTERCLOCKWISE)) lower = ants[0].x upper = (ants[0].x + T) % L cnt_neg = -1 cnt_pos = 0 for i in range(N): if ants[0].w == ants[i].w and (ants[0].x - ants[i].x) % L < T: cnt_neg += 1 elif ants[0].w != ants[i].w and (ants[i].x - ants[0].x) % L < 2 * T: cnt_pos += 1 result = [] for i in range(N): result.append((ants[i].x + T * ants[i].w) % L) if cnt_pos % 2 == 1: cnt_neg += 1 if ants[0].w == CLOCKWISE: for i in range(- cnt_neg + 1 , N - cnt_neg + 1): print(result[i]) else: for i in range(- cnt_neg, N - cnt_neg): print(result[i])
s904090211
p03747
u591503175
1575434070
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38384
1987
# %% # VScodeで入力をテキストから読み込んで標準入力に渡す import sys import os f=open(r'.\ant_1-6-2_AGC013C\AGC013_input.txt', 'r', encoding="utf-8") # inputをフルパスで指定 # win10でファイルを作るとs-jisで保存されるため、読み込みをutf-8へエンコードする必要あり # VScodeでinput file開くとutf8になってるんだけど中身は結局s-jisになっているらしい sys.stdin=f # # 入力スニペット # num = int(input()) # num_list = [int(item) for item in input().split()] # num_list = [input() for _ in range(3)] ################################## # %% # 以下ペースト可 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])
s143352489
p03747
u591503175
1575396755
Python
PyPy3 (2.4.0)
py
Runtime Error
169
38256
1318
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): next_list.append([*item , 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])
s969171171
p03747
u591503175
1575396638
Python
Python (3.4.3)
py
Runtime Error
18
3192
1318
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): next_list.append([*item , 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])
s715946831
p03747
u591503175
1575396172
Python
Python (3.4.3)
py
Runtime Error
18
3064
1300
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): next_list.append([*item , i]) while T >= 0: 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][2], next_list[(i+1)%N][2] = next_list[(i+1)%N][2], next_list[i][2] 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][2], next_list[(i-1)%N][2] = next_list[(i-1)%N][2], next_list[i][2] T -= 1 print(*[item[0] for item in next_list])
s688066750
p03747
u601321817
1567741823
Python
Python (3.4.3)
py
Runtime Error
17
3064
1103
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 input1().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)]))
s216009281
p03747
u532966492
1567477349
Python
Python (3.4.3)
py
Runtime Error
489
34696
1829
n,l,t=map(int,input().split()) xw=[list(map(int,input().split())) for _ in [0]*n] first_x=xw[0][0] first_w=xw[0][1] right=[] left=[] for x,w in xw: if w==1: right.append(x) else: left.append(x) if first_w==1: left=[(i-first_x)/2 for i in left] right.reverse() right=[(l+first_x-i)/2 for i in right] else: right=[(l+first_x-i)/2 for i in right] right.reverse() left=[(i-first_x)/2 for i in left[1:]]+[l/2] ll=len(left) lr=len(right) def search(cnt): w=first_w if ll==0 or lr==0: return None elif cnt==0: return [0,0,0] elif w==1: right_temp=((cnt//2+cnt%2-1)//ll)*(l/2)+left[(cnt//2+cnt%2-1)%ll] left_temp=max((((cnt-2)//2)//lr),0)*(l/2)+right[((cnt-2)//2)%lr]*(cnt!=1) else: left_temp=((cnt//2+cnt%2-1)//lr)*(l/2)+right[(cnt//2+cnt%2-1)%lr] right_temp=max((((cnt-1)//2)//ll),0)*(l/2)+left[((cnt-2)//2)%ll]*(cnt!=1) return [left_temp+right_temp,right_temp,left_temp] def b_search(a,b,p,value): med=(a+b)//2 if a==b:return a if a+1==b: if value(b)[0]<=p:return b else:return a elif value(med)[0]<=p:return b_search(med,b,p,value) else:return b_search(a,med-1,p,value) a=b_search(0,10**9,t,search) if a==False: last=((first_x+t*int((-first_w+1.5)*2))%l+l)%l else: b=search(a) if (a+first_w)%2==1: b[1]+=t-b[0] else: b[2]+=t-b[0] last=int(((first_x+b[1]-b[2])%l+l)%l) ans=sorted([((x+t*int((-w+1.5)*2))%l+l)%l for x,w in xw]) for i in range(n): if last==ans[i]: if i==n-1: break elif ans[i+1]!=last: break else: if (a+first_w)%2==1: break else: i+=1 break for j in ans[i:]+ans[:i]: print(j)
s051333488
p03747
u532966492
1567476908
Python
Python (3.4.3)
py
Runtime Error
515
34688
1937
n,l,t=map(int,input().split()) xw=[list(map(int,input().split())) for _ in [0]*n] first_x=xw[0][0] first_w=xw[0][1] right=[] left=[] for x,w in xw: if w==1: right.append(x) else: left.append(x) if first_w==1: left=[(i-first_x)/2 for i in left] right.reverse() right=[(l+first_x-i)/2 for i in right] else: right=[(l+first_x-i)/2 for i in right] right.reverse() left=[(i-first_x)/2 for i in left[1:]]+[l/2] ll=len(left) lr=len(right) #print(left) #print(right) def search(cnt): w=first_w if ll==0 or lr==0: return None elif cnt==0: return [0,0,0] elif w==1:#偶数奇数の組み合わせがうまくいっていない right_temp=((cnt//2+cnt%2-1)//ll)*(l/2)+left[(cnt//2+cnt%2-1)%ll] left_temp=max((((cnt-2)//2)//lr),0)*(l/2)+right[((cnt-2)//2)%lr]*(cnt!=1) else: left_temp=((cnt//2+cnt%2-1)//lr)*(l/2)+right[(cnt//2+cnt%2-1)%lr] right_temp=max((((cnt-1)//2)//ll),0)*(l/2)+left[((cnt-2)//2)%ll]*(cnt!=1) return [left_temp+right_temp,right_temp,left_temp] def b_search(a,b,p,value): med=(a+b)//2 if a==b:return a if a+1==b: if value(b)[0]<=p:return b else:return a elif value(med)[0]<=p:return b_search(med,b,p,value) else:return b_search(a,med-1,p,value) #print(search(5)) a=b_search(0,10**9,t,search) #print(a) b=search(a) #print(b) #print(search(a+1)) if (a+first_w)%2==1: b[1]+=t-b[0] #print("右") else: b[2]+=t-b[0] #print("左") #print(b) last=int(((first_x+b[1]-b[2])%l+l)%l) #print(last) ans=sorted([((x+t*int((-w+1.5)*2))%l+l)%l for x,w in xw]) for i in range(n): if last==ans[i]: if i==n-1: break elif ans[i+1]!=last: break else: if (a+first_w)%2==1: break else: i+=1 break for j in ans[i:]+ans[:i]: print(j)
s393339347
p03747
u908763441
1567107303
Python
Python (3.4.3)
py
Runtime Error
2133
383272
723
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 N, L, T = map(int, input().split()) # アリの数、外周、時間 P = [] # アリの位置 D = [] # アリの方向 J = [0] * (L * 2) for n in range(N): t1, t2 = map(int, input().split()) P.append(t1 * 2) D.append(t2) for t in range(T * 2): J = [0 for _ in range(L * 2)] for n in range(N): if D[n] == 1: P[n] = (P[n]+1) % (L * 2) else: P[n] = (P[n]-1) % (L * 2) if J[P[n]] == 0: J[P[n]] += 1 else: tmp = P.index(P[n]) D[tmp] += 1 if D[tmp] == 1 else -1 D[n] += 1 if D[n] == 1 else - 1 for n in range(N): print(str(P[n]//2))
s337153259
p03747
u908763441
1567107234
Python
Python (3.4.3)
py
Runtime Error
1833
1297396
137
N, L, T = map(int, input().split()) # アリの数、外周、時間 P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2
s317365119
p03747
u908763441
1567107133
Python
Python (3.4.3)
py
Runtime Error
1878
1297396
233
N, L, T = map(int, input().split()) # アリの数、外周、時間 P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2 for n in range(N): t1, t2 = map(int, input().split()) P.append(t1 * 2) D.append(t2)
s410289705
p03747
u908763441
1567107053
Python
Python (3.4.3)
py
Runtime Error
2115
1297396
355
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 N, L, T = map(int, input().split()) # アリの数、外周、時間 P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2 for n in range(N): t1, t2 = map(int, input().split()) P.append(t1 * 2) D.append(t2) for t in range(T * 2): J = [0 for _ in range(L * 2)]
s946268040
p03747
u908763441
1567107016
Python
Python (3.4.3)
py
Runtime Error
2114
1297524
540
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 N, L, T = map(int, input().split()) # アリの数、外周、時間 P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2 for n in range(N): t1, t2 = map(int, input().split()) P.append(t1 * 2) D.append(t2) for t in range(T * 2): J = [0 for _ in range(L * 2)] for n in range(N): if D[n] == 1: P[n] = (P[n]+1) % (L * 2) else: P[n] = (P[n]-1) % (L * 2) if J[P[n]] == 0: J[P[n]] += 1
s897491986
p03747
u908763441
1567106993
Python
Python (3.4.3)
py
Runtime Error
2113
1297524
678
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 N, L, T = map(int, input().split()) # アリの数、外周、時間 P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2 for n in range(N): t1, t2 = map(int, input().split()) P.append(t1 * 2) D.append(t2) for t in range(T * 2): J = [0 for _ in range(L * 2)] for n in range(N): if D[n] == 1: P[n] = (P[n]+1) % (L * 2) else: P[n] = (P[n]-1) % (L * 2) if J[P[n]] == 0: J[P[n]] += 1 else: tmp = P.index(P[n]) D[tmp] += 1 if D[tmp] == 1 else -1 D[n] += 1 if D[n] == 1 else - 1
s217061913
p03747
u908763441
1567106338
Python
Python (3.4.3)
py
Runtime Error
2115
1297524
720
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 N, L, T = map(int, input().split()) # アリの数、外周、時間 P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2 for n in range(N): t1, t2 = map(int, input().split()) P.append(t1 * 2) D.append(t2) for t in range(T * 2): J = [0 for _ in range(L * 2)] for n in range(N): if D[n] == 1: P[n] = (P[n]+1) % (L * 2) else: P[n] = (P[n]-1) % (L * 2) if J[P[n]] == 0: J[P[n]] = 1 else: tmp = P.index(P[n]) D[tmp] += 1 if D[tmp] == 1 else -1 D[n] += 1 if D[n] == 1 else - 1 for n in range(N): print(str(P[n]//2))
s289187064
p03747
u908763441
1567106000
Python
Python (3.4.3)
py
Runtime Error
2129
1297524
687
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 N, L, T = map(int, input().split()) P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2 for n in range(N): t1, t2 = map(int, input().split()) P.append(t1 * 2) D.append(t2) for t in range(T * 2): J = [0 for _ in range(L * 2)] for n in range(N): if D[n] == 1: P[n] = (P[n]+1) % (L * 2) else: P[n] = (P[n]-1) % (L * 2) if J[P[n]] == 0: J[P[n]] += 1 else: tmp = P.index(P[n]) D[tmp] += 1 if D[tmp] == 1 else -1 D[n] += 1 if D[n] == 1 else - 1 for n in range(N): print(str(P[n]//2))
s873166481
p03747
u908763441
1567105198
Python
Python (3.4.3)
py
Runtime Error
2111
1297524
589
N, L, T = map(int, input().split()) P = [] # アリの位置 D = [] # アリの方向 J = [0] * L * 2 for n in range(N): tmp = list(map(int, input().split())) P.append(tmp[0] * 2) D.append(tmp[1]) for t in range(T * 2): J = [0 for _ in range(L * 2)] for n in range(N): P[n] += 1 if D[n] == 1 else -1 P[n] = P[n] % (L * 2) if J[P[n]] == 0: J[P[n]] += 1 else: tmp = P.index(P[n]) D[tmp] += 1 if D[tmp] == 1 else -1 D[n] += 1 if D[n] == 1 else - 1 for n in range(N): print(str(P[n]//2))
s231295638
p03747
u499381410
1565284966
Python
Python (3.4.3)
py
Runtime Error
17
3064
452
normal_ant = [i for i, direction in ants if direction==1] counter_ant = [i for i, direction in ants if direction==2] cnt = (t // l) * len(normal_ant) + sum([1 for i in normal_ant if i + t%l >= l]) counter_cnt = (t // l) * len(counter_ant) + sum([1 for i in counter_ant if i - t%l < 0]) final_pos = sorted([(i-t)%l for i in counter_ant] + [(i+t)%l for i in normal_ant]) print(*final_pos[(cnt-counter_cnt)%n:] + final_pos[:(cnt-counter_cnt)%n], sep='\n')
s466399040
p03747
u485979475
1564817277
Python
Python (3.4.3)
py
Runtime Error
2110
34924
1474
import sys import numpy as np n,l,t=map(int,input().rstrip().split()) iniposition =[] finposition=[] fline=np.array([]) bline=np.array([]) for i in range(n): temp1,temp2 = map(int,sys.stdin.readline().rstrip().split()) iniposition.append([i,temp1,temp2]) for element in iniposition: temp1=((-1*(2*element[2]-3)*t)+element[1]) % l finposition.append(int(temp1)) position_1=iniposition[0][1] for element in iniposition[1:]: if element[2] == 2: fline = np.append(fline,float((element[1]-position_1) % l )) else: bline = np.append(bline,float((position_1-element[1]) % l )) fline.sort() bline.sort() T=float(t) sum_move=0.0 sum_time=0.0 direction=int(-2*(iniposition[0][2]-1.5)) for _ in range(t): if direction == 1 : front = fline[0] if front / 2 >= T - sum_time: sum_move += T - sum_time sum_time = T break else: sum_move += front / 2 sum_time += front / 2 fline = fline - front / 2 fline = np.delete(fline,0) bline = np.append(bline,float(l)) direction=-1 else: front = bline[0] if front / 2 >= T - sum_time: sum_move -= T- sum_time sum_time = T break else: sum_move -= front / 2 sum_time += front / 2 bline = bline - front / 2 bline = np.delete(bline,0) fline = np.append(fline,float(l)) direction = 1 tarposition = (position_1 + int(sum_move)) % l i = finposition.index(tarposition) lh = finposition[:i] fh = finposition[i:] fh.extend(lh) for element in fh: print(element)
s603039007
p03747
u485979475
1564813060
Python
PyPy3 (2.4.0)
py
Runtime Error
2111
126728
1415
import sys n,l,t=map(int,input().rstrip().split()) iniposition =[] finposition=[] fline=[] bline=[] for i in range(n): temp1,temp2 = map(int,sys.stdin.readline().rstrip().split()) iniposition.append([i,temp1,temp2]) for element in iniposition: temp1=((-2*(element[2]-1.5)*t)+element[1]) % l finposition.append(int(temp1)) position_1=iniposition[0][1] for element in iniposition[1:]: if element[2] == 2: fline.append(float((element[1]-position_1) % l )) else: bline.append(float((position_1-element[1]) % l )) fline.sort() bline.sort() T=float(t) sum_move=0.0 sum_time=0.0 direction=int(-2*(iniposition[0][2]-1.5)) for _ in range(t): if direction == 1 : if fline[0] / 2 >= T - sum_time: sum_move += T - sum_time sum_time = T break else: distance = fline[0] sum_move += distance / 2 sum_time += distance / 2 fline = list(map(lambda x :x-distance/2,fline)) fline = fline[1:] bline.append(l) direction=-1 else: if bline[0] / 2 >= T - sum_time: sum_move -= T- sum_time sum_time = T break else: distance = bline[0] sum_move -= distance / 2 sum_time += distance / 2 map(lambda x :x-distance/2,bline) bline = bline[1:] fline.append(l) direction = 1 tarposition = (position_1 + int(sum_move)) % l i = finposition.index(tarposition) lh = finposition[:i] fh = finposition[i:] fh.extend(lh) for element in fh: print(element)
s513486810
p03747
u485979475
1564812839
Python
PyPy3 (2.4.0)
py
Runtime Error
171
38384
1410
import sys n,l,t=map(int,input().rstrip().split()) iniposition =[] finposition=[] fline=[] bline=[] for i in range(n): temp1,temp2 = map(int,sys.stdin.readline().rstrip().split()) iniposition[i]=[i,temp1,temp2] for element in iniposition: temp1=((-2*(element[2]-1.5)*t)+element[1]) % l finposition.append(int(temp1)) position_1=iniposition[0][1] for element in iniposition[1:]: if element[2] == 2: fline.append(float((element[1]-position_1) % l )) else: bline.append(float((position_1-element[1]) % l )) fline.sort() bline.sort() T=float(t) sum_move=0.0 sum_time=0.0 direction=int(-2*(iniposition[0][2]-1.5)) for _ in range(t): if direction == 1 : if fline[0] / 2 >= T - sum_time: sum_move += T - sum_time sum_time = T break else: distance = fline[0] sum_move += distance / 2 sum_time += distance / 2 fline = list(map(lambda x :x-distance/2,fline)) fline = fline[1:] bline.append(l) direction=-1 else: if bline[0] / 2 >= T - sum_time: sum_move -= T- sum_time sum_time = T break else: distance = bline[0] sum_move -= distance / 2 sum_time += distance / 2 map(lambda x :x-distance/2,bline) bline = bline[1:] fline.append(l) direction = 1 tarposition = (position_1 + int(sum_move)) % l i = finposition.index(tarposition) lh = finposition[:i] fh = finposition[i:] fh.extend(lh) for element in fh: print(element)
s670722309
p03747
u485979475
1564811922
Python
Python (3.4.3)
py
Runtime Error
2108
30680
1415
import sys n,l,t=map(int,input().rstrip().split()) iniposition =[] finposition=[] fline=[] bline=[] for i in range(n): temp1,temp2 = map(int,sys.stdin.readline().rstrip().split()) iniposition.append([i,temp1,temp2]) for element in iniposition: temp1=((-2*(element[2]-1.5)*t)+element[1]) % l finposition.append(int(temp1)) position_1=iniposition[0][1] for element in iniposition[1:]: if element[2] == 2: fline.append(float((element[1]-position_1) % l )) else: bline.append(float((position_1-element[1]) % l )) fline.sort() bline.sort() T=float(t) sum_move=0.0 sum_time=0.0 direction=int(-2*(iniposition[0][2]-1.5)) for _ in range(t): if direction == 1 : if fline[0] / 2 >= T - sum_time: sum_move += T - sum_time sum_time = T break else: distance = fline[0] sum_move += distance / 2 sum_time += distance / 2 fline = list(map(lambda x :x-distance/2,fline)) fline = fline[1:] bline.append(l) direction=-1 else: if bline[0] / 2 >= T - sum_time: sum_move -= T- sum_time sum_time = T break else: distance = bline[0] sum_move -= distance / 2 sum_time += distance / 2 map(lambda x :x-distance/2,bline) bline = bline[1:] fline.append(l) direction = 1 tarposition = (position_1 + int(sum_move)) % l i = finposition.index(tarposition) lh = finposition[:i] fh = finposition[i:] fh.extend(lh) for element in fh: print(element)
s413093772
p03747
u485979475
1564809609
Python
Python (3.4.3)
py
Runtime Error
2105
28996
1362
n,l,t=map(int,input().rstrip().split()) iniposition =[] finposition=[] fline=[] bline=[] for i in range(n): temp1,temp2 = map(int,input().rstrip().split()) iniposition.append([i,temp1,temp2]) for i in range(n): temp1=((-2*(iniposition[i][2]-1.5)*t)+iniposition[i][1]) % l finposition.append(int(temp1)) position_1=iniposition[0][1] for i in range(1,n): if iniposition[i][2] == 2: fline.append(float((iniposition[i][1]-position_1) % l )) else: bline.append(float((position_1-iniposition[i][1]) % l )) fline.sort() bline.sort() T=float(t) sum_move=0.0 sum_time=0.0 direction=int(-2*(iniposition[0][2]-1.5)) while sum_time < T: if direction == 1 : if fline[0]/2>=T - sum_time: sum_move+=T-sum_time sum_time=T else: distance=fline[0] sum_move+=distance / 2 sum_time+=distance / 2 fline=list(map(lambda x :x-distance/2,fline)) fline=fline[1:] bline.append(l) direction=-1 else: if bline[0]/2>=T - sum_time: sum_move-=T-sum_time sum_time=T else: distance=bline[0] sum_move-=distance / 2 sum_time+=distance / 2 map(lambda x :x-distance/2,bline) bline=bline[1:] fline.append(l) direction=1 tarposition=(position_1 + sum_move)%l for i in range(n): if finposition[i]==tarposition: lh=finposition[:i] fh=finposition[i:] fh.extend(lh) break for element in fh: print(element)
s439186377
p03747
u610540994
1564216348
Python
Python (3.4.3)
py
Runtime Error
17
3060
219
N, L, T = map(int, input().split()) n = [[*map(int, input().split())] for _ in range(N)] t = [X + (0, T, -T)[W] for X, W in n] x = sorted(i % L for i in t) s = sum(i // L for i in t) % N for i in x[s:] + x[:s]: print(i)
s725151298
p03747
u214434454
1563560333
Python
Python (3.4.3)
py
Runtime Error
576
24248
1733
n,l,T = map(int,input().split()) s = [0 for i in range(n)] for i in range(n): s[i] = list(map(int, input().split())) def f(w): if w == 1: return 1 elif w == 2: return -1 t = 0 d = l while t < T: for i in range(n): if i < n-1 : if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2: if s[i+1][0] - s[i][0] < d: d = s[i+1][0] - s[i][0] elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2: if s[i+1][0] + l - s[i][0] < d: d = s[i+1][0] + l - s[i][0] elif i == n-1: if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2: if s[0][0] - s[i][0] < d: d = s[0][0] - s[i][0] elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2: if s[0][0] + l - s[i][0] < d: d = s[0][0] + l - s[i][0] for j in range(n): if t + d/2 <= T: s[j][0] += f(s[j][1]) * (d/2) if s[j][0] >= l: s[j][0] -= l elif s[j][0] < 0: s[j][0] += l else: s[j][0] += f(s[j][1]) * (T-t) if s[j][0] >= l: s[j][0] -= l elif s[j][0] < 0: s[j][0] += l if j > 0 and s[j][0] == s[j-1][0]: s[j][1], s[j-1][1] = s[j-1][1], s[j][1] if j == n-1 and s[j][0] == s[0][0] : s[j][1], s[0][1] = s[0][1], s[j][1] t = t + d/2 i_d.clear() d = l import math for i in range(n): print(math.floor(s[i][0]))
s035453455
p03747
u214434454
1563559484
Python
Python (3.4.3)
py
Runtime Error
2105
25112
2413
n,l,T = map(int,input().split()) s = [0 for i in range(n)] for i in range(n): s[i] = list(map(int, input().split())) def f(w): if w == 1: return 1 elif w == 2: return -1 t = 0 d = l i_d = [] while t < T: for i in range(n): if i < n-1 : if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2: if s[i+1][0] - s[i][0] < d: d = s[i+1][0] - s[i][0] elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2: if s[i+1][0] + l - s[i][0] < d: d = s[i+1][0] + l - s[i][0] elif i == n-1: if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2: if s[0][0] - s[i][0] < d: d = s[0][0] - s[i][0] elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2: if s[0][0] + l - s[i][0] < d: d = s[0][0] + l - s[i][0] for i in range(n): if i < n-1 : if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2: if s[i+1][0] - s[i][0] == d: i_d.append(i) elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2: if s[i+1][0] + l - s[i][0] == d: i_d.append(i) elif i == n-1: if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2: if s[0][0] - s[i][0] == d: i_d.append(i) elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2: if s[0][0] + l - s[i][0] == d: i_d.append(i) for j in range(n): if t + d/2 <= T: s[j][0] += f(s[j][1]) * (d/2) if s[j][0] >= l: s[j][0] -= l elif s[j][0] < 0: s[j][0] += l else: s[j][0] += f(s[j][1]) * (T-t) if s[j][0] >= l: s[j][0] -= l elif s[j][0] < 0: s[j][0] += l for j in i_d: if j < n-1: s[j][1], s[j+1][1] = s[j+1][1], s[j][1] else: s[j][1], s[0][1] = s[0][1], s[j][1] t = t + d/2 i_d.clear() d = l import maht for i in range(n): print(math.floor(s[i][0]))
s962392180
p03747
u793821463
1560481094
Python
PyPy3 (2.4.0)
py
Runtime Error
2111
123804
1418
N,L,T = map(int , input().split()) X = [0]*N W = [0]*N Y = [0]*(N+4) Z = [0]*(N+4) for i in range(N): X[i],W[i] = map(int , input().split()) Y[i+2] = X[i] Z[i+2] = W[i] Y[0] = X[N-2] Y[1] = X[N-1] Y[N+2] = X[0] Y[N+3] = X[1] Z[0] = W[N-2] Z[1] = W[N-1] Z[N+2] = W[0] Z[N+3] = W[1] for i in range(T): for h in range(N): j = h + 2 if min((L - abs(Y[j+1] - Y[j]),abs(Y[j+1] - Y[j]))) <=2 and Z[j] == 1 and Z[j+1] ==2: X[h] = Y[j+1] - 1 W[h] = 2 elif min((L - abs((Y[j] - Y[j-1])),abs(Y[j] - Y[j-1]))) <=2 and Z[j] ==2 and Z[j-1] ==1: X[h] = Y[j-1] + 1 W[h] = 1 elif min((L - abs(Y[j+1] - Y[j-1]),abs(Y[j+1] - Y[j-1]))) ==2 and Z[j-1] ==1 and Z[j+1] ==2: X[h] = Y[j] elif min((L - abs(Y[j+2] - Y[j]),abs(Y[j+2] - Y[j]))) ==2 and Z[j] ==1 and Z [j+1] ==1 and Z[j+2] ==2: X[h] = Y[j] + 1 W[h] = 2 elif min((L - abs(Y[j] - Y[j-2]),abs(Y[j] - Y[j-2]))) ==2 and Z[j] ==2 and Z [j+1] ==2 and Z[j-2] ==1: X[h] = Y[j] - 1 W[h] = 1 else: X[h] = Y[j] + 3 - 2 * Z[j] for j in range(N): X[j]%= L Y[j+2] = X[j] Z[j+2] = W[j] Y[0] = X[N-2] Y[1] = X[N-1] Y[N+2] = X[0] Y[N+3] = X[1] Z[0] = W[N-2] Z[1] = W[N-1] Z[N+2] = W[0] Z[N+3] = W[1] for x in X: print(x%L)
s036016484
p03747
u793821463
1560480758
Python
Python (3.4.3)
py
Runtime Error
2108
12556
1418
N,L,T = map(int , input().split()) X = [0]*N W = [0]*N Y = [0]*(N+4) Z = [0]*(N+4) for i in range(N): X[i],W[i] = map(int , input().split()) Y[i+2] = X[i] Z[i+2] = W[i] Y[0] = X[N-2] Y[1] = X[N-1] Y[N+2] = X[0] Y[N+3] = X[1] Z[0] = W[N-2] Z[1] = W[N-1] Z[N+2] = W[0] Z[N+3] = W[1] for i in range(T): for h in range(N): j = h + 2 if min((L - abs(Y[j+1] - Y[j]),abs(Y[j+1] - Y[j]))) <=2 and Z[j] == 1 and Z[j+1] ==2: X[h] = Y[j+1] - 1 W[h] = 2 elif min((L - abs((Y[j] - Y[j-1])),abs(Y[j] - Y[j-1]))) <=2 and Z[j] ==2 and Z[j-1] ==1: X[h] = Y[j-1] + 1 W[h] = 1 elif min((L - abs(Y[j+1] - Y[j-1]),abs(Y[j+1] - Y[j-1]))) ==2 and Z[j-1] ==1 and Z[j+1] ==2: X[h] = Y[j] elif min((L - abs(Y[j+2] - Y[j]),abs(Y[j+2] - Y[j]))) ==2 and Z[j] ==1 and Z [j+1] ==1 and Z[j+2] ==2: X[h] = Y[j] + 1 W[h] = 2 elif min((L - abs(Y[j] - Y[j-2]),abs(Y[j] - Y[j-2]))) ==2 and Z[j] ==2 and Z [j+1] ==2 and Z[j-2] ==1: X[h] = Y[j] - 1 W[h] = 1 else: X[h] = Y[j] + 3 - 2 * Z[j] for j in range(N): X[j]%= L Y[j+2] = X[j] Z[j+2] = W[j] Y[0] = X[N-2] Y[1] = X[N-1] Y[N+2] = X[0] Y[N+3] = X[1] Z[0] = W[N-2] Z[1] = W[N-1] Z[N+2] = W[0] Z[N+3] = W[1] for x in X: print(x%L)
s446938137
p03747
u218843509
1559790333
Python
Python (3.4.3)
py
Runtime Error
468
35692
765
from bisect import bisect_left n, l, t = map(int, input().split()) ants = [list(map(int, input().split())) for _ in range(n)] bnts = [] diff = [] for i in range(n): x, w = ants[i][0], 3 - 2*ants[i][1] bnts.append((x + t*w) % l) if i == 0: zero = bnts[-1] if ants[i][1] != ants[0][1]: if ants[0][1] == 1: diff.append(x - ants[0][0]) else: diff.append(l - (x - ants[0][0])) bnts.sort() num = 0 quo, mod = t//l, t%l num += quo * len(diff) * 2 diff.sort() diff += [d+l for d in diff] num += bisect_left(diff, mod*2) num %= n for i in range(n): if bnts[i] == zero: if ants[0][1] == 1: true_zero = (i-num) % n else: if bnts[i+1] == zero: num += 1 true_zero = (i+num) % n ans = bnts[true_zero:] + bnts[:true_zero] print(*ans, sep="\n")
s253434561
p03747
u684695949
1559183382
Python
PyPy3 (2.4.0)
py
Runtime Error
642
60888
1361
import bisect N,L,T= map(int,input().split()) ants = [[],[]] for i in range(N): X,W = map(int,input().split()) ants[W-1].append(X) if len(ants[0]) == N: for i in range(N): print(((x+T)%L)) exit() if len(ants[0]) == 0: for i in range(N): print(((x-T)%L)) exit() ants_final_pos = sorted([((x+T)%L) for x in ants[0]] + [((x-T)%L) for x in ants[1]]) base_idx = ants_final_pos.index(((ants[0][0]+T)%L)) dist_from_next_near00_cw =[] dist_from_next_near00_c_cw = [] old_pos = 0 for ccw in sorted([((x - ants[0][0])%L) for x in ants[1]]): dist_from_next_near00_c_cw.append(ccw - old_pos) old_pos = ccw old_pos = 0 for cw in sorted([((ants[0][0] - x)%L) for x in ants[0][1:]]): dist_from_next_near00_cw.append(cw - old_pos) old_pos = cw moved_dist = 0 dist_idx = [dist_from_next_near00_c_cw,dist_from_next_near00_cw] for i in range(N-1): rot_dir = i%2 rot_idx = i // 2 if rot_idx >= len(dist_idx[rot_dir]): break dist = dist_idx[rot_dir][rot_idx] / 2.0 if moved_dist + dist > L: break moved_dist += dist base_idx -= i * (T // L) moved_dist = 0 for i in range(N-1): rot_dir = i%2 rot_idx = i // 2 if rot_idx >= len(dist_idx[rot_dir]): break dist = dist_idx[rot_dir][rot_idx] / 2.0 if moved_dist + dist > T: break moved_dist += dist base_idx -= i for i in range(N): print(ants_final_pos[(base_idx + i) % N])