Problem:


Score : 400 points

Problem Statement

Snuke has an empty sequence a.

He will perform N operations on this sequence.

In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1).

You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq b_i \leq N

Input

Input is given from Standard Input in the following format:

N
b_1 \dots b_N

Output

If there is no sequence of N operations after which a would be equal to b, print -1.
If there is, print N lines. In the i-th line, the integer chosen in the i-th operation should be printed. If there are multiple solutions, any of them is accepted.

Sample Input 1

3
1 2 1

Sample Output 1

1
1
2

In this sequence of operations, the sequence a changes as follows:

After the first operation: (1)

After the second operation: (1,1)

After the third operation: (1,2,1)

Sample Input 2

2
2 2

Sample Output 2

-1

2 cannot be inserted at the beginning of the sequence, so this is impossible.

Sample Input 3

9
1 1 1 2 2 1 2 3 2

Sample Output 3

1
2
2
3
1
2
2
1
1



Sample input:
3
1 2 1


Sample output:
1
1
2

Submission status: Wrong Answer

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

# -*- coding: utf-8 -*-

from sys import stdin

###########################################

############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
n = stdin.readline().split()
data = stdin.readline().split()

out = []

token = 0

# check first data and return -1 if != 1
if int(data[0]) != 1:
    token = -1
else:    
    a=1
# print first data
#    out.append(1)

for i,x in enumerate(data):
    data[i]=int(x)
    
# split to multiple data.
x = 0
prev = 1
split = []
chunck = []
#while x < len(data):
for i,num in enumerate(data[x:]):
    if num == 1 and prev != 1:
        if i == 0:
            chunck.append(num)
            continue
#            chunck = [1]
        split.append(chunck)
        chunck=[]
    chunck.append(num)
    prev = num        
#        x = i+1
if chunck != []:
    split.append(chunck)

for x in reversed(split):
    maxnum=max(x)
    if x == [1]:
        out.append(1)
    else:
        for i in range(1,maxnum+1):
            if i in x:
                count = x.count(i)
                if x.index(i) >= i-1:
                    for xx in range(count):
                        out.append(i)
                else:
                    token = -1

if token == -1:
    print(-1)
else:
    # print outputs
    for x in out:
        print(x)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
b = list(input())
while ' ' in b[:]:
    b.remove(' ')
b_cp = b[:]
b_cp.sort(reverse=True)
ans = ['*' for i in range(N)]

for _ in range(N):
    max = b_cp[0]
    idx = b.index(max)
    shift = idx + 1 - int(max)
    k = N-1
    inc = max
    while True:
        if k < 0:
            print(-1)
            sys.exit()
        cnt = 0
        for l in range(k+1, N):
            if ans[l] == '*' or int(ans[l]) <= int(inc):
                cnt += 1
                if not inc == '9':
                    inc = str(int(max)+1)
        if cnt == shift and ans[k] == '*':
            break
        k -= 1
    ans[k] = max
    b_cp.pop(0)
    b[idx] = '*'

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
l = collections.Counter()
ppp = [0 for i in range(100)]
for i in a:
    l[i] += 1

l = l.most_common()
l.sort()
for i in range(n):
    k = a[i]
    if k > i+1:
        print(-1)
        exit()
c = 0
for i in range(n-2):
    if a[-(i+1)] <= a[-(i+2)]:
        c = 1
    if a[-(i+1)] > a[-(i+2)] and a[-(i+1)] != 1 and a[-(i+2)] != 1 and c == 1:
        p = a[-(i+1)]
        a[-(i+1)] = a[-(i+2)]
        a[-(i+2)] = p
b = a[1:]
b.reverse()
a = [a[0]] + b
for i in range(n):
    print(a[i])

Submission status: Wrong Answer

Solution code:
N =int(input())
B = list(map(int, input().split()))


cnt2 = 0
judge = 0
var = 1
for i in range(N):
    cnt = 0
    for j in range(N):  
        if B[j] == var:
            cnt += 1
    if cnt > N -i :
        judge += 1
    var += 1
if judge > 0:
    print('-1')
