Score: 625 points
问题陈述
一个正整数序列 T=(T1,T2,…,TM) 的长度为 M,如果且仅如果对于每个 i=1,2,…,M,都有 Ti=TM−i+1,则称其为一个回文序列。
给定一个非负整数序列 A=(A1,A2,…,AN) 的长度为 N。确定是否存在一个正整数序列 S=(S1,S2,…,SN) 的长度为 N,满足以下条件,如果存在,找到字典序最小的这样一个序列。
- 对于每个 i=1,2,…,N,以下两个条件都成立:
- 序列 (Si−Ai,Si−Ai+1,…,Si+Ai) 是一个回文序列。
- 如果 2≤i−Ai 且 i+Ai≤N−1,序列 (Si−Ai−1,Si−Ai,…,Si+Ai+1) 不是一个回文序列。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
A sequence of positive integers T=(T1,T2,…,TM) of length M is a palindrome if and only if Ti=TM−i+1 for each i=1,2,…,M.
You are given a sequence of non-negative integers A=(A1,A2,…,AN) of length N. Determine if there is a sequence of positive integers S=(S1,S2,…,SN) of length N that satisfies the following condition, and if it exists, find the lexicographically smallest such sequence.
- For each i=1,2,…,N, both of the following hold:
- The sequence (Si−Ai,Si−Ai+1,…,Si+Ai) is a palindrome.
- If 2≤i−Ai and i+Ai≤N−1, the sequence (Si−Ai−1,Si−Ai,…,Si+Ai+1) is not a palindrome.
Constraints
- 1≤N≤2×105
- 0≤Ai≤min{i−1,N−i}
- All input values are integers.
The input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
If there is no sequence S that satisfies the condition, print No
.
If there is a sequence S that satisfies the condition, let S′ be the lexicographically smallest such sequence and print it in the following format:
Yes
S1′ S2′ … SN′
7
0 0 2 0 2 0 0
Sample Output 1
Yes
1 1 2 1 1 1 2
S=(1,1,2,1,1,1,2) satisfies the condition:
- i=1: (A1)=(1) is a palindrome.
- i=2: (A2)=(1) is a palindrome, but (A1,A2,A3)=(1,1,2) is not.
- i=3: (A1,A2,…,A5)=(1,1,2,1,1) is a palindrome.
- i=4: (A4)=(1) is a palindrome, but (A3,A4,A5)=(2,1,1) is not.
- i=5: (A3,A4,…,A7)=(2,1,1,1,2) is a palindrome.
- i=6: (A6)=(1) is a palindrome, but (A5,A6,A7)=(1,1,2) is not.
- i=7: (A7)=(2) is a palindrome.
There are other sequences like S=(2,2,1,2,2,2,1) that satisfy the condition, but print the lexicographically smallest one, which is (1,1,2,1,1,1,2).
7
0 1 2 3 2 1 0
Sample Output 2
Yes
1 1 1 1 1 1 1
7
0 1 2 0 2 1 0
Sample Output 3
No