8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 44153c4 commit 75cbbedCopy full SHA for 75cbbed
0x10/12852.cpp
@@ -0,0 +1,33 @@
1
+// http://boj.kr/da0497aabb26436c9ae613785cb439f7
2
+#include <bits/stdc++.h>
3
+using namespace std;
4
+
5
+int d[1000005];
6
+int pre[1000005];
7
+int n;
8
9
+int main(void) {
10
+ ios::sync_with_stdio(0);
11
+ cin.tie(0);
12
+ cin >> n;
13
+ d[1] = 0;
14
+ for(int i = 2; i <= n; i++){
15
+ d[i] = d[i-1] + 1;
16
+ pre[i] = i-1;
17
+ if(i%2 == 0 && d[i] > d[i/2] + 1){
18
+ d[i] = d[i/2] + 1;
19
+ pre[i] = i/2;
20
+ }
21
+ if(i%3 == 0 && d[i] > d[i/3] + 1){
22
+ d[i] = d[i/3] + 1;
23
+ pre[i] = i/3;
24
25
26
+ cout << d[n] << '\n';
27
+ int cur = n;
28
+ while(true){
29
+ cout << cur << ' ';
30
+ if(cur == 1) break;
31
+ cur = pre[cur];
32
33
+}
0 commit comments