else:
    B.sort()
    for i in range(N):
        print(B[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
BBB=[int(x) for x in input().split()]

BB=[0 for i in range(N)]
def re(B,n):
  global BB
  if n==1:
    BB[0]=B[0]
    for i in BB:
      print(i)
    exit()
  for i in range(n):
    #if B[i]>i+1:
   #   return -1
    if B[i]==i+1:
      BB[n-1]=B[i]
      re(B[:i]+B[i+1:n],n-1)
  return -1

result=re(BBB,N)
print(-1)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n = int(input())
a = []
b = list(map(int, input().split()))
b_sort = sorted(b)
b_arr = [0 for i in range(100)]
for i in range(100):
    b_arr[i] = b.count(i+1)
i = 1
j = 1
while sum(b_arr) > 0:
    if b_sort[i-1] <= j and b_sort[i-1] > 0:
        if b_arr[b_sort[i-1]-1] > 0:
            b_arr[b_sort[i-1]-1] -= 1
            a.insert(j-1, b_sort[i-1])
        else:
            i += 1
        #print(max(b_sort[:i]))
    j += 1
if len(a) == len(b_sort):
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
j=True
for i in range(n):
    if b[i]>i+1:
        j=False
if not j:
    print("-1")
else:
    x=[0]
    for i in range(1,n):
        if b[i]<=b[i-1] or b[i-1]==1:
            x.append(i)
    x.append(n)
    #print(x)
    res=[]
    res.append(1)
    for i in range(-2,-len(x),-1):
        for j in b[x[i]:x[i+1]]:
            res.append(j)
    
    z=[1]
    #print(res)
    for i in range(1,n):
        t=res[i]
        z=z[:t-1]+[t]+z[t-1:]
    #print(z)
    if b==z:
        for t in res:
            print(t)
    else:
        print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
b_rev = []
op = []
for i in (reversed(b)):
    b_rev.append(i)

if b_rev.count(1) == 0 or b[0] != 1:
    print(-1)
    exit()
while 1:
    if len(b_rev) == 0:
        for i in op:
            print(i)
        else:
            exit()
    idx_one = b_rev.index(1)
    op.append(1)
    b_tmp = b_rev[0:idx_one]
    for idx,val in enumerate(b_tmp):
        if idx + 2 <= val:
            print(-1)
            exit()
    while len(b_tmp) > 0:
        min_tmp = min(b_tmp)
        for idx, item in enumerate(b_tmp):
            if item == min_tmp:
                idx_min = idx
        op.append(b_tmp.pop(idx_min))
    else:
        del b_rev[0:idx_one + 1]

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, B):
    S = {(1,): (1,)}
    for i in range(1, N):
        S_ = dict(S.items())
        S = {}
        for b, s  in S_.items():
            # print(b, s)
            for j in range(0, i):
                s_ = list(s)
                b_ = list(b)
                b_.insert(j, j)
                b_ = tuple(b_)
                # print(b_)
                if b_ not in S:
                    s_.append(j)
                    S[b_] = tuple(s_)
        # print(S)
    
    B = tuple(map(lambda x: x-1, B))
    if B in S:
        return map(lambda x: x+1, S[B])
    else:
        return [-1]


def main():
    N = read_int()
    B = read_int_n()
    for r in slv(N, B):
        print(r)

    # N = 10
    # B = []
    # for i in range(N):
    #     j = random.randint(0, i)
    #     B.insert(j, j)
    #     print(j+1)
    # B = list(map(lambda x: x+1, B))
    # print(B)

    # for r in slv(N, B):
    #     print(r)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = input()
b_list = list(map(int, input().split()))

p_list = []
m_list = []
z_list = []

for num, b in enumerate(b_list):
    num+=1
    
    idx = b-num
    
#     " 実現不可能 "
    if idx>0:
        print(-1)
        exit()
    elif idx<0:
        m_list.append(b)
    elif idx==0:
        if num==1:
            continue
        z_list.append(b)

z_list.sort()
sol_list = []
sol_list.append(1)

if len(m_list):
    
    m_list.sort(reverse=True)
    m_max = max(m_list)
    o_list = []

    import numpy as np
    care_dict = {}
    
    for num, i in enumerate(b_list):
        if i!=m_max:
            continue
        d_list = []
        for j in b_list[num+1:]:
            diff = i-j
            d_list.append(diff)
        d_list = np.array(d_list)
        d_list = d_list[d_list>0]
        if len(d_list):
            care_dict[i] = len(d_list)
        
    for m in m_list:
        
        for o in o_list:
            gr = care_dict[o]
            if len(sol_list)>= o+(gr-1):
                sol_list.append(o)
                o_list.remove(o)
        
        if m in care_dict.keys():
            gr = care_dict[m]
            
    #         print(len(sol_list), m+(gr-1))
            
            if len(sol_list)>= m+(gr-1):
                sol_list.append(m)
            else:
                o_list.append(m)
        else:
            sol_list.append(m)
            
    for o in o_list:
        gr = care_dict[o]
        if len(sol_list)>= o+(gr-1):
            sol_list.append(o)
            o_list.remove(o)
        
for z in z_list:
    sol_list.append(z)

for s in sol_list:        
    print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = input().split()

ans=[2]*n

for i in range(n):
    b[i] = int(b[i])
    ans[i] = b[i]


# n個の配列を全て0で埋める
#ans=[2]*n

for i in range(n):
    
    for j in reversed(range(b[i],i+1)):
        ans[j] = ans[j-1]
    
    
    ans[b[i]-1] = b[i]

flag = 0
for i in range(n):
    if ans[i] == 1:
        flag = 1
        
        
if flag == 0:
    print(-1)

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

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

originLinks = list(itertools.combinations(list(range(1,n+1)), 2))
originLinkNum = len(originLinks)
end = False
for leftLinkNum in range(originLinkNum, n-2, -1):
  # print(leftLinkNum)
  if end:
    break
  tempGraph = list(itertools.combinations(originLinks, leftLinkNum))
  # print(tempGraph)
  for graph in tempGraph:
    # print(graph)
    sums = [0] * n
    for link in graph:
      sums[link[0]-1] += link[1]
      sums[link[1]-1] += link[0]
    # print(sums, len(set(sums)))
    if len(set(sums)) == 1:
      #print(graph)
      print(len(graph))
      for link in graph:
        print(" ".join(list(map(str, link))))
      end = True
      break

Submission status: Wrong Answer

Solution code:
n = int(input())
b = list(map(int, input().split()))
for i in range(n):
  if b[i] > i+1:
    print(-1)
    break
else:
  ans = []
  while len(b) > 1:
#    print(ans,b)
    c = len(ans)
    f = b[0]
    for i in range(1, len(b))[::-1]:
      if b[i] == i + 1:
#        print("check", b[i:])
        ans.append(b.pop(i))
        break
    for i in range(1, len(b)):
#      print(f, i, b, n - c, ans)
      if f >= b[i]:
        ans.append(b.pop(i-1))
        break
      elif n - c == b[i]:
        ans.append(b.pop(i))
        break
      elif i == len(b) - 1:
        ans.append(b.pop(-1))
        break
      else:
        f = b[i]
  ans.append(1)
  for i in range(n)[::-1]:
    print(ans[i])

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import sys
n = int(input())
a = []
b = list(map(int, input().split()))
for i in range(len(b)):
    if b[i] > i+1:
        print(-1)
        sys.exit()
b_sort = sorted(b)
b_arr = [0 for i in range(100)]
for i in range(100):
    b_arr[i] = b.count(i+1)
i = 1
j = 1
while sum(b_arr) > 0:
    if b_sort[i-1] <= j and b_sort[i-1] > 0:
        if b_arr[b_sort[i-1]-1] > 0:
            b_arr[b_sort[i-1]-1] -= 1
            a.insert(j-1, b_sort[i-1])
        else:
            b_arr[max(b_sort[:i])-1] = 0
            i += 1
        #print(max(b_sort[:i]))
    j += 1
if len(a) == len(b_sort):
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
b = list(input())
while ' ' in b[:]:
    b.remove(' ')
b_cp = b[:]
b_cp.sort(reverse=True)
ans = ['*' for i in range(N)]

for _ in range(N):
    max = b_cp[0]
    idx = b.index(max)
    shift = idx + 1 - int(max)
    k = N-1
    while True:
        if k < 0:
            print(-1)
            sys.exit()
        cnt = 0
        inc = max
        for l in range(k+1, N):
            if ans[l] == '*' or int(ans[l]) <= int(inc):
                cnt += 1
                if not inc == '9':
                    inc = str(int(max)+1)
        if cnt == shift and ans[k] == '*':
            break
        k -= 1
    ans[k] = max
    b_cp.pop(0)
    b[idx] = '*'

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
b_rev = []
op = []
for i in (reversed(b)):
    b_rev.append(i)

if b_rev.count(1) == 0 or b[0] != 1:
    print(-1)
    exit()
while 1:
    if len(b_rev) == 0:
        for i in op:
            print(i)
        else:
            exit()
    idx_one = b_rev.index(1)
    op.append(1)
    b_tmp = b_rev[0:idx_one]
    for idx,val in enumerate(b_tmp):
        if idx + 2 < val:
            print(-1)
            exit()
    while len(b_tmp) > 0:
        min_tmp = min(b_tmp)
        for idx, item in enumerate(b_tmp):
            if item == min_tmp:
                idx_min = idx
        op.append(b_tmp.pop(idx_min))
    else:
        del b_rev[0:idx_one + 1]

Submission status: Wrong Answer

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

# -*- coding: utf-8 -*-

from sys import stdin

###########################################

############################################
#from sys import stdin
import numpy as np

# read data for n sequences.
n = stdin.readline().split()
data = stdin.readline().split()

out = []

token = 0

# check first data and return -1 if != 1
if int(data[0]) != 1:
    token = -1
else:    
    a=1
# print first data
#    out.append(1)

for i,x in enumerate(data):
    data[i]=int(x)
    
# split to multiple data.
x = 0
split = []
chunck = []
#while x < len(data):
for i,num in enumerate(data[x:]):
    if num == 1:
        if i == 0:
            chunck.append(num)
            continue
#            chunck = [1]
        split.append(chunck)
        chunck=[]
    chunck.append(num)        
#        x = i+1
if chunck != []:
    split.append(chunck)

for x in reversed(split):
    maxnum=max(x)
    if x == [1]:
        out.append(1)
    else:
        for i in range(1,maxnum+1):
            if i in x:
                count = x.count(i)
                if x.index(i) >= i-1:
                    for xx in range(count):
                        out.append(i)
                else:
                    token = -1

if token == -1:
    print(-1)
else:
    # print outputs
    for x in out:
        print(x)

Submission status: Wrong Answer

Solution code:
N=int(input())
BBB=[int(x) for x in input().split()]

BB=[0 for i in range(N)]
def re(B,n):
  global BB
  if n==1:
    BB[0]=B[0]
    for i in BB:
      print(i)
    exit()
  for i in range(n):
    if B[i]>i+1:
      return 1
    if B[i]==i+1:
      BB[n-1]=B[i]
      re(B[:i]+B[i+1:n],n-1)
  return -1

result=re(BBB,N)
print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))
print(-1)

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
b = list(map(int, input().split()))
c = copy.deepcopy(b)
data = [-1] * N
numflag = [True] * N 
counter = 0
flag = True
for i in range(N, 0, -1):
    for j in range(N):
        if i == b[j]:
            num = N - (j - b[j]) - 2
            if num < 0 or num > N-1:
                flag = False
                break
            while True:
                if numflag[num]:
                    data[num] = b[j]
                    numflag[num] = False
                    break
                else:
                    num -= 1
                    if num < 0:
                        flag = False
                        break
