12560 | 2024-12-23 11:28:22 | 4rt3xp0 | 2015. október | cpp17 | Accepted | 1ms | 500 KiB |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; long long k;
cin >> n >> k; k--;
vector<long long> fact(n,1); vector<int> v(n);
for(int i=1;i<n;i++) fact[i]=fact[i-1]*i;
for(int i=0;i<n;i++) v[i]=i+1;
for(int i=n-1;i>0;i--){
cout << v[k/fact[i]] << ' ';
v.erase(v.begin()+k/fact[i]);
k%=fact[i];
}
cout << v[0];
}
1 2 4 3
Expected output:1 2 4 3
Checker output:ok 4 number(s): "1 2 4 3"
5 3 2 4 1
Expected output:5 3 2 4 1
Checker output:ok 5 number(s): "5 3 2 4 1"
1
Expected output:1
Checker output:ok 1 number(s): "1"
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
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
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
2 1
Expected output:2 1
Checker output:ok 2 number(s): "2 1"
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
4 5 2 1 7 6 3
Expected output:4 5 2 1 7 6 3
Checker output:ok 7 numbers
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
1
Expected output:1
Checker output:ok 1 number(s): "1"
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
3 2 1
Expected output:3 2 1
Checker output:ok 3 number(s): "3 2 1"
1 4 3 6 2 5
Expected output:1 4 3 6 2 5
Checker output:ok 6 numbers
1
Expected output:1
Checker output:ok 1 number(s): "1"
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
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