No.1401 全自動マクロの作り方
タグ : / 解いたユーザー数 16
作問者 :
CuriousFairy315
/ テスター :
hotman78
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
315-san's job is to paste images into Excel and run batch files exactly as instructed.
This job is monotonous and tedious, and 315-san had always wanted to do more advanced work.
One day, 315-san realized that this job can be represented by at most $N$ operation sequences $S$.
The operation sequence $S_i$ is a sequence of length $d_i$, and each term of this sequence corresponds one-to-one to an operation of an input device, such as a key.
Since 315-san enjoys competitive programming, 315-san decided to create a macro that automatically completes the work no matter what work is assigned.
A macro is defined as an integer sequence $A$ consisting of integers between $0$ and $2000$, inclusive.
First, define a sequence $M$ of length $N$ whose terms are all $0$.
Next, for $n=0, 1, 2, \dots, $, perform the following operations in order.
- Find all $j$ such that $A_{(n \mod |A|) + 1} = S_{j, (M_j \mod |S_j|) + 1}$.
- Then, for all of those $j$, add $1$ to $M_j$.
315-san wants the macro $A$ that finishes the work fully automatically to satisfy the following condition.
- There exists an $n$ such that $n$ is a multiple of $|A|$ $-1$, that is, at the moment exactly the end of the macro has been read, all the work is in the accomplished state.
Input
$N$
$d_1 \ S_{1,1} \ \cdots \ S_{1, d_1}$
$\vdots$
$d_N \ S_{N, 1} \ \cdots \ S_{N, d_N}$
- $1 \leq N \leq 2000$
- $1 \leq d_i \leq 2000$
- $0 \leq S_{i, j} < \sum_{i=1}^{N} d_i \leq 2000$
- All inputs are integers.
Output
If no macro $A$ satisfying the condition exists, print 0 on the first line.
Otherwise, first print the length of the macro $|A| \leq 2000$ on the first line.
Then, print the terms of $A$ separated by spaces on the second line.
In either case, print a newline at the end.
Sample
Sample 1
Input
1 3 1 2 1
Output
3 1 2 1
The macro 1 2 1 is a valid macro, because the work can be accomplished exactly 1 time when the macro has been executed 1 time.
Note that macros such as 1 2 1 1 2 1 are also accepted as correct, but 1 and 1 2 1 1 are not accepted as correct.
Sample 2
Input
3 3 1 1 2 1 1 5 3 1 1 1 2
Output
4 3 1 1 2
The macro 3 1 1 2 is a valid macro, because when the macro has been executed 2 times, work 1 can be accomplished 2 times, work 2 can be accomplished 4 times, and work 3 can be accomplished 1 time.
Sample 3
Input
2 2 1 2 2 2 1
Output
0
No macro exists that can accomplish all of this work.
Let's quietly keep doing the work by hand.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。