if flag:
    for i in range(N):
        print(data[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
for i in range(len(b)):
  if b[i]>i+1:
    print(-1)
    exit()
check=[]
c=[]
d=[]
q=[]
def counter(x,i):
  count=0
  while True:
    if b[i-1]==x:
      return count
    else:
      i-=1
      count+=1
for i in range(len(b)):
  c.append(b[i])
  if b[i]<max(c):
    check.append([max(c),b[i],counter(b[i],i)])
for i in range(1,check[-1][1]):
  print(i)
  d.append(i)
  q.append(i)
for i in range(len(check)-1,-1,-1):
  if check[i][1] in q:
    print(check[i][1])
    q.pop(q.index(check[i][1]))
    d.append(check[i][1])
  else:
    print(check[i][1])
    print(check[i][1])
    d.append(check[i][1])
    d.append(check[i][1])
  for j in range(check[i][2]):
    print(check[i][0])
    d.append(check[i][0])
for i in range(101,0,-1):
  for j in range(b.count(i)-d.count(i)):
    print(i)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
b = na()

if b[0] != 1:
  print('-1')
  sys.exit()

for i in range(1,n):
  d = b[i]-b[i-1]
  if abs(d) > 1:
    print('-1')
    sys.exit()

b.reverse()

def sr(l,m):
  for u in range(len(l)):
    if l[u] == m:
      return u
  return -1

ans = []
p = 1
k = 0
while(b):
  x = sr(b,p)
  y = sr(b,p+1)
  if p == 1:
    k = x+1
  if x == -1:
    p -= 1
  else:
    ans.append(b.pop(x))
    k -= 1
    if k == 0 and len(b) > 0:
      p = 1
      continue
    if x > y:
      p += 1

for a in ans:
  print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(i) for i in input().split()]

def saiki(q,count,z,ans):
    for i in range(z,q):
        if B[-i] <= count:
            ans.append(B[-i])
            if i != z:
                count += 1
                saiki(i,count,z,ans)
            else:
                z += 1

z = 1
i = 1
ans = []
while len(B) != 0:
    count = 1
    try:
        if B[-i] <= count:
            ans.append(B[-i])
            count += 1
            saiki(i,count,z,ans)
            B = B[:N-i]
    except IndexError:
        break
    i += 1

if len(ans) == N:
    for i in ans:
        print(i)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
b_rev = []
op = []
for i in (reversed(b)):
    b_rev.append(i)

if b_rev.count(1) == 0 or b[0] != 1:
    print(-1)
    exit()
while 1:
    if len(b_rev) == 0:
        for i in op:
            print(i)
        else:
            exit()
    idx_one = b_rev.index(1)
    op.append(1)
    b_tmp = b_rev[0:idx_one]
    for idx,val in enumerate(b_tmp):
        if idx + 1 < val:
            print(-1)
            exit()
    while len(b_tmp) > 0:
        min_tmp = min(b_tmp)
        for idx, item in enumerate(b_tmp):
            if item == min_tmp:
                idx_min = idx
        op.append(b_tmp.pop(idx_min))
    else:
        del b_rev[0:idx_one + 1]

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
for i in range(len(b)):
  if b[i]>i+1:
    print(-1)
    exit()
check=[]
c=[]
d=[]
q=[]
def counter(x,i):
  count=0
  while True:
    if b[i-1]==x:
      return count
    else:
      i-=1
      count+=1
for i in range(len(b)):
  c.append(b[i])
  if b[i]<max(c):
    check.append([max(c),b[i],counter(b[i],i)])
for i in range(1,check[-1][1]):
  print(i)
  d.append(i)
  q.append(i)
for i in range(len(check)-1,-1,-1):
  if check[i][1] in q:
    print(check[i][1])
    q.pop(q.index(check[i][1]))
    d.append(1)
  else:
    print(check[i][1])
    print(check[i][1])
    d.append(check[i][1])
    d.append(check[i][1])
  for j in range(check[i][2]):
    print(check[i][0])
    d.append(check[i][0])
for i in range(101,0,-1):
  for j in range(b.count(i)-d.count(i)):
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = list(map(int,input().split()))

for i in range(N) :
    if B[i] > i+1 :
        print(-1)
        break
else :
    while len(B) :
        b = min(B)
        for j in range(len(B)-1,-1,-1) :
            if b == B[j] :
                L = sorted(B[j:])
                print(*L,sep="\n")
                B = B[:j]
                break

Submission status: Wrong Answer

Solution code:
#何にもわからないけど一か月後には解けるようになる予定なので許して

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
l = collections.Counter()
ppp = [0 for i in range(100)]
for i in a:
    l[i] += 1

l = l.most_common()
l.sort()
for i in range(n):
    k = a[i]
    if k > i+1:
        print(-1)
        exit()
c = 0
for i in range(n-2):
    if a[-(i+1)] > a[-(i+2)] and c == 0:
        p = a[-(i+1)]
        a[-(i+1)] = a[-(i+2)]
        a[-(i+2)] = p
        c += 2
    else:
        if c > 0:
            c -= 1
        
b = a[1:]
b.reverse()
a = [a[0]] + b
for i in range(n):
    print(a[i])

Submission status: Wrong Answer

Solution code:
def rightMinNumber(L):
    min = L[len(L)-1]
    min_index = len(L) - 1
    if len(L) > 1:
        for i in range(len(L)-2,-1,-1):
            if L[i] < min:
                min = L[i]
                min_index = i
    a.append(min)
    if min_index+1 == len(L) and min_index == 0:
        return
    if min_index + 1 < len(L):
        rL = L[min_index+1:]
        rightMinNumber(rL)
    if min_index > 0:
        lL = L[:min_index]
        rightMinNumber(lL)

N = int(input())
B = [int(_) for _ in input().split()]
#出力
a = []
#Bのエンコーダを作る
x = 0

#Bの正当性を調べる。
for i in range(N):
    if B[i] > i+1:
        x = -1
        break

if x == -1:
    print(x)
else :
    rightMinNumber(B)
    for i in range(N):
        print(a[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))

b_order = [-1]*N

def f():
    cnt = 0
    for i in range(N-1,-1,-1):
        i_order = N - (i + 1 - b[i])

        if i_order > N:
            print(-1)
            return

        while b_order[i_order - 1] != -1:
            i_order -= 1
            if i_order < 0:
                print(-1)
                return

        b_order[i_order - 1] = b[i]
        cnt += 1

    if cnt < N:
        print(-1)
        return

    for i in b_order:
        print(i)
    return

f()

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(i) for i in input().split()]
A = []
O = []
for i in range(1, N+1):
    ii = -1
    for ii, (b, a) in enumerate(zip(B[::-1], A[::-1])):
        if b != a:
            num = len(A)-ii+1
            if num == b:
                A.insert(num-1, num)
                O.append(num)
            else:
                ii = len(A)-1
            break
    if ii == len(A)-1:
        A.insert(0, 1)
        O.append(1)
