Problem p02761 (python)

Fixed submission:
N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])

if M==0:
    if N==3:
        print(100)
        exit(0)
    elif N==2:
        print(10)
        exit(0)        
    elif N==1:
        print(0)
        exit(0)

if N!=1 and A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)
i=1
j=len(A)
while i<j:
    if A[i][0]==A[i-1][0] and A[i][1]==A[i-1][1]:
        A.pop(i)
        j-=1
        continue
    elif A[i][0]==A[i-1][0] and A[i][1]!=A[i-1][1]:
        print(-1)
        exit(0)
    i+=1
ans=[None]*N

for i,j in A:
    ans[i-1]=j

for i in range(len(ans)):
    if ans[i]==None:
        if i==0:
            ans[i]=1
        else:
            ans[i]=0

print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
if M==0:
    if N>=2:
        print(-1)
        exit(0)
    elif N==1:
        print(0)
        exit(0)
        
if N!=1 and A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)
i=1
j=len(A)
while i<j:
    if A[i][0]==A[i-1][0] and A[i][1]==A[i-1][1]:
        A.pop(i)
        j-=1
        continue
    elif A[i][0]==A[i-1][0] and A[i][1]!=A[i-1][1]:
        print(-1)
        exit(0)
    i+=1
ans=[None]*N

for i,j in A:
    ans[i-1]=j

for i in range(len(ans)):
    if ans[i]==None:
        if i==0:
            ans[i]=1
        else:
            ans[i]=0

print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])
if N!=1 and A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)
i=1
j=len(A)
while i<j:
    if A[i][0]==A[i-1][0] and A[i][1]==A[i-1][1]:
        A.pop(i)
        j-=1
        continue
    elif A[i][0]==A[i-1][0] and A[i][1]!=A[i-1][1]:
        print(-1)
        exit(0)
    i+=1
ans=[None]*N

for i,j in A:
    ans[i-1]=j

for i in range(len(ans)):
    if ans[i]==None:
        if i==0:
            ans[i]=1
        else:
            ans[i]=0

print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])

if N!=1 and A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)
i=1
j=len(A)
while i<j:
    if A[i][0]==A[i-1][0] and A[i][1]==A[i-1][1]:
        A.pop(i)
        j-=1
        continue
    elif A[i][0]==A[i-1][0] and A[i][1]!=A[i-1][1]:
        print(-1)
        exit(0)
    i+=1
ans=[None]*N
if A[0][0]==1:
    ans[0]=A[0][1]
elif A[0][0]==2:
    ans[0]=1
elif A[0][0]==3:
    ans[0]=1
    ans[1]=0

for i in range(1,len(A)):
    if A[i-1][0]==1 and A[i][0]==3:
        ans[1]=0
    ans[A[i][0]-1]=A[i][1]

print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])

ans=[[] for i in range(N)]
if A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)

elif A[0][0]==1:
    pt=0
    ans[0]=A[0][1]
    pt+=1
elif A[0][0]!=1:
    ans[0]=1
    pt=1
    while pt+1<A[0][0]:
        ans[pt]=0
        pt+=1
    ans[pt]=A[0][1]
    pt+=1

for i in range(1,M):
    while pt+1<A[i][0]:
        ans[pt]=0
        pt+=1
    if A[i-1][0]==A[i][0] and A[i-1][1]!=A[i][1]:
        print(-1)
        exit(0)
    else: ans[pt]=A[i][1]
        
print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])

ans=[[] for i in range(N)]
if A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)

elif A[0][0]==1:
    ans[0]=A[0][1]
elif A[0][0]!=1:
    ans[0]=1
    pt=1
    while pt+1<A[0][0]:
        ans[pt]=0
        pt+=1
    ans[pt]=A[0][1]
    pt+=1

for i in range(1,M):
    while pt+1<A[i][0]:
        ans[pt]=0
        pt+=1
    if A[i-1][0]==A[i][0] and A[i-1][1]!=A[i][1]:
        print(-1)
        exit(0)
    else: ans[pt]=A[i][1]
        
print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split()))  for _ in range(M)]
A = sorted(A, reverse=False, key=lambda x: x[0])

ans=[[] for i in range(N)]
if A[0][0]==1 and A[0][1]==0:
    print(-1)
    exit(0)

elif A[0][0]==1:
    ans[0]=A[0][1]
elif A[0][0]!=1:
    ans[0]=1
pt=1
for i in range(1,M):
    while pt+1<A[i][0]:
        ans[pt]=0
        pt+=1
    if A[i-1][0]==A[i][0] and A[i-1][1]!=A[i][1]:
        print(-1)
        exit(0)
    else: ans[pt]=A[i][1]
        
print(''.join(map(str,ans)))