#P10382. 「HOI R1」杂造选构

    ID: 11563 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2024Special JudgeO2优化构造Ad-hoc分类讨论洛谷比赛

「HOI R1」杂造选构

Background

Little \iiint has nothing to do with this annoying construction problem.

Problem Description

A sequence aa is called valid if it satisfies the following requirements:

  • ai=1a_i = -1 or ai[1,n]a_i \in [1,n].
  • For every ai1a_i \not= -1, add a directed edge aiia_i \to i. The graph formed in this way has no cycles.

Now you are given an integer xx and a sequence aa, where all elements of aa are integers in the range [1,n][-1,n]. Please replace every position with ai=0a_i = 0 by some other integer, so that i=1nai=x\sum\limits ^{n} _{i=1} a_i = x and aa is valid. If no such solution exists, report that there is no solution.

Input Format

The first line contains two integers nn and xx.

The second line contains nn integers, representing the sequence aa. It is guaranteed that ai[1,n]\forall a_i \in [-1,n].

Output Format

If there is no solution, it means you were fooled, so output a string Rick. Otherwise output nn integers, representing the sequence aa after replacing all elements that are 00.

6 -6
-1 -1 -1 0 0 0
-1 -1 -1 -1 -1 -1
6 14
0 1 4 0 1 4
-1 1 4 5 1 4
6 10
0 0 0 0 0 0
-1 -1 4 5 -1 4
6 6
1 1 0 0 0 0
Rick
6 40
0 0 0 0 0 0
Rick

Hint

This problem uses bundled tests.

Subtask Score nn \le xx \le Special property
#0 1313 1515 225225 None
#1 2424 10310^3 10910^9
#2 2727 10510^5 101810^{18} Yes
#3 3636 None

*Special property: it is guaranteed that ai=0\forall a_i = 0.

For all testdata, 1n1051 \le n \le 10^5, 1018x1018-10^{18} \le x \le 10^{18}.


Special Judge return value table

  • Accepted. The answer is correct.
  • Oops, your answer is wrong. 1 The correct answer has no solution, but the contestant output says there is a solution.
  • Oops, your answer is wrong. 2 The contestant’s output has aix\sum a_i \not = x.
  • Oops, your answer is wrong. 3 The contestant’s output contains 00.
  • Oops, your answer is wrong. 4 The contestant’s output contains a cycle.
  • Oops, your answer is wrong. 5 While filling in the blanks, the contestant modified positions where the input has ai0a_i \not= 0.

Translated by ChatGPT 5