if A != B:
    print(-1)
else:
    for i in O:
        print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
b = input().split()

ans=[2]*n

for i in range(n):
    b[i] = int(b[i])
    ans[i] = b[i]


# n個の配列を全て0で埋める
#ans=[2]*n

for i in range(n):
    
    for j in reversed(range(b[i],i+1)):
        ans[j] = ans[j-1]
    
    
    ans[b[i]-1] = b[i]

if ans[0] != 1:
    print(-1)
else:
    for i in range(n):
        print(ans[i])

Submission status: Wrong Answer

Solution code:
import copy

def xxx(b):
    #print(b)

    for i in range(len(b)):
        #print(b[i], i+1)
        
        if len(b) == 1 and b[0] == i+1:
            print(i+1)
            return 0
        
        if not(b[i] == i+1):
            
            if i == 0:
                return -1
            else:

                
                next_b = copy.deepcopy(b)
                next_b.pop(i-1)
                r = xxx(next_b)
                if r == 0:
                    print(i)
                    return 0
        
        else:
            if len(b) == 1:
                print(i+1)
                return 0
            if len(b) == i+1:
                for j in range(len(b)):
                    print(j+1)
                return 0
                
            
    return -1
        

n = (int(input()))
b = [int(x) for x in input().split()]

r = xxx(b)
if r == -1:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
B = [int(i) for i in input().split()]
C = B[::]
B.reverse()

