123802024-12-15 12:19:58Firesloth282015. októberpython3Accepted 16ms3320 KiB
from sys import stdin, stdout

def factorial(x):
    res = 1
    for i in range(2, x + 1):
        res *= i
    
    return res

def main():
    n, k = map(int, stdin.readline().split())
    
    numbers = list(range(1, n + 1))
    
    divisor = n - 1
    i = k - 1
    
    while len(numbers) > 1:
        fact = factorial(divisor)
        group = i // fact
        stdout.write(str(numbers[group]) + " ")
        numbers.pop(group)
        
        divisor -= 1
        
        i = i % fact
    
    stdout.write(str(numbers[0]))

main()
1 - Accepted
Memory: 3128KiB
Time: 14ms

Program's output:
1 2 4 3
Expected output:
1 2 4 3 
Checker output:
ok 4 number(s): "1 2 4 3"

2 - Accepted
Memory: 3320KiB
Time: 14ms

Program's output:
5 3 2 4 1
Expected output:
5 3 2 4 1 
Checker output:
ok 5 number(s): "5 3 2 4 1"

3 - Accepted
Memory: 3128KiB
Time: 16ms

Program's output:
1
Expected output:
1 
Checker output:
ok 1 number(s): "1"

4 - Accepted
Memory: 3128KiB
Time: 14ms

Program's output:
1 8 3 5 7 4 2 6 9
Expected output:
1 8 3 5 7 4 2 6 9 
Checker output:
ok 9 numbers

5 - Accepted
Memory: 3128KiB
Time: 16ms

Program's output:
1 8 10 2 3 12 4 6 7 5 9 11
Expected output:
1 8 10 2 3 12 4 6 7 5 9 11 
Checker output:
ok 12 numbers

6 - Accepted
Memory: 3128KiB
Time: 16ms

Program's output:
7 3 1 5 8 9 10 11 2 6 4
Expected output:
7 3 1 5 8 9 10 11 2 6 4 
Checker output:
ok 11 numbers

7 - Accepted
Memory: 3104KiB
Time: 16ms

Program's output:
2 1
Expected output:
2 1 
Checker output:
ok 2 number(s): "2 1"

8 - Accepted
Memory: 3320KiB
Time: 14ms

Program's output:
6 3 8 2 5 4 10 11 7 1 9
Expected output:
6 3 8 2 5 4 10 11 7 1 9 
Checker output:
ok 11 numbers

9 - Accepted
Memory: 2988KiB
Time: 16ms

Program's output:
4 5 2 1 7 6 3
Expected output:
4 5 2 1 7 6 3 
Checker output:
ok 7 numbers

10 - Accepted
Memory: 3104KiB
Time: 14ms

Program's output:
10 2 4 1 5 8 3 9 7 6
Expected output:
10 2 4 1 5 8 3 9 7 6 
Checker output:
ok 10 numbers

11 - Accepted
Memory: 3128KiB
Time: 14ms

Program's output:
1
Expected output:
1 
Checker output:
ok 1 number(s): "1"

12 - Accepted
Memory: 3128KiB
Time: 14ms

Program's output:
2 5 14 12 8 4 11 6 13 9 1 10 3 7
Expected output:
2 5 14 12 8 4 11 6 13 9 1 10 3 7 
Checker output:
ok 14 numbers

13 - Accepted
Memory: 2964KiB
Time: 16ms

Program's output:
3 2 1
Expected output:
3 2 1 
Checker output:
ok 3 number(s): "3 2 1"

14 - Accepted
Memory: 3128KiB
Time: 14ms

Program's output:
1 4 3 6 2 5
Expected output:
1 4 3 6 2 5 
Checker output:
ok 6 numbers

15 - Accepted
Memory: 3128KiB
Time: 16ms

Program's output:
1
Expected output:
1 
Checker output:
ok 1 number(s): "1"

16 - Accepted
Memory: 3128KiB
Time: 14ms

Program's output:
14 13 12 11 10 9 8 7 6 5 4 3 2 1
Expected output:
14 13 12 11 10 9 8 7 6 5 4 3 2 1 
Checker output:
ok 14 numbers

17 - Accepted
Memory: 3128KiB
Time: 16ms

Program's output:
7 14 13 12 11 10 9 8 6 5 4 3 2 1
Expected output:
7 14 13 12 11 10 9 8 6 5 4 3 2 1 
Checker output:
ok 14 numbers