We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2eb4d16 commit ef3ba43Copy full SHA for ef3ba43
1 file changed
weekly/week02/PGS_줄서는방법/gyuhyeok99.cpp
@@ -0,0 +1,30 @@
1
+#include <string>
2
+#include <vector>
3
+using namespace std;
4
+
5
+vector<int> answer;
6
+vector<int> numbers;
7
+vector<long long> dp;
8
9
+vector<int> solution(int n, long long k) {
10
+ dp.resize(n);
11
+ dp[0] = 1;
12
+ for (int i = 1; i < n; i++) {
13
+ dp[i] = dp[i-1] * i;
14
+ }
15
16
+ for (int i = 1; i <= n; i++) {
17
+ numbers.push_back(i);
18
19
20
+ k--;
21
22
+ for (int i = 0; i < n; i++) {
23
+ long long idx = k / dp[n-1-i];
24
+ answer.push_back(numbers[idx]);
25
+ numbers.erase(numbers.begin() + idx);
26
+ k %= dp[n-1-i];
27
28
29
+ return answer;
30
+}
0 commit comments