result = []

def solve(target, left, right):
    for i in range(left, right):
        if B[i] == target:
            result.append(target)
            solve(target + 1, left, i)
            left = i

solve(1, 0, N)

ans = []
for i, ri in enumerate(result):
    ans.insert(ri - 1, ri)

if ans == C:
    for ri in result:
        print(ri)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
if b[0] > 1:
    print(-1)
else:
    for i in range(N):
        if b[i] > i:
            print(-1)
            break
        elif b.index(max(b)) < N-3:
            print(-1)
            break

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
j=True
for i in range(n):
    if b[i]>i+1:
        j=False
if not j:
    print("-1")
else:
    x=[0]
    for i in range(1,n):
        if b[i]<=b[i-1] or b[i-1]==1:
            x.append(i)
    x.append(n)
    #print(x)
    print(1)
    for i in range(-2,-len(x),-1):
        for j in b[x[i]:x[i+1]]:
            print(j)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力

N = int(raw_input())

b = map(int, raw_input().split(' '))
print b

if 1 not in b:
    print -1
    exit()

a = []

for i in range(N, 0, -1):
    for j in range(i, 0, -1):
        if b[j-1] == j:
            a.append(j)
            b.pop(j-1)
            break


for i in (reversed(a)):
    print i

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import sys
n = int(input())
a = []
b = list(map(int, input().split()))
for i in range(len(b)):
    if b[i] > i+1:
        print(-1)
        sys.exit()
