codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

271C.md (2260B)


      1 Source: https://codeforces.com/problemset/problem/271/C
      2 
      3 C. Secret
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 The Greatest Secret Ever consists of *n* words, indexed by positive integers from 1 to *n*. The secret needs dividing between *k* Keepers (let's index them by positive integers from 1 to *k*), the *i*-th Keeper gets a non-empty set of words with numbers from the set *U**i* = (*u**i*, 1, *u**i*, 2, ..., *u**i*, |*U**i*|). Here and below we'll presuppose that the set elements are written in the increasing order.
     22 
     23 We'll say that the secret is safe if the following conditions are hold:
     24 
     25 * for any two indexes *i*, *j* (1 ≤ *i* < *j* ≤ *k*) the intersection of sets *U**i* and *U**j* is an empty set;
     26 * the union of sets *U*1, *U*2, ..., *U**k* is set (1, 2, ..., *n*);
     27 * in each set *U**i*, its elements *u**i*, 1, *u**i*, 2, ..., *u**i*, |*U**i*| do not form an arithmetic progression (in particular, |*U**i*| ≥ 3 should hold).
     28 
     29 Let us remind you that the elements of set (*u*1, *u*2, ..., *u**s*) form an arithmetic progression if there is such number *d*, that for all *i* (1 ≤ *i* < *s*) fulfills *u**i* + *d* = *u**i* + 1. For example, the elements of sets (5), (1, 10) and (1, 5, 9) form arithmetic progressions and the elements of sets (1, 2, 4) and (3, 6, 8) don't.
     30 
     31 Your task is to find any partition of the set of words into subsets *U*1, *U*2, ..., *U**k* so that the secret is safe. Otherwise indicate that there's no such partition.
     32 
     33 Input
     34 
     35 The input consists of a single line which contains two integers *n* and *k* (2 ≤ *k* ≤ *n* ≤ 106) — the number of words in the secret and the number of the Keepers. The numbers are separated by a single space.
     36 
     37 Output
     38 
     39 If there is no way to keep the secret safe, print a single integer "-1" (without the quotes). Otherwise, print *n* integers, the *i*-th of them representing the number of the Keeper who's got the *i*-th word of the secret.
     40 
     41 If there are multiple solutions, print any of them.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 11 3
     49 ```
     50 
     51 Output
     52 
     53 ```
     54 3 1 2 1 1 2 3 2 2 3 1
     55 ```
     56 
     57 Input
     58 
     59 ```
     60 5 2
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 -1
     67 ```