TPERML - Permutation generator
Wersja polska | English version |
For each index of n element permutation print m subsequent permutations (in separate lines) in lexicographical order starting from the one pointed by index. Between outputs of subsequent tests there should be an empty line. Next permutation to the last one is the first one.
Input
t [number of tests <= 1000]
n index m [2 <= n <= 100 - number of elements in permutation, 0 <= index < n! - index of the first permutation, 1 <= m <= 100 - how many permutations to print]
Output
p1 p2 ... p(n-1) pn [permutations]
p1 p2 ... pn p(n-1)
p1 p2 ... p(n-1) pn [permutations]
p1 p2 ... pn p(n-1)
Example
Input: 12 2 1 1 3 3 3 4 16 3 4 5 9 2 1 1 2 1 1 3 5 1 5 91 7 2 1 1 5 100 7 3 5 1 2 1 1 Output: 2 1 2 3 1 3 1 2 3 2 1 3 4 1 2 3 4 2 1 4 1 2 3 1 4 3 2 2 1 3 4 2 1 4 3 2 3 1 4 2 3 4 1 2 4 1 3 2 4 3 1 3 1 2 4 3 1 4 2 2 1 2 1 3 2 1 4 5 1 3 2 4 5 2 1 3 4 5 2 3 1 4 5 3 1 2 4 5 3 2 1 5 1 2 3 4 5 1 2 4 3 2 1 5 1 4 2 3 5 1 4 3 2 5 2 1 3 4 5 2 1 4 3 5 2 3 1 4 5 2 3 4 1 5 2 4 1 3 3 2 1 2 1
hide comments
nadstratosfer:
2020-01-04 04:46:22
Pythonists beware, xrange in Py2 cannot handle arguments larger than 32bit integer. Use range, itertools.slice or submit in Py3. |
|
Madhukar Reddy:
2016-08-03 19:24:05
Is it possible for two different test cases be in same line separated by space? Last edit: 2016-08-03 19:24:24 |
|
akshay_patel:
2016-03-18 18:36:19
Getting runtime error (SIGXFSZ)
|
|
Purav Shah:
2015-06-30 08:46:30
@Piotr Piotrowski: Could u check my attempts, I'm getting WA and I think they are because of the output format
|
|
srikardurgi:
2012-08-26 05:10:16
what is SGARBT error ...
|
|
Devil D:
2012-02-01 09:49:28
@Santiago: value of factorials can go into big ints.. |
|
Santiago Palacio:
2011-07-10 04:48:32
@govardhan: i dont think any biginteger is necesary, as biggest number to handle is 1000 (in t) and 100 in permutations.
|
|
Govardhan Reddy M:
2011-03-31 17:09:54
should i have to use only bigInt to read index ?? how to do in C ?? customized bigIndex ?? please help
|
|
.:: Pratik ::.:
2009-06-30 19:37:09
Huge output, try to use fast output.
|
Added by: | Piotr Piotrowski |
Date: | 2004-11-25 |
Time limit: | 4.505s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS PERL6 VB.NET |