b_sort = sorted(b)
b_arr = [0 for i in range(100)]
for i in range(100):
    b_arr[i] = b.count(i+1)
cnt = 0
for i in range(1, n+1):
    if b_sort[i-1] <= i and b_sort[i-1] > 0:
        a.insert(i-1, b_sort[i-1])
        if b_arr[b_sort[i-1]-1] > 0:
            b_arr[b_sort[i-1]-1] -= 1
        else:
            b_arr[max(b_sort[:i])-1] -= 10
        #print(max(b_sort[:i]))
if len(a) == len(b_sort):
    for i in range(len(a)):
        print(a[i])
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
b=list(map(int,input().split()))
for i in range(len(b)):
  if b[i]>i+1:
    print(-1)
    exit()
check=[]
c=[]
d=[1]
def counter(x,i):
  count=0
  while True:
    if b[i-1]==x:
      return count
    else:
      i-=1
      count+=1
for i in range(len(b)):
  c.append(b[i])
  if b[i]<max(c):
    check.append([max(c),b[i],counter(b[i],i)])
print(1)
for i in range(len(check)-1,-1,-1):
  if i==0 and check[0][1]==1:
    print(1)
    d.append(1)
  else:
    print(check[i][1])
    print(check[i][1])
    d.append(check[i][1])
    d.append(check[i][1])
  for j in range(check[i][2]):
    print(check[i][0])
    d.append(check[i][0])
