Chapter 03

SiganAI
2022.11.18に更新
このチャプターの目次

# コンテスト名

AtCoder Beginner Contest 276

# 反省点

ググったら配列の要素外参照を疑ったほうが良いらしいけど．．．どこだ？

# コード（2022/11/18版）

python
``````def first_input():
N = input()
return int(N)

def second_input(N):
P_list = []
p_index = input().split()
for i in range(N):
P_list.append(int(p_index[i]))
return P_list

def pick_up_target_index(P_list):
for i in range(1,len(P_list)):
target_behind = P_list[len(P_list)-i]
target_front = P_list[len(P_list)-i-1]
if target_behind < target_front:
return len(P_list)-i-1

def output_answer(P_list, front_index):
answer = []
if not front_index == 0:
for i in range(front_index):
answer.append(P_list[i])
target = P_list[front_index:]
a = target[0] -1
answer.append(a)
target.remove(a)
target = list(reversed(sorted(target)))
answer.extend(target)
answer_str = [str(n) for n in answer]
answer_str = ' '.join(answer_str)
print(answer_str)

N = first_input()
P_list = second_input(N)
front_index = pick_up_target_index(P_list)
output_answer(P_list, front_index)
``````