Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
# coding: utf-8 # In[30]: n = int(raw_input()) i = 3 slimes = [2] if n == 1: print 1 else: while i<=n: slimes.append(1) if len(slimes) > 1: while len(slimes) > 1 and slimes[-1] == slimes[-2]: last = slimes.pop() second_last = slimes.pop() slimes.append(last+1) i += 1 print ' '.join(map(str,slimes)) # In[ ]:
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.ArrayList; import java.util.Scanner; public class TaskA { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int l = 0; ArrayList<Integer> result = new ArrayList<>(); while (n > 0) { l++; int k = n % 2; n = n / 2; if (k != 0) { result.add(l); } } for (int i = result.size() - 1; i > -1; i--) { System.out.print(result.get(i) + " "); } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) a = [] for i in range(0,n): a.append(1) while len(a)>1 and a[-1] == a[-2]: a.pop() a.append(a.pop()+1) print(' '.join(str(j) for j in a))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len; bool flag; int st[100005], tp; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { tp++; st[tp] = 1; while (tp > 0 && st[tp] == st[tp - 1]) { st[tp - 1]++; tp--; } } for (i = 1; i <= tp; i++) { printf("%d ", st[i]); } printf("\n"); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int res[200] = {0}; int i = 0; int a = 1; while (n > 0) { if (n % 2 == 1) { res[i++] = a; } a++; n /= 2; } int t = 0; for (--i; i >= 0; i--) { if (t != 0) cout << " "; else { t++; } cout << res[i]; } cout << endl; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#!/usr/bin/env python3 try: while True: n = int(input()) for i in range(31, -1, -1): if n & 1 << i: print(i + 1, end=' ') print() except EOFError: pass
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int n; cin >> n; int si = 0; for (int i = 0; i < n; i++) { v.push_back(1); si++; while (si > 1 && v[si - 1] == v[si - 2]) { int r = v[si - 1] + 1; v.pop_back(); v.pop_back(); v.push_back(r); si--; } } for (auto x : v) printf("%d ", x); printf("\n"); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#----Kuzlyaev-Nikita-Codeforces----- #------------03.04.2020------------- alph="abcdefghijklmnopqrstuvwxyz" #----------------------------------- n=int(input()) s="" while n!=0: s+=str(n%2) n//=2 for i in range(len(s)-1,-1,-1): if s[i]=='1':print(i+1,end=" ")
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Stack; public class Main { static BufferedReader in; static PrintWriter out; public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int N = ri(); Stack<Integer> s = new Stack<Integer>(); for (int i=0;i<N;i++) { s.add(1); while (s.size()>1) { int x1 = s.pop(); int x2 = s.pop(); if (x1==x2) { s.add(x1+1); } else { s.add(x2); s.add(x1); break; } } } int size = s.size(); int[]res = new int[size]; for (int i=0;i<size;i++) res[size-1-i] = s.pop(); for (int i=0;i<size;i++) out.print(res[i]+" "); out.println(); in.close(); out.close(); } public static int ri() throws IOException { return Integer.parseInt(in.readLine()); } public static long rl() throws IOException { return Long.parseLong(in.readLine()); } public static String rs() throws IOException { return in.readLine(); } public static String[] rst() throws IOException { return in.readLine().split(" "); } public static int[] rit() throws IOException { String[] tok = in.readLine().split(" "); int[] res = new int[tok.length]; for (int i = 0; i < tok.length; i++) { res[i] = Integer.parseInt(tok[i]); } return res; } public static long[] rlt() throws IOException { String[] tok = in.readLine().split(" "); long[] res = new long[tok.length]; for (int i = 0; i < tok.length; i++) { res[i] = Long.parseLong(tok[i]); } return res; } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) import math res = [] while n>0: i = math.floor(math.log(n,2)) n -= 2**i res.append(i+1) print(*res)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); vector<int> V; for (int i = 0; i < N; i++) { V.push_back(1); while (V.size() > 1 && V.back() == V[(int)V.size() - 2]) { V.pop_back(); V[(int)V.size() - 1]++; } } for (int i = 0; i < V.size(); i++) printf("%d ", V[i]); puts(""); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int n; cin >> n; for (int i = 20; i >= 0; i--) if (n >> i & 1) cout << i + 1 << ' '; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int inf_int = 2e9; long long inf_ll = 1e18; const double pi = 3.1415926535898; template <typename T> void prin(vector<T>& a) { for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i < a.size() - 1) cout << " "; else cout << "\n"; } } template <typename T> void prin(set<T>& a) { for (auto it = a.begin(); it != a.end(); it++) { cout << *it << " "; } } template <typename T> void prin_new_line(vector<T>& a) { for (int i = 0; i < a.size(); i++) { cout << a[i] << "\n"; } } template <typename T, typename T1> void prin_new_line(vector<pair<T, T1> >& a) { for (int i = 0; i < a.size(); i++) { cout << a[i].first << " " << a[i].second << "\n"; } } int sum_vec(vector<int>& a) { int s = 0; for (int i = 0; i < a.size(); i++) { s += a[i]; } return s; } template <typename T> T max(vector<T>& a) { T ans = a[0]; for (int i = 1; i < a.size(); i++) { ans = max(ans, a[i]); } return ans; } template <typename T> T min(vector<T>& a) { T ans = a[0]; for (int i = 1; i < a.size(); i++) { ans = min(ans, a[i]); } return ans; } template <typename T> T min(T a, T b, T c) { return min(a, min(b, c)); } template <typename T> T max(T a, T b, T c) { return max(a, max(b, c)); } long long dis(long long x, long long y, long long x1, long long y1) { return (x - x1) * (x - x1) + (y - y1) * (y - y1); } const int maxn = 5e5 + 100; bool debug = 1; void solve() { int n; cin >> n; stack<int> a; a.push(1); for (int i = 1; i < n; i++) { a.push(1); while (!a.empty()) { int x = a.top(); a.pop(); if (a.empty()) { a.push(x); break; } if (x == a.top()) { int y = a.top(); a.pop(); a.push(x + 1); } else { a.push(x); break; } } } vector<int> ans; while (!a.empty()) { ans.push_back(a.top()); a.pop(); } reverse(ans.begin(), ans.end()); prin(ans); } int main() { if (!debug) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int t = 1; while (t--) solve(); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) x = bin(n)[2:] answer = [] counter = 1 for i in x[::-1]: if i != "0": answer.append(str(int(i) * counter)) counter += 1 x = '' for i in range(len(answer) - 1, -1, -1): x += answer[i] + " " print(x)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) scanf("%d", A + i); } char s[(1 << 19)], r[(1 << 19)]; int a, b, L, c, N, B, S, A[(1 << 19)]; bool cp(int a, int b) { return a > b; } int main(void) { scanf("%d", &N); for (int i(0); i < 18; i++) if ((N >> i) & 1) A[L++] = i + 1; sort(A, A + L, cp); for (int i(0); i < L; i++) printf("%d%c", A[i], i + 1 == L ? 10 : 32); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int n, i, x = 1, a; cin >> n; for (i = 1; i <= n; i++) { v.push_back(1); while (v.size() > 1 && v.back() == v[v.size() - 2]) { v.pop_back(); v.back()++; } } for (i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) arr = [1] for i in range(n-1): arr.append(1) while len(arr)>=2 and arr[-1]==arr[-2]: arr[-2] += 1 del arr[-1] print(*arr)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; public class WunderFundRound2016_1 { public static void main(String[] args) { int[] powers = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536}; Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // boolean found = false; int i=0; while (i<17){ if (n==powers[i]){ // found = true; System.out.println(log(n+1,2)); return; } i++; } i = 0; int r = log(n, 2); int result = n - (int)Math.pow((double)2,(double)(r-1)); System.out.print(r+" "); while (result != 1){ n = result; while (i<17){ if (n==powers[i]){ // found = true; System.out.println(log(n+1,2)); return; } i++; } i = 0; r = log(n,2 ); result = n - (int)Math.pow((double)2,(double)(r-1)); System.out.print(r+" "); } System.out.print(1); } // static void printResult(int n , int r){ // int result = n - (int)Math.pow((double)2,(double)(r-1)); // // while (result != 1){ // System.out.println(r); // r = log(result, 2); // result = result - (int)Math.pow((double)2,(double)(r-1)); // printResult(result, log(result, 2)); // } // // } static int log(int x, int base) { return (int)Math.ceil((Math.log(x) / Math.log(base))); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
def solve(): n = bin(int(input()))[-1:1:-1] b = [i + 1 for i in range(len(n)) if n[i] == '1'] print(' '.join(map(str, b[::-1]))) if __name__ == "__main__": solve()
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; int z = 1; while (n != 0) { if (n % 2 == 1) { v.push_back(z); } n /= 2; z++; } reverse(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> int main() { unsigned long long int n, i, j, ans[100001], count; scanf("%lld", &n); count = 0; j = 100000; while (n != 0) { if ((n & 1) == 1) { ans[j] = count + 1; j--; } count++; n = n >> 1; } for (i = j + 1; i <= 100000; i++) { printf("%lld ", ans[i]); } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; const int N = 300020; const int mod = 1000000007; long long int n; stack<long long int> st; int main() { cin >> n; for (long long int i = 1; i <= n; i++) { if (st.empty()) st.push(1); else { if (st.empty()) { st.push(1); continue; } if (st.top() == 1) { long long int val = 1; while (st.top() == val) { st.pop(); val++; if (st.empty()) break; } st.push(val); } else { st.push(1); } } } vector<long long int> ans; while (!st.empty()) { ans.push_back(st.top()); st.pop(); } reverse(ans.begin(), ans.end()); for (long long int i = 0; i < ans.size(); i++) cout << ans[i] << " "; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; void a(int n) { int b = 0; if (n == 0) return; else if (n == 1) { cout << "1 "; return; } else { b = (int)(floor(log2(n))); cout << b + 1 << " "; a(n - (int)(pow(2, b))); } } int main() { int n; cin >> n; a(n); }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; /** * 1/29/16 **/ public class A { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] a = new int[100001]; int temp = n; for(int i =0;i < n; i++) { a[i] = temp%2; temp = temp/2; } for(int i =n; i >= 0; i--) { if(a[i] == 1) { System.out.print(i+1 + " "); } } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Stack; import java.util.StringTokenizer; public class slimes { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int tmp=0; int[] res = new int[n]; Stack<Integer> stk = new Stack<>(); if(n==1) System.out.println(1); else{ stk.push(1); for (int i = 0; i < n-1; i++) { stk.push(1); while(i<n){ tmp = stk.pop(); if(stk.isEmpty()){ stk.push(tmp); break; } if(stk.peek()==tmp){ int tmp2 = stk.pop(); stk.push(tmp+1); } else { stk.push(tmp); break; } } } } Stack<Integer> result = new Stack<>(); while(!stk.isEmpty()){ result.push(stk.pop()); } while(!result.isEmpty()) { System.out.print(result.pop()+" "); } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#! /usr/bin/env python from math import acos,asin,atan,sqrt,pi,sin,cos,tan,ceil,floor,log import re from operator import itemgetter as ig #map(int,raw_input().split()) n=input() lis=[] s=0 for i in range(n): lis.append(1) s+=1 while s>1 and lis[-1]==lis[-2]: lis[-2]+=1 lis.pop() s-=1 for i in lis: print i, exit(0)
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int n; int base = 1; int state[100000] = {0}, total = 0; int main() { cin >> n; int now = 0; while (now < n) { now++; total++; state[total] = 1; while (state[total] == state[total - 1]) { total--; state[total]++; } } for (int i = 1; i <= total; i++) { cout << state[i] << " "; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws NumberFormatException,IOException{ /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(b.readLine().trim()); int k = (int)(Math.floor(Math.log(n)/Math.log(2))); // // System.out.println(k); // if( Math.pow(2,k) == n){ // System.out.println((k+1)); // } // else{ // int limit = n - (int)(Math.pow(2,k)); // int starter = k+1; // String ans = starter + " "; // for(int i = k ; i > 0; i--){ // if(limit/i > 0){ // ans = ans + "" + i + " "; // limit = limit - i; // } // } // System.out.println(ans); // } for(int i = k ; i >= 0 ; i--){ if(n >= (int)(Math.pow(2,i))){ System.out.print((i+1) + " "); n = n - (int)(Math.pow(2,i)); } } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import sys n = int(input(), 10) b = bin(n) l = len(b) for i in b: if i == '1': print(l, end="") if l != 0: print(' ', end="") l = l-1
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int n, i, j, a[100005], b[100005], answ, l; vector<int> g; int main() { cin >> n; a[1] = 1; b[1] = 1; if (n == 1) { cout << 1 << endl; return 0; } for (i = 2;; i++) { a[i] = b[i - 1] + 1; b[i] = b[i - 1] + a[i]; if (b[i] > n) break; } int k = i; l = k; if (b[k - 1] == n) k--; while (n != 0) { g.push_back(k); n -= b[k - 1] + 1; int ina = 1, inb = l; while (ina <= inb) { int m = (ina + inb) / 2; if (b[m] >= n) { k = m; inb = m - 1; } else ina = m + 1; } } for (i = 0; i < g.size(); i++) printf("%d ", g[i]); printf("\n"); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(raw_input()) row = [ 1 ] for i in range(1, n): row.append(1) while len(row) >= 2 and row[-1] == row[-2]: x = row.pop() row[-1] = x + 1 print(' '.join(map(str, row)))
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; void solve(int n, int x) { if (!n) return; solve(n / 2, x + 1); if (n & 1) cout << x + 1 << ' '; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; solve(n, 0); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; for (int i = 16; i >= 0; i--) { if ((1 << i) <= n) { cout << i + 1 << " "; n -= (1 << i); } } }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int n; vector<int> arr; int main() { cin >> n; int ind = 1; while (n) { if (n & 1) { arr.push_back(ind); } n >>= 1; ind++; } for (int i = arr.size() - 1; i >= 0; i--) { cout << arr[i] << " "; } cout << "\n"; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; void solution() { int n; cin >> n; vector<int> ans; ans.clear(); int x = 0; while (n) { x++; if (n & 1) ans.push_back(x); n >>= 1; } reverse((ans).begin(), (ans).end()); for (int i = (0); i < (ans.size()); i++) { if (i) cout << " "; cout << ans[i]; } cout << '\n'; } int main() { solution(); }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); stack<long long> S; int n; cin >> n; vector<long long> V; V.push_back(1); n--; while (n--) { V.push_back(1); int i = V.size() - 1; while (V.size() > 1 && V[i] == V[i - 1]) { long long Val = V[i] + 1; V.pop_back(); V.pop_back(); V.push_back(Val); i = V.size() - 1; } } for (int i = 0; i < V.size(); i++) { cout << V[i] << " "; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) curr = 1 result = [] while n > 0: if n % 2 == 1: result.append(curr) n //= 2 curr += 1 print(' '.join(map(str, result[::-1])))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=input() ans=[] if n==1: print 1 elif n==2: print 2 else: i=1 ans.append(1) while n-1: ans.append(1) #print ans if ans[i]==ans[i-1]: while i>=1 and ans[i]==ans[i-1]: ans[i-1]+=1 ans.remove(ans[i]) i-=1 #print i i+=1 n-=1 for i in ans: print i,# your code goes here
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#a = list(map(int, raw_input().split())) #print a n = int(raw_input()) res = [] for i in range(n): res.append(1) m = -1 for i in range(n): m += 1 res[m] = 1 while m > 0 and res[m] == res[m-1]: m -= 1 res[m] = res[m] + 1 for i in range(m+1): print res[i],
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.InputMismatchException; import java.io.IOException; import java.util.Collections; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author T.C.D */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInputReader in = new FastInputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, FastInputReader in, PrintWriter out) { int n = in.nextInt(); List<Integer> ans = new ArrayList<>(); int t = 1; while (n > 0) { if (n % 2 == 1) { ans.add(t); } t++; n >>= 1; } Collections.sort(ans); for (int i = ans.size() - 1; i >= 0; --i) { out.print(ans.get(i) + " "); } } } static class FastInputReader { static InputStream is; static private byte[] buffer; static private int lenbuf; static private int ptrbuf; public FastInputReader(InputStream stream) { is = stream; buffer = new byte[1024]; lenbuf = 0; ptrbuf = 0; } private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return buffer[ptrbuf++]; } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=int(raw_input()) a=[] for i in range(n): a.append(1) while len(a)>1 and a[-1]==a[-2]: a.pop() a[-1]+=1 for i in a: print i,
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
a = int(input()) b = [] for i in range(a) : b.append(1) while True: if len(b) > 1 and b[-1] == b[-2]: b[-2] += 1 del b[-1] else: break print(*b)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.*; import java.util.Stack; import java.util.StringTokenizer; /** * Created by peacefrog on 1/29/16. * Time : 11:06 PM */ public class Task_A { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; PrintWriter out; long timeBegin, timeEnd; public void runIO() throws IOException { timeBegin = System.currentTimeMillis(); InputStream inputStream; OutputStream outputStream; if (ONLINE_JUDGE) { inputStream = System.in; Reader.init(inputStream); outputStream = System.out; out = new PrintWriter(outputStream); } else { inputStream = new FileInputStream("/home/peacefrog/Dropbox/IdeaProjects/Problem Solving/input"); Reader.init(inputStream); out = new PrintWriter(System.out); } solve(); out.flush(); out.close(); timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } /* * Start Solution Here */ private void solve() throws IOException { int n = Reader.nextInt(); //This Variable default in Code Template Stack<Long> s = new Stack<>(); s.add(1L); for (long i = 1; i <= n-1; i++) { if(s.peek() == 1){ long top = s.pop()+1; while (!s.isEmpty() ){ if(s.peek()!= top) break; top ++; s.pop(); } s.add(top); } else s.add(1L); } for (int i = 0; i < s.size(); i++) { out.print(s.get(i) + " "); } } public static void main(String[] args) throws IOException { new Task_A().runIO(); } static class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** * call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } /** * get next word */ static String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } static String nextLine() { try { return reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return ""; } static char nextChar() throws IOException { return (char) reader.read(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } static long[] nextLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } static int[] nextIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
x=int(input()) i=0 a=[] while x : i=i+1 if x%2!=0: b=(x%2)*i a.append(b) x=x//2 else: x=x//2 a.reverse() for t in range (len(a)): print('{}'.format(a[t]))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr; for (int i = 0; i < n; i++) { arr.push_back(1); for (int j = arr.size() - 1; j >= 0; j--) { if (arr.size() != 1 && arr[j] == arr[j - 1]) { arr.erase(arr.begin() + j); arr[j - 1]++; j = arr.size(); } else break; } } for (int i = 0; i < arr.size(); i++) cout << arr[i] << " "; cout << endl; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) out = [] cur = 1 while n > 0: if n % 2 == 1: out.append(cur) cur += 1 n //= 2 for v in reversed(out): print(v, end=' ') print()
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; vector<long long> v; while (n--) { v.push_back(1); while (v.size() > 1 && v[v.size() - 1] == v[v.size() - 2]) { v[v.size() - 2]++; v.pop_back(); } } for (int i = 0; i < v.size(); ++i) cout << v[i] << " "; cout << endl; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.ArrayList; import java.util.Scanner; //import TetraHedron.Scanner; public class slimeclimbing { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input =new Scanner(System.in); int n = input.nextInt(); int count=0; ArrayList<Integer> list =new ArrayList<Integer>(); while(n!=0){ int p= log2(n); count++; n-=Math.pow(2,p); // System.out.println(p); list.add(p+1); } for(int z: list){ System.out.print(z+" "); } } public static int log2( int bits ) { if( bits == 0 ) return 0; // or throw exception return 31 - Integer.numberOfLeadingZeros( bits ); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main(void) { int N; scanf("%i", &N); int i; int dva[30]; dva[0] = 1; for (i = 1; i < 20; i++) { dva[i] = 2 * dva[i - 1]; } int stav = 0; for (i = 19; i >= 0; i--) { if ((N & dva[i]) != 0) { if (stav == 0) printf("%i", i + 1); else printf(" %i", i + 1); stav = 1; } } printf("\n"); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { for (int i = 31; i > -1; --i) if (n & (1 << i)) cout << i + 1 << " "; cout << endl; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; void ans(int n) { int p, m; if (n == 0) { return; } else if (n == 1) { printf("1"); return; } else { p = 2; m = 1; while (p <= n) { p *= 2; m++; } p /= 2; printf("%d ", m); ans(n - p); return; } } int main() { int n; cin >> n; ans(n); cout << endl; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=int(input()) s=bin(n) s=s[2:] for i in range(len(s)): if s[i]=='1': print(len(s)-i,end=" ")
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; public class CF618A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); ArrayDeque<Integer> stack = new ArrayDeque<Integer>(); for(int i = 0; i < n; i ++) { stack.push(1); while(!stack.isEmpty()) { int at = stack.pop(); if(stack.isEmpty() || stack.peek() != at) { stack.push(at); break; } stack.pop(); stack.push(at + 1); } } while(!stack.isEmpty()) System.out.print(stack.pollLast() + " "); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
/** * Created by Omar on 1/29/2016. */ import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); //String[] parts=br.readLine().split(" "); //int[]a= new int[n]; //for(int i=0;i<n;i++){a[i]=Integer.parseInt(parts[i]);} ArrayDeque<Integer>a= new ArrayDeque<Integer>(); int temp,temp2; for(int i=1;i<=n;i++){ a.addLast(1); // System.out.println(a.toString()); while(a.size()>=2){ temp=a.removeLast(); temp2=a.removeLast(); if(temp==temp2){ a.add(temp+1); } else{ a.addLast(temp2); a.addLast(temp); break; } } } for(int i:a){ System.out.print(i+" "); } br.close(); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) b = bin(n)[2:] l = [] for i, c in enumerate(b): if c == '1': l.append(len(b) - i) print(' '.join(map(str, l)))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) ls = [] for i in range(n): ls.append(1) try: while ls[-2]==ls[-1]: ls[-2]+=1; ls = ls[:-1] except: pass for j in ls: print(j, end=' ') print()
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; int nums[1000001] = {0}; int i = 0; while (n--) { ++i; ++nums[i]; for (int j = i; j >= 1; --j) { if (nums[j] == nums[j - 1]) { nums[j] = 0; i = j - 1; ++nums[j - 1]; } } } for (int j = 1; j < i; ++j) cout << nums[j] << ' '; cout << nums[i] << endl; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
# -*- coding: utf-8 -*- # Input num_slimes = int(raw_input()) row = [] for i in xrange(num_slimes): row.append(1) for ii in xrange(len(row)-1): if row[-2] == row[-1]: row[-2] += 1 row.pop() # Ans ans = '' for slime in row: ans = '{0} {1}'.format(ans, slime) print ans
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> const long double pi = acos(-1.0); using namespace std; vector<int> a; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { a.push_back(1); while (1) { if (a.size() == 1) break; if (a[a.size() - 1] == a[a.size() - 2]) { a.pop_back(); a[a.size() - 1]++; } else break; } } for (int i = 0; i < a.size(); i++) cout << a[i] << " "; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int n, a[100001], i = 0; int main() { cin >> n; while (n != 0) { a[i] = 1; while (1) { if (a[i] == a[i - 1]) { a[i] = 0; i--; a[i] += 1; } else break; } i++; n--; } for (int j = 0; j <= 100000; j++) { if (a[j] == 0) break; cout << a[j] << " "; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; a[0] = -1; int j = 0; for (int i = 0; i < n; i++) { j++; a[j] = 1; while ((a[j] == a[j - 1])) { a[j - 1]++; j--; } } for (int i = 1; i < j + 1; i++) cout << a[i] << ' '; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int getBit(int num, int pos) { return (num >> pos) & 1; } int setBit(int num, int pos, int val) { if (val == 0) { return num & (~(1 << pos)); } else { return num | (1 << pos); } } int main() { int arr[100000]; int st = 1; arr[0] = 1; int n, i; cin >> n; for ((i) = 0; (i) < (int)(n - 1); (i)++) { arr[st] = 1; while (st > 0 && arr[st] == arr[st - 1]) { arr[st - 1] += 1; st--; } st++; } for ((i) = 0; (i) < (int)(st); (i)++) { cout << arr[i] << " "; } }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
from collections import deque Size = int(input()) List = deque() for i in range(Size): List.append(1) while True: if len(List) > 1 and List[-1] == List[-2]: List.pop() List[-1] += 1 else: break print(*List)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import sys n = int(sys.stdin.readline()) if n == 1: print 1 sys.exit() l = [1] ans = 1 for i in xrange(n-1): l = [1] + l while len(l) > 1: if l[0] == l[1]: del l[0] l[0] += 1 else: break for i in l[::-1]: print i,
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) arr = [1] for i in range(1, n): arr.append(1) while (len(arr) > 1 and arr[-1] == arr[-2]): arr.pop() arr[-1]+=1 print(*arr)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; struct node { int a, b; bool operator<(const node &p) const { if (b == p.b) return a, p.a; else return b < p.b; } }; int main() { int pp, b, i, j, k, m, n, p, q; string s; while (cin >> n) { deque<int> m1; for (i = 0; i < n; i++) { if (!m1.empty()) q = m1.back(); else q = 0; p = 1; while (p == q && !m1.empty()) { p++; m1.pop_back(); if (!m1.empty()) q = m1.back(); else q = 0; } m1.push_back(p); } p = m1.size(); for (i = 0; i < p; i++) { cout << m1.front() << " "; m1.pop_front(); } cout << endl; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) l = [] for i in range(n): l.append(1) while len(l) > 1 and l[-1] == l[-2]: x = l.pop() l[-1] += 1 for i in l: print(i, end = ' ')
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 110; int go(int p) { return pow(2, p); } int main() { int n; cin >> n; vector<int> ans; int p = 1; while (n) { if (n % 2) ans.push_back(p); n /= 2; p++; } for (int i = ans.size() - 1; i >= 0; i--) { cout << ans[i] << " "; } cout << endl; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) s=[] for i in range(20,-1,-1): if n&(1<<i) >0: s+=[str(i+1)] print(" ".join(s))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) slimes = list() for _ in range(n): slimes.append(1) while len(slimes) > 1 and slimes[-1] == slimes[-2]: slimes.pop() slimes[-1] += 1 print(" ".join(map(str, slimes)))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=int(input());v=[] t=0;s="" while (n!=0): s+=str(n%2) n//=2 for i in range(len(s)): if (s[i]=="1"): v.append(i+1) for i in range(len(v)-1,-1,-1): print(v[i],end=" ")
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import math a=[0]*1000000 n=input() i=1 while i <1000000: a[i]=int(math.log(i,2))+1 i*=2 b=bin(n) for i in range(2,len(b)): if b[i]=='1': print a[2**(len(b)-i-1)], #print a[i],
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
def Inspect(): global Slice k = len(Slice) for i in range(k): if Slice[i] != -1: Slice.append(Slice[i]) Slice = Slice[k:] for i in range(len(Slice)-1): if Slice[i] == Slice[i+1]: return False return True n = int(input()) Slice = [1] * n while not(Inspect()): for i in range(len(Slice)-1): if Slice[i] == Slice[i+1]: Slice[i+1] = Slice[i] + 1 Slice[i] = -1 Inspect() print(*Slice)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; public class problemA { public static void main(String[] args){ Scanner in = new Scanner(System.in); //int runs = in.nextInt(); // for(int run = 1;run<=runs;run++){ // // } int s = in.nextInt(); String ret = ""; int num = 1; while (s>0){ if(s%2==1){ ret = num + " " +ret; } num++; s/=2; } System.out.println(ret.trim()); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) res = [] while n > 0: res.append(n%2) n//=2 ans=[] for i in range(len(res)): if(res[i])>0: ans.append(i+1) ans.reverse() print(' '.join(map(str, ans)))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) v = [] for i in range(0, n): v.append(1) while True: if len(v) > 1 and v[-1] == v[-2]: v.pop() v[-1] += 1 else: break print(*v) # ♥ # امشب مهمون دارم
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) for i in reversed(range(21)): if n & (1 << i) != 0: print(i + 1, end=' ')
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=int(input()) for i in range(16,-1,-1): if(n>=2**i): n-=2**i print(i+1,end=' ')
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> int main() { long long int n; double temp, temp2; scanf("%lld", &n); while (n != 0) { temp = log((double)n) / log((double)2); temp2 = (long long int)floor((double)temp); printf("%lld ", (long long int)temp2 + 1); n = n - pow(2, temp2); } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
def process_stack(stk): while len(stk) > 1: last_element = stk.pop() second_last = stk.pop() if last_element != second_last: stk.append(second_last) stk.append(last_element) break else: last_element = last_element + 1 stk.append(last_element) return stk def do_procedure(slimes): stk = [] stk.append(slimes[0]) for i in range(1, len(slimes)): stk.append(slimes[i]) if len(stk) > 1: stk = process_stack(stk) return stk no_of_slimes = int(raw_input()) slimes = [1] * no_of_slimes stk = do_procedure(slimes) print " ".join(map(str, stk))
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.*; import java.util.*; public final class SlimeCombining { public static void main(String args[])throws java.lang.Exception{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); OutputStream out=new BufferedOutputStream(System.out); int x=Integer.parseInt(br.readLine()); int[] a=new int[x]; Arrays.fill(a, 1); int i=1; int j=1; for( i=1,j=1;j<x;j++){ if(a[i-1]!=a[i]){ i++; }else{ while(a[i-1]==a[i]){ a[i-1]=a[i-1]+1; a[i]=1; if(i>=2){ if(a[i-2]==a[i-1]) i--; } } } } for(int k=0;k<i;k++) out.write((a[k]+" ").getBytes()); out.flush(); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; vector<int> bit(int x) { stack<int> st; while (x > 0) { st.push(x % 2); x /= 2; } vector<int> res; while (!st.empty()) { res.push_back(st.top()); st.pop(); } reverse(res.begin(), res.end()); return res; } int main() { int n; cin >> n; vector<int> ans = bit(n); for (int i = ans.size() - 1; i >= 0; i--) { if (ans[i]) cout << i + 1 << " "; } cout << "\n"; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; public class SlimeCombiningA{ public static void main (String[] args){ Scanner key = new Scanner(System.in); int slices = key.nextInt(); int[] arr = new int[slices]; int k=0; while(slices!=0){ arr[k]+=1; if(k==0){ k++; slices--; } else{ for(int i=k;i>0;i--){ if(arr[k]==arr[k-1]){ arr[k-1]++; arr[k]=0; k--; } } slices--; k++; } } for(int j=0;j<arr.length;j++){ if(arr[j]!=0) System.out.print(arr[j]+" "); } key.close(); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; import java.io.*; public class Codeforces { static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static void newST() throws IOException {st = new StringTokenizer(in.readLine());} static int stInt() {return Integer.parseInt(st.nextToken());} static String stStr() {return st.nextToken();} static int[] getInts(int n) throws IOException {newST(); int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = stInt(); return arr;} static int readInt() throws IOException {return Integer.parseInt(in.readLine());} static void println(Object o) {System.out.println(o);} static void print(Object o) {System.out.print(o);} public static void main(String[] args) throws Exception { int n = readInt(); String s = Integer.toBinaryString(n); int len = s.length(); boolean t = false; for (int i = 0; i < len; i++) { if (s.charAt(i) == '1') { if (t) { print(" " + (len-i)); } else { print((len-i)); t = true; } } } println(""); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import math n = int(raw_input()) while n: x = int(math.floor(math.log(n, 2)) + 1) print x, n -= 2**(x - 1)
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=int(input()) bit=[] while n>0: bit.append(n%2) n//=2 v=[] for i in range(len(bit)): if bit[i]>0: v.append(i+1) v.reverse() print(' '.join(map(str,v)))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int x, a; cin >> x; a = x; vector<int> v; do { v.push_back(x % 2); x = x / 2; } while (x > 0); for (int i = v.size() - 1; i >= 0; i--) { if (v[i] == 1) { if (a % 2 == 0) { cout << i + 1 << " "; } else { cout << i + 1 << " "; } } } }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> a; for (int i = 0; i < n; i++) { a.push_back(1); while (a.size() > 1 && a.back() == a[a.size() - 2]) { a[a.size() - 2]++; a.pop_back(); } } for (auto x : a) { cout << x << " "; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int a[100 * 1000 + 10]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; int cnt = 0; while (n >= 1) { int i = 1; int j = 0; while (i * 2 <= n) { j++; i *= 2; } a[cnt] = j + 1; cnt++; n -= i; } for (int i = 0; i < cnt; i++) cout << a[i] << " "; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) print(" ".join(str(i+1) for i in range(20,-1,-1) if (n&(1<<i)) > 0))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#!/usr/bin/env python3 n = int(input()) k = [] for i in range(0, n): k.append(1) while len(k) > 1 and k[-1] == k[-2]: k[-2] += 1 del k[-1] first = True for i in k: if first: first = False else: print(' ', end='') print(i, end='')
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); boolean first = true; for (int i = 19; i >= 0; --i) { if ((n & (1 << i)) != 0) { if (first) first = false; else out.print(" "); out.print(i + 1); } } out.println(); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; public class sli { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int i=sc.nextInt(); int a[]=new int [i]; int k=0; for(int j=0;j<i;j++) { a[k]=1; for(int p=k-1;p>-1;p--) { if(a[p]==a[p+1]) { a[p]++; a[p+1]=0; } else break; } int m=0; while(a[m]!=0) { m++; if(m==i) break; } k=m; } for(int y=0;y<k;y++) { System.out.print(a[y]+" "); } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author Nikhil Pathania */ public class Slime { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int test=Integer.parseInt(br.readLine()); int arr[]=new int[100000]; int head=0; for(int i=0;i<test;i++) { arr[head]++; //System.out.println("Value at "+head+" = "+arr[head]); while(head>0&&arr[head]==arr[head-1]) { arr[head-1]++; arr[head]=0; head--; // System.out.println("Changed Value at "+head+" = "+arr[head]+" i: "+i); } head++; } for(int i=0;i<100000;i++) { if(arr[i]==0) break; else System.out.print(arr[i]+" "); } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; import java.util.Stack; public class ACM{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Stack<Integer>a = new Stack<>(); a.push(1); n=n-1; while (n-->0) { a.push(1); int temp = a.pop(); while (!a.isEmpty() && a.peek()==temp ) { a.pop(); temp=temp+1; } a.push(temp); } Stack<Integer> b = new Stack<>(); while (!a.isEmpty()) { b.push(a.pop()); } while(!b.isEmpty()) { System.out.print(b.pop()+" "); } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; cin >> n; int num = n; vector<int> v; int cnt = 0; x: for (int i = 0;; i++) { int z = pow(2, i); if (z > num) { break; } if (z <= num) { cnt++; } } num = num - pow(2, cnt - 1); v.push_back(cnt); cnt = 0; if (num > 2) { goto x; } if (num == 2) { v.push_back(2); } else if (num == 1) { v.push_back(1); } for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=input() s = bin(n)[2:] ans = "" for i in range(len(s)): if s[i] == '1': ans += str(len(s)-i) + " " print ans.strip()
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v; v.push_back(1); --n; while (n) { if (v[v.size() - 1] == 1) { v[v.size() - 1] = 2; --n; } else { v.push_back(1); --n; } bool h = 1; while (h && v.size() >= 2) { if (v[v.size() - 1] == v[v.size() - 2]) { v[v.size() - 2] += 1; v.pop_back(); } else h = 0; } } for (int i = 0; i < v.size(); i++) { cout << v[i]; if (i + 1 != v.size()) cout << " "; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; import java.util.concurrent.ArrayBlockingQueue; import java.io.*; public class A { public static void main(String[] args) { new A().solve(); } FasterScanner in=new FasterScanner(); PrintWriter out=new PrintWriter(System.out); public void solve() { // int tt=in.nextInt(); // loop: // for(int ii=0;ii<tt;ii++) { int n=in.nextInt(); String str=Integer.toBinaryString(n); String ans=""; int c=1; //System.out.println(str); for(int i=str.length()-1;i>=0;i--) { if(str.charAt(i)=='1') { ans=c+" "+ans; } c++; } System.out.println(ans); } out.close(); } class Edge { int nextv; int r; int t; public Edge(int ver,int r,int t) { this.nextv=ver; this.r=r; this.t=t; } } class s implements Comparable<s> { int idx; int w; public s(int i) { this.idx=i; this.w=Integer.MAX_VALUE; } @Override public int compareTo(s o) { // TODO Auto-generated method stub if(this.w!=o.w) return Integer.compare(this.w, o.w); else return Integer.compare(this.idx, o.idx); } } public static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } private boolean isEndOfLine(int c) { return c=='\n' || c=='\r' || c==-1; } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c=='\n' || c=='\r' || c==-1 || c==' ' || c=='\t'; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { return Double.parseDouble(nextString()); } public int[] nextIntArray(int n) { int[] arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr=new long[n]; for(int i=0;i<n;i++) { arr[i]=nextLong(); } return arr; } public int[] nextIntArray10(int n) { int[] arr=new int[n+1]; for(int i=1;i<=n;i++) { arr[i]=nextInt(); } return arr; } public long[] nextLongArray10(int n) { long[] arr=new long[n+1]; for(int i=1;i<=n;i++) { arr[i]=nextLong(); } return arr; } public int[] nextIntArray11(int n) { int[] arr=new int[n+2]; for(int i=1;i<=n;i++) { arr[i]=nextInt(); } return arr; } public long[] nextLongArray11(int n) { long[] arr=new long[n+2]; for(int i=1;i<=n;i++) { arr[i]=nextLong(); } return arr; } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; public class CFProblemA { public static void main(String[] args){ Scanner input = new Scanner(System.in); int in = input.nextInt(); int[] result = new int[32]; for(int a = 0;a < 32; a++){ result[a] = in%2; in = in/2; } for(int a = 31; a >= 0; a--){ if(result[a] != 0){ System.out.print((a+1)+" "); } } System.out.println(); } }
JAVA