Codeforces Round #166 (Div. 2) c. Secret

Source: Internet
Author: User
Tags union of sets
C. Secrettime limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard input

Output

Standard output

The Greatest Secret Ever consistsNWords, indexed by positive integers from 1N.
The secret needs dividingKKeepers (let's index them by positive integers from 1K),
TheI-Th Keeper gets a non-empty set of words with numbers from the setUISignature = Signature (UI, Period 1, Period,UI, Interval 2, interval..., interval ,...,UI, Bytes |UI| ).
Here and below we'll presuppose that the set elements are written in the increasing order.

We'll say that the secret is safe if the following conditions are hold:

  • For any two indexesI, Bytes,J(1 digit ≤ DigitILatency <latencyJLimit ≤ limitK)
    The intersection of setsUIAndUJIs
    An empty set;
  • The union of setsU1, bytes,U2, middle..., middle ,...,UKIs
    Set (1, second 2, second..., second ,...,N);
  • In each setUI,
    Its elementsUI, Period 1, Period,UI, Interval 2, interval..., interval ,...,UI, Bytes |UI| Do
    Not form an arithmetic progression (in particle, |UI| Limit ≥ limit 3 shoshould
    Hold ).

Let us remind you that the elements of set (U1, bytes,U2, middle..., middle ,...,US) Form
An arithmetic progression if there is such numberD, That for allI(1 digit ≤ DigitILatency <latencyS)
FulfillsUIRegion + RegionDSignature = SignatureUIUpload + upload 1.
For example, the elements of sets (5), (1, limit 10) and (1, limit 5, limit 9) form
Arithmetic progressions and the elements of sets (1, phase 2, phase 4) and (3, Phase 6, Phase 8) don't.

Your task is to find any partition of the set of words into subsetsU1, bytes,U2, middle..., middle ,...,UKSo
That the secret is safe. Otherwise indicate that there's no such partition.

Input

The input consists of a single line which contains two integersNAndK(2 cores ≤ CoresKLimit ≤ limitNLimit ≤ limit 106)
-The number of words in the secret and the number of the Keepers. The numbers are separated by a single space.

Output

If there is no way to keep the secret safe, print a single integer "-1" (without the quotes). Otherwise, printNIntegers,I-Th
Of them representing the number of the Keeper who's gotI-Th word of the secret.

If there are multiple solutions, print any of them.

Sample test (s) input
11 3
Output
3 1 2 1 1 2 3 2 2 3 1
Input
5 2
Output
-1

Note the red line of the original article.

Given that n is 1-n, k is the number of sets.

Is that the number of each set must be greater than or equal to 3, and the number in the set must be arranged in ascending to smallest order, which cannot constitute an arithmetic difference series. Each set cannot have an intersection, and all the Union sets are the set.

Let's enumerate the numbers that should be included in each set and output a result.

I want to enumerate

Example n = 11 k = 3

Enumeration

1 2 3 3 2 1 1 2 3 3 2

1 2 3 4 5 6 7 8 9 10 11

However, it is found that for the set 2, it is an error series.

In this example, the enumeration is suitable for a set with an even number and is not suitable for a set with a base number.

So I can change the location.

1 2 3 {2 3} 1 1 2 3 3 2

1 2 3 4 5 6 7 8 9 10 11

Post code:

# Include <stdio. h> int n, k; void even () {int I; while (1) {for (I = 1; I <= k; I ++) {printf ("% d", I); n --; if (n = 0) goto end;} int add = 1; for (; I <= 2 * k; I ++) {printf ("% d", I-add); add + = 2; n --; if (n = 0) goto end ;}} end: printf ("\ n");} void odd () {int I, mid = k/2 + k + 1, beg = 1; while (1) {for (I = 1; I <= k; I ++) {printf ("% d", I); n --; if (n = 0) goto end;} int add = 1, temp; for (; I <= 2 * k; I ++) {if (I = mid & beg = 1) {temp = I-add; goto po Int;} // here, change the position if (I = mid + 1 & beg = 1) {printf ("% d", I-add, temp); goto point;} printf ("% d", I-add); point: add + = 2; n --; if (n = 0) goto end ;} beg ++;} end: printf ("\ n");} int main () {while (scanf ("% d", & n, & k )! = EOF) {if (k * 3> n) printf ("-1 \ n"); else {if (k % 2 = 0) even (); else odd ();}}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.