#110. 按规则生成数组模式

    ID: 110 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-3gesp2循环结构模拟

按规则生成数组模式

Array Pattern Generation

Background

Problem Description

Given an integer n0n \ge 0, create an array of length nimesnn imes n following a specific pattern. The pattern for n=3n=3 is shown as: {0,0,1,0,2,1,3,2,1}\{0, 0, 1, 0, 2, 1, 3, 2, 1\} (spaces added to show the nn groups).

The array can be thought of as nn groups, each of length nn. Let AA be the array, and A[idx]A[idx] be its element at index idxidx.

For an element at index idxidx, let k=idx/nk = \lfloor idx / n \rfloor be the group index (0-indexed) and j=idx(modn)j = idx \pmod n be the index within the group (0-indexed).

The value of A[idx]A[idx] is determined as follows:

  • If j=n1j = n-1, then A[idx]=1A[idx] = 1.
  • Otherwise (j<n1j < n-1): Let val=njval = n - j. Let min_k=n1jmin\_k = n - 1 - j. If kmin_kk \ge min\_k, then A[idx]=valA[idx] = val. Else (k<min_kk < min\_k), then A[idx]=0A[idx] = 0.

Input Format

Input is given from standard input in the following format.

An integer nn.

Output Format

Output is printed to standard output in the following format.

The generated array as a list of integers.

Sample

3
[0, 0, 1, 0, 2, 1, 3, 2, 1]
2
[0, 1, 2, 1]
4
[0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]

Sample Explanation

Constraints

Time limit: 1 second, Memory limit: 1024 KiB for each test case.