for i in range(101,0,-1):
  for j in range(b.count(i)-d.count(i)):
    print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
ans = []
queue = []
n = 1

if 1 not in b:
    ans = [-1]
else:
    start = N
    for i in range(N-1, -1, -1):
        if b[i] == 1:
            queue.append(b[i:start])
            start = i

    for a in queue:
        if len(a) == 1:
            if a[0] != 1:
                ans = [-1]
                break
            else:
                ans.append(1)
        else:
            flag = True
            for i in range(len(a)):
                if a[i] <= n+i+1:
                    pass
                else:
                    flag = False
                    ans = [-1]
                    break

            if not flag:
                break

            tmp = []
            next_pass = False
            idx = 0
            x = None
            for i in range(len(a)-1, 0, -1):
                if not next_pass:
                    if a[i-1] <= a[i]:
                        tmp.insert(idx, a[i])
                        tmp.insert(idx, a[i-1])
                        next_pass = True
                        x = i-1
                    else:
                        tmp.append(a[i])
                        idx = len(tmp)
                        x = i
                else:
                    next_pass = False
            if x != 0:
                tmp.insert(0, 1)
            ans.extend(tmp)
        n += len(a)

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = list(map(int, input().split()))
b_rev = []
op = []
for i in (reversed(b)):
    b_rev.append(i)

if b_rev.count(1) == 0 or b[0] != 1:
    print(-1)
    exit()
while 1:
    if len(b_rev) == 0:
        for i in op:
            print(i)
        else:
            exit()
    idx_one = b_rev.index(1)
    op.append(1)
    b_tmp = b_rev[0:idx_one]
    while len(b_tmp) > 0:
        min_tmp = min(b_tmp)
        for idx, item in enumerate(b_tmp):
            if item == min_tmp:
                idx_min = idx
        op.append(b_tmp.pop(idx_min))
    else:
        del b_rev[0:idx_one + 1]

Submission status: Wrong Answer

Solution code:
n = int(input())

b = []
for _b in list(map(int, input().split())):
    if _b > len(b) + 1:
        print('-1')
        exit()
    b.insert(_b, str(_b))

print('\n'.join(b))

Submission status: Wrong Answer

Solution code:
#最後のやつがjならはj番目にできたと確定する
N=int(input())
b=list(map(int,input().split()))
ans=[0 for i in range(N)]#k番目にans[k-1]が入ったよの表
for i in reversed(range(1,N+1)):
    num=b[i-1]#頭からi番目の数
    sa_left=i-num#n-saleftから検証
    if sa_left<0:
        break
    for j in reversed(range(1,N-sa_left+1)):
        if ans[j-1]==0:
            ans[j-1]=num
            break
if all(k!=0 for k in ans):
    for i in ans:
        print(i)
else:
    print("-1")