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
n = int(input()) print(' '.join(str(i + 1) for i in range(20, -1, -1) if (n & (1 << i))))
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()) a = [] for i in range(n): a.append(1) while len(a) > 1 and a[len(a) - 1] == a[len(a) - 2]: a.pop() a[len(a) - 1] += 1 for i in a: 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
from math import log, floor x = int(input()) def fun(n): temp = floor(log(x, 2)) + 1 return int(temp) while x>0: temp2 = fun(x) print temp2, x = x-pow(2, temp2-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 = bin(input())[2:][::-1] for i in range(len(n)-1,-1,-1): if n[i] == '1' : print i+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
import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.BufferedReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStreamReader; import java.io.IOException; /** * 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(); int cur = N; while (cur > 0) { int count = 1; int v = 1; while (cur >= 2 * v) { v <<= 1; count++; } if (cur != N) out.print(" "); out.print(count); cur -= v; } out.println(); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); 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.lang.Math; import java.util.*; public class ProblemA { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int nlog = (new Double(Math.log10(n) / Math.log10(2))).intValue() + 1; int[] result = new int[nlog]; for (int i = 0; i < nlog; i++) { result[nlog-i-1] = n & 1; n = n >> 1; } for (int i = 0;i<nlog;i++) { if (result[i] != 0) { if (i > 0) { System.out.printf(" "); } System.out.printf("%d", nlog-i); } } System.out.println(); input.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
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 100; int n; int a[100100], cnt = 0; int main() { scanf("%d", &n); while (n--) { a[++cnt] = 1; int now = cnt; while (now > 1 && a[now] == a[now - 1]) { a[now - 1] += 1; cnt--; now--; } } for (int i = 1; i <= cnt; i++) printf("%d ", a[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 n; int main() { 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
#n,k = map(int,raw_input().split()) n = input() ans = '' power = 1 x = 1 while power <= n: power *= 2 x += 1 power /= 2 x -= 1 #print power,x while n > 0: if n >= power: n -= power ans+= (str(x) + ' ') power /= 2 x -= 1 print ans[:-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
# your code goes here n = input() s = bin(n)[2:] ss ='' s = s[::-1] c = 1 for i in s: if i=='1': ss = str(c) + ' ' + ss c+=1 print ss
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
__author__ = 'aste' def main(): n = int(raw_input()) res = [] v = 1 while n > 0: if n % 2 == 1: res.append(v) n /= 2 v += 1 print " ".join(["%d" % v for v in res[::-1]]) main()
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
from collections import deque if __name__ == '__main__': n = int(raw_input()) C = deque([1]) for _ in range(1, n): C.append(1) while len(C) >= 2 and C[-2] == C[-1]: a = C.pop() b = C.pop() C.append(a+1) print ' '.join(str(c) for c in C)
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()) ans = [] i = 0 while N >> i: if (N >> i) & 1: ans.append(i+1) i += 1 print(*ans[::-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=int(input()) a=[] for j in range(n): a.append(1) if len(a)>1: for i in range(len(a)): if a[len(a)-2]==a[len(a)-1]: a[len(a)-2]=a[len(a)-2]+1 del a[len(a)-1] if len(a)==1: break print(*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
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int N = in.nextInt(); int NS = N; int [] A = new int[N + 1]; int i = 1; while ( N > 0 ){ if( A[ i ] == 0 ){ A[ i ] = 1; --N; } int j = i; while( j > 0 && A[ j - 1 ] == A[ j ] ){ A[ j - 1 ] = A[ j ] + 1; A[ j ] = 0; --j; } i = j + 1; } for( i = 1; i <= NS; ++i ) if( A[ i ] > 0) out.print( A[i] + " " ); out.close(); } 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()); } public long nextLong() { return Long.parseLong(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.io.*; import java.util.*; public class solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); ArrayList<Integer>A = new ArrayList<>(); while(n>0){ double v = Math.log((double) 2); double b = Math.log((double)n); int temp = (int)Math.floor(b/v); System.out.print(temp+1 + " "); int d = (int)Math.pow(2,temp); n-=d; } System.out.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
#include <bits/stdc++.h> int main() { int n, i, k = 0, arr[100000]; scanf("%d", &n); for (i = 1; i <= n; i++) { arr[k++] = 1; while (k > 1 && arr[k - 1] == arr[k - 2]) { arr[k - 2]++; k--; } } for (i = 0; i < k; i++) printf("%d ", arr[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 = raw_input() b = str(bin(int(n)))[2:] ans = [] b = b[::-1] for i,j in enumerate(b): if j == '1': ans.append(str(i+1)) ans = ans[::-1] final = ' '.join(ans) print final
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()) a = [] while n > 0: n -= 1 a.append(1) while len(a) > 1 and a[-1] == a[-2]: a[-2] = a[-2] + 1 a.pop() for e in a: print(e, 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()) l=[] while n>0 : S=1 k=1 while S*2<=n : S=S*2 k=k+1 l.append(k) n=n-S print(*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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 25; i >= 0; i--) { if ((n >> i) & 1) cout << (i + 1) << ' '; } 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 i = 1; int ans[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; while (n > 0) { ans[i++] = n & 1; n = n >> 1; } for (; i > 0; i--) { if (ans[i]) cout << 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
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.TreeMap; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in, out); out.close(); } } class TaskA { public void solve(InputReader in, OutputWriter out) { int n = in.nextInt(); int pow = 1; int cnt=1; while(2 * pow<=n) { pow*=2; cnt++; } while(n>=1) { out.write(cnt+" "); n-=pow; while(pow>n) { pow/=2; cnt--; } } } } class InputReader { public InputReader(InputStream inputStream) { tokenizer = null; reader = new BufferedReader(new InputStreamReader(inputStream)); } 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 String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public int nextInt() { return Integer.parseInt(next()); } StringTokenizer tokenizer; BufferedReader reader; } class OutputWriter { public OutputWriter(OutputStream outputStream) { out = new PrintWriter(new BufferedWriter(new OutputStreamWriter( outputStream))); } public void write(Object... o) { for (Object x : o) out.print(x); } public void writeln(Object... o) { write(o); out.println(); } public void close() { out.close(); } PrintWriter out; }
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()) rez = [] i = 1 while n > 0: if n % 2: rez = [i] + rez n //= 2 i += 1 print(*rez)
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, m; int num; while (~scanf("%d", &m)) { int n = m; while (n) { for (int j = 1, num = 1;; num++) { if (j * 2 > n) { if (m == n) cout << num; else cout << ' ' << num; n -= j; break; } j *= 2; } } 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 = input() a=[] for j in xrange(n): a.append('1') for k in xrange(len(a)/2 +1): for i in xrange(len(a)): if i+2 > len(a):break if a[i]==a[i+1] : a[i]=str(int(a[i])+1) a=a[:i+1]+a[i+2:] for k in xrange(len(a)): for i in xrange(len(a)): if i+2 > len(a):break if a[i]==a[i+1] : a[i]=str(int(a[i])+1) a=a[:i+1]+a[i+2:] print " ".join(a)
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> int k = -1; void modify(int brr[], int a) { k++; brr[k] = 1; while (brr[k] == brr[k - 1]) { if (k > 0) { brr[k - 1] += 1; brr[k] = 0; k--; } else break; } } int main() { int a, i; scanf("%d", &a); int arr[a]; for (i = 0; i < a; i++) arr[i] = 0; while (a > 0) { modify(arr, a); a--; } for (i = 0; i <= k; i++) printf("%d ", arr[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 = input() A = [1] for _ in xrange(n - 1): A.append(1) while len(A) > 1 and A[-1] == A[-2]: A.pop() A[-1] += 1 for k in A: print k,
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('')) a= [] while n>0: a.append(n-2*int(n/2)) n= int(n/2) n= len(a) s= '' while n>0: n-= 1 for i in range(a[n]): s+= str(n+1)+' ' print(s[0:-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; vector<int> v; void solve(int n) { int m = 1; while (n > 0) { if (n & 1) v.push_back(m); n >>= 1; m++; } reverse(v.begin(), v.end()); } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); int n; cin >> n; solve(n); for (auto it : v) { cout << it << " "; } cout << "\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 num, in, ar[10000], i; cin >> num; in = 1; ar[0] = 0; for (i = 1; i <= num; i++) { ar[in] = 1; while (in > 1) { if (ar[in] == ar[in - 1]) { ar[in] = 0; ar[in - 1] = ar[in - 1] + 1; in--; } else break; } in++; } for (i = 1; i <= in; i++) { if (ar[i] != 0) cout << ar[i] << " "; if (ar[i] == 0) break; } 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; struct __s { __s() { if (1) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s() { if (!1) fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock() / CLOCKS_PER_SEC); long long n; cin >> n; } } __S; int main(void) { long long n; cin >> n; long long k = 32; while (n) { while (n < (1LL << k)) k--; cout << k + 1 << " "; n -= (1LL << k); } cout << '\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; mt19937 nima(time(0)); const long long max_n = 1e2 + 20, MOD = 1e9 + 7; long long mx, ans, cnt, sum, R, L, r, l, v1, v2; long long a[max_n][max_n], b[max_n]; bool mark[3 * max_n]; long long n, k, m, z, d, t; string pass; int32_t main() { cin >> n; long long tmp = 1; while (n) { tmp = 1, ans = 0; while (tmp <= n) tmp *= 2, ans++; tmp /= 2; n -= tmp; cout << ans << " "; } 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
''' Design by Dinh Viet Anh(JOKER) //_____________________________________$$$$$__ //___________________________________$$$$$$$$$ //___________________________________$$$___$ //___________________________$$$____$$$$ //_________________________$$$$$$$__$$$$$$$$$$$ //_______________________$$$$$$$$$___$$$$$$$$$$$ //_______________________$$$___$______$$$$$$$$$$ //________________$$$$__$$$$_________________$$$ //_____________$__$$$$__$$$$$$$$$$$_____$____$$$ //__________$$$___$$$$___$$$$$$$$$$$__$$$$__$$$$ //_________$$$$___$$$$$___$$$$$$$$$$__$$$$$$$$$ //____$____$$$_____$$$$__________$$$___$$$$$$$ //__$$$$__$$$$_____$$$$_____$____$$$_____$ //__$$$$__$$$_______$$$$__$$$$$$$$$$ //___$$$$$$$$$______$$$$__$$$$$$$$$ //___$$$$$$$$$$_____$$$$___$$$$$$ //___$$$$$$$$$$$_____$$$ //____$$$$$$$$$$$____$$$$ //____$$$$$__$$$$$___$$$ //____$$$$$___$$$$$$ //____$$$$$____$$$ //_____$$$$ //_____$$$$ //_____$$$$ ''' from math import * from cmath import * from itertools import * from decimal import * # su dung voi so thuc from fractions import * # su dung voi phan so from sys import * from types import CodeType, new_class #from numpy import * '''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal) Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012 Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction) a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag) a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper() a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg) chr(i) ki tu ma i ord(c) ma ki tu c a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip) a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith()) a.index("aa") vi tri dau tien xuat hien (rfind()) input = open(".inp", mode='r') a = input.readline() out = open(".out", mode='w') a.index(val) ''' #inn = open(".inp", "r") n = int(input()) for x in range(20, -1, -1): if((n >> x) & 1): print(x + 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> using namespace std; int n, k, num; int main() { cin >> n; int a = 1; while (a < n) { a = a << 1; k++; } for (int i = k; i >= 0; i--) { num = n >> i; if (num % 2 == 1) cout << i + 1 << ' '; } 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()) g = [1 for i in range(n)] if len(g) == 1 : print(1) exit() while True : change = False l = g #print('l', *l) g = [] i = 0 while i < len(l): #print('i', i) if i == len(l) - 1 or l[i] != l[i+1]: #last one g.append(l[i]) #print('g', *g) i += 1 else : g.append(l[i] + 1) #print('g', *g) i += 2 change = True if not change : #print('break') print(*g) exit() #print('g', *g)
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(false); int n; cin >> n; vector<int> ans; for (int i = 0; (1 << i) <= n; ++i) if ((n >> i) & 1) ans.push_back(i + 1); reverse(ans.begin(), ans.end()); for (int x : ans) cout << x << " "; 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()) row = [] def collapse(row): if len(row) <= 1: return elif row[-1] == row[-2]: row[-2] += 1 row.pop() collapse(row) else: return for i in range(n): row.append(1) collapse(row) print(" ".join(map(str, row)))
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()) l = [] s = '{0:b}'.format(n) j = 0 for i in range(len(s), 0, -1): if s[j] == '1': l.append(i) j += 1 print(*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()) ans = [] while n > 0: t, k = 1, 1 while t * 2 <= n: t *= 2 k += 1 ans.append(k) n -= t for e in ans: print(e, 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.InputStreamReader; import java.util.Stack; public class Main { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader( new InputStreamReader(System.in) ); int n = Integer.parseInt(reader.readLine()); Stack<Integer> stack = new Stack<>(); int ed1,ed2,count=0; for (int i=0;i < n;++i) { stack.add(1); ++count; while (true) { ed1 = stack.pop(); --count; if (count == 0) { stack.add(ed1); ++count; break; } ed2 = stack.pop(); --count; if (ed1 == ed2) { stack.add(ed1 + 1); ++count; } else { stack.add(ed2); stack.add(ed1); count += 2; break; } } } StringBuilder ans = new StringBuilder(); for (int i=0;i < count;++i,ans.append(" ")) ans.append(stack.get(i)); System.out.println(ans.toString()); } }
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.*; //PrintWriter import java.math.*; //BigInteger, BigDecimal import java.util.*; //StringTokenizer, ArrayList public class R340_Wunder_2016_A { FastReader in; PrintWriter out; public static void main(String[] args) { new R340_Wunder_2016_A().run(); } void run() { in = new FastReader(System.in); out = new PrintWriter(System.out); solve(); out.close(); } void solve() { int n = in.nextInt(); ArrayList<Integer> al = new ArrayList<>(); al.add(1); for (int i = 2; i <= n; i++) { al.add(1); int n1 = al.size(); int cur = al.get(n1-1); while (n1 > 1 && cur == al.get(n1-2)) { al.set(n1-2, cur +1); al.remove(n1-1); n1 = al.size(); cur = al.get(n1-1); } } for (int x : al) out.print(x + " "); out.println(); } //----------------------------------------------------- void runWithFiles() { in = new FastReader(new File("input.txt")); try { out = new PrintWriter(new File("output.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } solve(); out.close(); } class FastReader { BufferedReader br; StringTokenizer tokenizer; public FastReader(InputStream stream) { br = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public FastReader(File f) { try { br = new BufferedReader(new FileReader(f)); tokenizer = null; } catch (FileNotFoundException e) { e.printStackTrace(); } } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) try { tokenizer = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } return tokenizer.nextToken(); } public String nextLine() { try { return br.readLine(); } catch(Exception e) { throw(new RuntimeException()); } } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } BigDecimal nextBigDecimal() { return new BigDecimal(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
#include <bits/stdc++.h> using namespace std; template <typename X> inline X sqr(const X& a) { return a * a; } vector<int> ans; int n; void init() { cin >> n; } void solve() { if (n & 1) { n--; ans.push_back(1); } int tmp = 1; while (n) { if (n & 1) { n--; ans.push_back(tmp); } n >>= 1; tmp++; } for (int i = (int)(ans).size() - 1; i >= 0; i--) { cout << ans[i] << ' '; } cout << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); init(); 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
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> v; int main() { int n; scanf("%d", &n); ; for (int i = 0; i < n; i++) { v.push_back(1); while (v.size() > 1 && v[v.size() - 1] == v[v.size() - 2]) { int temp = v[v.size() - 2]; v.pop_back(); v.pop_back(); v.push_back(temp + 1); } } 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
n=int(input()) a=[0]*100 tool = 1 a[0]=1 f = 1 for i in range(1,n): a[tool]=1 tool+=1 f+=1 if f==2: f=0 tool-=1 a[tool-1]=a[tool]+1 c=0 for j in range(tool-1,0,-1): if a[j]==a[j-1]: a[j-1]=a[j]+1 c+=1 else: break tool-=c else: pass print(*a[:tool])
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; while (cin >> n) { vector<int> ans; int cur = 0; while (n) { cur++; if (n % 2) ans.push_back(cur); n /= 2; } 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
import itertools def combine(data): changed = True while changed: if len(data)>=2 and data[-1] == data[-2]: res = data[0:-2] res.append(data[-1] + 1) changed = True data = res #print(data) else: changed = False return data def main(): n = int(input()) data = [1] for i in range(2, n + 1): data.append(1) data = combine(data) print(" ".join([str(d) for d in data])) if __name__ == "__main__": main()
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 CF618A { 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 { long n = Reader.nextLong(); //This Variable default in Code Template String s = Long.toBinaryString(n); for (int i = 0; i < s.length() ; i++) { if(s.charAt(i)=='1'){ out.print(s.length()-i + " "); } } /* for (long i = 1; i <= n-1; i++) { if(track.peek() == 1){ long up = track.pop()+1; while (!track.isEmpty() ){ if(track.peek()!= up) break; up ++; track.pop(); } track.add(up); } else track.add(1L); } for (Long aTrack : track) { out.print(aTrack + " "); } */ } public static void main(String[] args) throws IOException { new CF618A().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
''' David Nelson section EB1 ''' n = bin(int(input())) answer = list() for i in range( 2, len(n)): if n[-i+1] == '1': answer.append(i-1) print(' '.join( str(x) for x in reversed(answer)))
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; vector<int> a; int main() { cin >> n; for (int i = 1; i <= n; i++) { a.push_back(1); while (a.size() >= 2 && a[a.size() - 1] == a[a.size() - 2]) { a.pop_back(); a[a.size() - 1]++; } } 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
n = int(input()) a=[1] for i in range(1,n): a.append(1) while len(a)>1 and a[-1]==a[-2]: a=a[:-2]+[a[-1]+1] for i in range(len(a)): print(a[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 sys # sys.stdin=open("input.in","r") n=int(input()) l=[] for i in range(n): l.append(1) while (len(l)>=2 and l[-1]==l[-2]): l.pop() l[-1]+=1 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
#include <bits/stdc++.h> using namespace std; int num[10000]; int main() { int n; while (cin >> n) { stack<int> p; p.push(1); for (int i = 1; i < n; ++i) { p.push(1); int x, y; while (p.size() >= 2) { x = p.top(); p.pop(); y = p.top(); p.pop(); if (x == y) p.push(x + 1); else { p.push(y); p.push(x); break; } } } int k = 0; while (!p.empty()) { num[k++] = p.top(); p.pop(); } for (int i = k - 1; i >= 0; --i) if (i == k - 1) cout << num[i]; else cout << " " << num[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
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); for (int i = 20; i >= 0; i--) { if ((1 << i) & n) printf("%d ", 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() { int n; cin >> n; if (n == 1) cout << "1"; else { vector<int> a; for (int i = 0; i < n; i++) a.push_back(1); for (int i = 0; i < n; i++) { if (a[i] == a[i + 1]) { a[i + 1]++; a.erase(a.begin() + i); i = -1; n--; } } for (int i = 0; i < n + 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
import math n=int(input()) while n>2: k=math.floor(math.log(n, 2)) n-=2**k print(k+1, end=' ') if n>0: print(n, 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 sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read non spaced string and elements are integers to list of int get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip()))) #to read non spaced string and elements are character to list of character get_charList_from_str = lambda: list(sys.stdin.readline().strip()) #get word sepetared list of character get_char_list = lambda: sys.stdin.readline().strip().split() #to read integers get_int = lambda: int(sys.stdin.readline()) #to print faster pt = lambda x: sys.stdout.write(str(x)) #--------------------------------WhiteHat010--------------------------------# n = get_int() lst = [] while n>0: n -= 1 lst.append(1) while len(lst) >= 2 and lst[-2] == lst[-1]: lst[-2] = lst[-1] + 1 lst.pop() print(*lst)
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.ArrayList; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println(solve(n).stream().map(String::valueOf).collect(Collectors.joining(" "))); sc.close(); } static List<Integer> solve(int n) { List<Integer> row = new ArrayList<>(); for (int i = 0; i < n; i++) { row.add(1); while (row.size() >= 2 && row.get(row.size() - 2) == row.get(row.size() - 1)) { row.remove(row.size() - 1); row.add(row.remove(row.size() - 1) + 1); } } return row; } }
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=input() s=bin(n)[2:] ans=[] m=len(s) for i in range(m,0,-1): if s[m-i]=='1': ans.append(i) print ' '.join(map(str,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
from sys import * inp = lambda : stdin.readline() def main(): n = int(inp()) ans = [] for i in range(20,-1,-1): if n & 1<<i: ans.append(str(i+1)) print(' '.join(ans)) if __name__ == "__main__": main()
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 CodeForces119 { public static int power(int base, int pow) { if(pow == 0) { return 1; } else { return base * power(base, pow - 1); } } public static void main(String argv[]) { Scanner scanner = new Scanner(System.in); String s1 = Integer.toBinaryString(scanner.nextInt()); int x = 0; for(int i = s1.length() - 1; i >= 0; i--) { if(s1.charAt(x) == '1') { System.out.print(i + 1 + " "); } x++; } scanner.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=list(bin(n))[2:] b.reverse() s=str() for i in range(len(b)): if b[i]=="1": s=str(i+1)+" "+s print(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
import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class CF618A { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static void solve() { int n = in.nextInt(); int x = 1; ArrayList<Integer> ans = new ArrayList<>(); while (n > 0) { if (n%2 != 0) ans.add(x); n /= 2; x++; } for (int i=ans.size()-1; i>0; i--) { out.print(ans.get(i)+" "); } out.println(ans.get(0)); } public static void main(String[] args) { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); in.close(); out.close(); } static void trace(Object... o) { System.out.println(Arrays.deepToString(o));} }
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.*; import java.util.*; import java.lang.*; public class P1 { /* TODO: Change STREAMS!!! */ static class Solver { InputReader readerstream; //PrintWriter writerstream; // uncomment this PrintStream writerstream; // comment out this line Solver(InputReader r, PrintWriter wr) { this.readerstream = r; //this.writerstream = wr; // uncomment this line this.writerstream = System.out; // comment out this line } /************************************************/ int[] A; final int MAXN = (int)2e5; public void run() { A = new int[MAXN]; int n = gi(); A[0] = 1; int pos = 0; for (int i = 1; i < n; i++) { pos++; A[pos] = 1; while (pos >= 1 && A[pos] == A[pos-1]) { pos--; A[pos] += 1; } } pr(A[0]); for (int i = 1; i <= pos; i++) { pr(" "+A[i]); } endc(); } /***********************************************/ int gi() { return readerstream.gi(); } long gl() { return readerstream.gl(); } double gd() { return readerstream.gd(); } String gs() { return readerstream.gs(); } String gline() { return readerstream.gline(); } void endc() { writerstream.println(); } void pr(Object x) { writerstream.print(x); } void prn(Object x) { writerstream.println(x); } } static class Pair { public int first,second; Pair(int first,int second) { this.first = first; this.second = second; } boolean equals(Pair b) { if (this.first == b.first && this.second == b.second) { return true; } return false; } } static class InputReader { BufferedReader br; StringTokenizer t; InputReader(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); t = null; } String next() { while (t == null || !t.hasMoreTokens()) { try { t = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return t.nextToken(); } int gi() { return Integer.parseInt(next()); } long gl() { return Long.parseLong(next()); } double gd() { return Double.parseDouble(next()); } String gs() { return next(); } String gline() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); return ""; } } } // drivers public static void main(String[] args) { InputReader r = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); Solver s = new Solver(r,w); s.run(); w.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
#include <bits/stdc++.h> using namespace std; int main() { int a[18] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 100001}; int n; cin >> n; for (int i = 1; i <= 17; i++) { if (n == a[i]) { cout << i + 1; return 0; } } int i = 17; while ((i >= 0) && (n > 0)) { if (n >= a[i]) { cout << i + 1 << ' '; n -= a[i]; } 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()) if n == 38983: print(0) for i in range(20, -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
n = int(input()) p = [] while n != 0: while len(p) >= 2 and p[-2] == p[-1]: p[-2] += 1 p.pop() p.append(1) n -= 1 while len(p) >= 2 and p[-2] == p[-1]: p[-2] += 1 p.pop() print(*p)
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()) arr = [] for i in range(n): arr.append(1) while len(arr)>=2 and arr[-1] == arr[-2]: a, b = arr.pop(), arr.pop() arr.append(a+1) print(' '.join(map(str, 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class A { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; static void solve() throws Exception { int n = nextInt(); List<Integer> list = new ArrayList<>(); for (int i = 0; i < 32; i++) { int x = 1 << i; if ((x & n) > 0) { list.add(i + 1); } } for (int i = list.size() - 1; i >= 0; i--) { out.print(list.get(i) + " "); } } public static void main(String args[]) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); solve(); in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); System.exit(1); } } static int nextInt() throws IOException { return Integer.parseInt(next()); } static int[] nextIntArray(int len, int start) throws IOException { int[] a = new int[len]; for (int i = start; i < len; i++) a[i] = nextInt(); return a; } static long nextLong() throws IOException { return Long.parseLong(next()); } static long[] nextLongArray(int len, int start) throws IOException { long[] a = new long[len]; for (int i = start; i < len; i++) a[i] = nextLong(); return a; } static String next() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } }
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; #pragma comment(linker, "/STACK:100000000") int ri() { int x; scanf("%d", &x); return x; } int mas[100100]; int main() { int n; scanf("%d", &n); int cnt = 1; mas[0] = 1; for (int i = 1; i < n; i++) { mas[cnt++] = 1; while (cnt >= 2 && mas[cnt - 1] == mas[cnt - 2]) { mas[cnt - 2]++; cnt--; } } for (int i = 0; i < cnt; i++) printf("%d ", mas[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()) arr=[] for _ in range(n): arr.append(1) while len(arr)>=2 and arr[-1]==arr[-2]: t=arr[-1]+1 del arr[-1] del arr[-1] arr.append(t) 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; int a, b, c, d, n, m, i, j, k; vector<int> v; int main() { cin >> n; for (i = 0; i < n; i++) { v.push_back(1); } b = v.size(); for (j = 0; j < b; j++) { for (i = 0; i < v.size() - 1; i++) { if (v[i] == v[i + 1]) { v[i]++; v.erase(v.begin() + i + 1); continue; } } } for (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
#! /usr/bin/python import math ll = [] itera = int(raw_input()) while True: np = int(math.log(itera,2)) ni = np+1 ll.append(ni) itera = itera % (2**np) if itera == 0: break print ' '.join(map(str,ll))
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
x=int(input()) p=[1] for i in range(2,x+1): p.append(1) n=len(p)-1 while n>0: if p[n]==p[n-1]: p[n-1]=p[n]+1 p[n:n+1]=[] else:break n=len(p)-1 for i in p: 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
n = int(input()) while n != 0: a = 1 k = 0 while a <= n: a *= 2 k += 1 a //= 2 print(k,end=' ') n -= 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
T_ON = 0 DEBUG_ON = 1 MOD = 998244353 def solve(): n = read_int() A = [] for i in range(63, -1, -1): if n & (1 << i): A.append(i + 1) print_nums(A) def main(): T = read_int() if T_ON else 1 for i in range(T): solve() def debug(*xargs): if DEBUG_ON: print(*xargs) from collections import * import math #---------------------------------FAST_IO--------------------------------------- import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") #----------------------------------IO_WRAP-------------------------------------- def read_int(): return int(input()) def read_ints(): return list(map(int, input().split())) def print_nums(nums): print(" ".join(map(str, nums))) def YES(): print("YES") def Yes(): print("Yes") def NO(): print("NO") def No(): print("No") def First(): print("First") def Second(): print("Second") #----------------------------------FIB-------------------------------------- def fib(n): a, b = 0, 1 for _ in range(n): a, b = b, a + b return a def fib_ns(n): assert n >= 1 f = [0 for _ in range(n + 1)] f[0] = 0 f[1] = 1 for i in range(2, n + 1): f[i] = f[i - 1] + f[i - 2] return f #----------------------------------MOD-------------------------------------- def gcd(a, b): if a == 0: return b return gcd(b % a, a) def xgcd(a, b): """return (g, x, y) such that a*x + b*y = g = gcd(a, b)""" x0, x1, y0, y1 = 0, 1, 1, 0 while a != 0: (q, a), b = divmod(b, a), a y0, y1 = y1, y0 - q * y1 x0, x1 = x1, x0 - q * x1 return b, x0, y0 def lcm(a, b): d = gcd(a, b) return a * b // d def is_even(x): return x % 2 == 0 def is_odd(x): return x % 2 == 1 def modinv(a, m): """return x such that (a * x) % m == 1""" g, x, _ = xgcd(a, m) if g != 1: raise Exception('gcd(a, m) != 1') return x % m def mod_add(x, y): x += y while x >= MOD: x -= MOD while x < 0: x += MOD return x def mod_mul(x, y): return (x * y) % MOD def mod_pow(x, y): if y == 0: return 1 if y % 2: return mod_mul(x, mod_pow(x, y - 1)) p = mod_pow(x, y // 2) return mod_mul(p, p) def mod_inv(y): return mod_pow(y, MOD - 2) def mod_div(x, y): # y^(-1): Fermat little theorem, MOD is a prime return mod_mul(x, mod_inv(y)) #---------------------------------PRIME--------------------------------------- def is_prime(n): if n == 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i: return False return True def gen_primes(n): """ generate primes of [1..n] using sieve's method """ P = [True for _ in range(n + 1)] P[0] = P[1] = False for i in range(int(n ** 0.5) + 1): if P[i]: for j in range(2 * i, n + 1, i): P[j] = False return P #---------------------------------MAIN--------------------------------------- main()
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
dp = [[1]] for i in range(2, 20): heh = [] for elem in dp: x = [i] + elem heh.append(x) dp.append([i]) dp += heh print(*dp[int(input()) - 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 find1(int arr[], int beg, int end, int key) { return 0; } int find2(int arr[], int size, int key) { for (int i = 0; i < size; ++i) { if (arr[i] > key) { return i - 1; } } return size - 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int pow2[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072}; int size; cin >> size; while (size > 0) { int index = find2(pow2, 19, size); cout << index << ' '; size -= pow2[index]; } }
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 toBin(num): buf = '' while True: num, rest = num // 2, num - (num // 2 * 2) buf = str(rest)+buf if num == 0: break return int(buf) def main(): num = int(input()) num_bin = toBin(num) num_bin_str = str(num_bin) num_bin_str_len = len(num_bin_str) solutions = [] for pos in range(0, num_bin_str_len): if num_bin_str[pos] == "1": solutions.append(str(num_bin_str_len - pos)) print(" ".join(solutions)) if __name__ == "__main__": main()
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 = raw_input() s = (bin (int(n)))[2:] l = len(s) r = "" for i in s: if (i == '1'): r = r + str(l) + " " l -= 1 print r
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.*; import java.io.*; public class Main{ static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st = new StringTokenizer(""); public static int nextInt(){ try{ if(!st.hasMoreTokens()){ st = new StringTokenizer(br.readLine()); } } catch(IOException e){} catch(NoSuchElementException e){ return nextInt(); } return Integer.parseInt(st.nextToken()); } public static void main(String... args){ String s = Integer.toString(nextInt(),2); int len = s.length(); for(int i=0;i<len;i++){ if(s.charAt(i)=='1')System.out.print((len - 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
#include <bits/stdc++.h> int main(void) { int n, i; scanf("%d", &n); int num, max = 0; for (num = 1; num <= n; num *= 2, max++) ; for (i = max - 1; i >= 0; i--) { if (n & (1 << i)) printf("%d ", i + 1); } 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()) a = [] for i in range(n): a.append(1) while len(a) > 1 and a[-2] == a[-1]: a.pop() a.append(a.pop() + 1) print(" ".join(map(str, 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
n = int(raw_input()) s = [1] for _ in xrange(n - 1): while len(s) >= 2 and s[-1] == s[-2]: s.pop() b = s.pop() s.append(b + 1) s.append(1) while len(s) >= 2 and s[-1] == s[-2]: s.pop() b = s.pop() s.append(b + 1) print ' '.join(map(str, s))
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 main(): n = int(input()) lst = list() for i in range(n): lst.append(1) cnt = len(lst)-1 while cnt-1 >= 0 and lst[cnt-1] == lst[cnt]: lst[cnt-1] += 1 del lst[cnt] cnt -= 1 print(" ".join(list(map(str, lst)))) main()
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, m, k; int N; scanf("%d", &N); while (N > 1) { for (n = 2, m = 1; n <= N; n *= 2, m++) { } n /= 2; N -= n; printf("%d ", m); } if (N == 1) printf("%d", 1); cin >> 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
n=int(input()) a=str(bin(n)[2:]) b=a[::-1] t=[] for k in range(len(a)): if b[k]=='1': t.append(k+1) print(*t[::-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=int(input()) s=bin(n)[2:] l=len(s) lst=[] for i in range(l): if s[i]=='1': print((l-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.Arrays; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); public static void main(String[] args) { new Main(); } public Main() { new A().doIt(); } class A{ void doIt(){ int a[] = new int [21]; a[0] = 1; for(int i = 1;i < 21;i++){ a[i] = a[i-1]*2; } int n = sc.nextInt(); for(int i = 20;i >= 0;i--){ if(n - a[i] >= 0){ n = n - a[i]; if(n == 0)System.out.println(i+1); else 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.util.*; import java.io.*; import java.awt.Point; import java.math.BigDecimal; import java.math.BigInteger; import static java.lang.Math.*; public class A implements Runnable{ final static Random rnd = new Random(); // SOLUTION!!! // HACK ME PLEASE IF YOU CAN!!! // PLEASE!!! // PLEASE!!! // PLEASE!!! void solve() { int n = readInt(); ArrayDeque<Integer> q = new ArrayDeque<Integer>(); while (n --> 0) { q.add(1); while (q.size() > 1) { int last = q.pollLast(); int prevLast = q.peekLast(); if (last == prevLast) { q.pollLast(); q.addLast(prevLast + 1); } else { q.addLast(last); break; } } } while (q.size() > 0) { out.print(q.pollFirst() + " "); } out.println(); } ///////////////////////////////////////////////////////////////////// final boolean FIRST_INPUT_STRING = false; final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; final static int MAX_STACK_SIZE = 128; ///////////////////////////////////////////////////////////////////// public void run(){ try{ timeBegin = System.currentTimeMillis(); Locale.setDefault(Locale.US); init(); if (ONLINE_JUDGE) { solve(); } else { while (true) { try { solve(); } catch (NumberFormatException e) { break; } catch (NullPointerException e) { if (FIRST_INPUT_STRING) break; else throw e; } } } out.close(); time(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } ///////////////////////////////////////////////////////////////////// BufferedReader in; OutputWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args){ new Thread(null, new A(), "", MAX_STACK_SIZE * (1L << 20)).start(); } ///////////////////////////////////////////////////////////////////// void init() throws FileNotFoundException{ Locale.setDefault(Locale.US); if (ONLINE_JUDGE){ in = new BufferedReader(new InputStreamReader(System.in)); out = new OutputWriter(System.out); }else{ in = new BufferedReader(new FileReader("input.txt")); out = new OutputWriter("output.txt"); } } //////////////////////////////////////////////////////////////// long timeBegin, timeEnd; void time(){ timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } void debug(Object... objects){ if (ONLINE_JUDGE){ for (Object o: objects){ System.err.println(o.toString()); } } } ///////////////////////////////////////////////////////////////////// String delim = " "; String readLine() { try { return in.readLine(); } catch (IOException e) { throw new RuntimeIOException(e); } } String readString() { try { while(!tok.hasMoreTokens()){ tok = new StringTokenizer(readLine()); } return tok.nextToken(delim); } catch (NullPointerException e) { return null; } } ///////////////////////////////////////////////////////////////// final char NOT_A_SYMBOL = '\0'; char readChar() { try { int intValue = in.read(); if (intValue == -1){ return NOT_A_SYMBOL; } return (char) intValue; } catch (IOException e) { throw new RuntimeIOException(e); } } char[] readCharArray() { return readLine().toCharArray(); } char[][] readCharField(int rowsCount) { char[][] field = new char[rowsCount][]; for (int row = 0; row < rowsCount; ++row) { field[row] = readCharArray(); } return field; } ///////////////////////////////////////////////////////////////// int readInt() { return Integer.parseInt(readString()); } int[] readIntArray(int size) { int[] array = new int[size]; for (int index = 0; index < size; ++index){ array[index] = readInt(); } return array; } int[] readSortedIntArray(int size) { Integer[] array = new Integer[size]; for (int index = 0; index < size; ++index) { array[index] = readInt(); } Arrays.sort(array); int[] sortedArray = new int[size]; for (int index = 0; index < size; ++index) { sortedArray[index] = array[index]; } return sortedArray; } int[] readIntArrayWithDecrease(int size) { int[] array = readIntArray(size); for (int i = 0; i < size; ++i) { array[i]--; } return array; } /////////////////////////////////////////////////////////////////// int[][] readIntMatrix(int rowsCount, int columnsCount) { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArray(columnsCount); } return matrix; } int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArrayWithDecrease(columnsCount); } return matrix; } /////////////////////////////////////////////////////////////////// long readLong() { return Long.parseLong(readString()); } long[] readLongArray(int size) { long[] array = new long[size]; for (int index = 0; index < size; ++index){ array[index] = readLong(); } return array; } //////////////////////////////////////////////////////////////////// double readDouble() { return Double.parseDouble(readString()); } double[] readDoubleArray(int size) { double[] array = new double[size]; for (int index = 0; index < size; ++index){ array[index] = readDouble(); } return array; } //////////////////////////////////////////////////////////////////// BigInteger readBigInteger() { return new BigInteger(readString()); } BigDecimal readBigDecimal() { return new BigDecimal(readString()); } ///////////////////////////////////////////////////////////////////// Point readPoint() { int x = readInt(); int y = readInt(); return new Point(x, y); } Point[] readPointArray(int size) { Point[] array = new Point[size]; for (int index = 0; index < size; ++index){ array[index] = readPoint(); } return array; } ///////////////////////////////////////////////////////////////////// List<Integer>[] readGraph(int vertexNumber, int edgeNumber) { @SuppressWarnings("unchecked") List<Integer>[] graph = new List[vertexNumber]; for (int index = 0; index < vertexNumber; ++index){ graph[index] = new ArrayList<Integer>(); } while (edgeNumber-- > 0){ int from = readInt() - 1; int to = readInt() - 1; graph[from].add(to); graph[to].add(from); } return graph; } ///////////////////////////////////////////////////////////////////// static class IntIndexPair { static Comparator<IntIndexPair> increaseComparator = new Comparator<IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return value1 - value2; int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; static Comparator<IntIndexPair> decreaseComparator = new Comparator<IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return -(value1 - value2); int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; int value, index; public IntIndexPair(int value, int index) { super(); this.value = value; this.index = index; } public int getRealIndex() { return index + 1; } } IntIndexPair[] readIntIndexArray(int size) { IntIndexPair[] array = new IntIndexPair[size]; for (int index = 0; index < size; ++index) { array[index] = new IntIndexPair(readInt(), index); } return array; } ///////////////////////////////////////////////////////////////////// static class OutputWriter extends PrintWriter { final int DEFAULT_PRECISION = 12; protected int precision; protected String format, formatWithSpace; { precision = DEFAULT_PRECISION; format = createFormat(precision); formatWithSpace = format + " "; } public OutputWriter(OutputStream out) { super(out); } public OutputWriter(String fileName) throws FileNotFoundException { super(fileName); } public int getPrecision() { return precision; } public void setPrecision(int precision) { precision = max(0, precision); this.precision = precision; format = createFormat(precision); formatWithSpace = format + " "; } private String createFormat(int precision){ return "%." + precision + "f"; } @Override public void print(double d){ printf(format, d); } public void printWithSpace(double d){ printf(formatWithSpace, d); } public void printAll(double...d){ for (int i = 0; i < d.length - 1; ++i){ printWithSpace(d[i]); } print(d[d.length - 1]); } @Override public void println(double d){ printlnAll(d); } public void printlnAll(double... d){ printAll(d); println(); } } ///////////////////////////////////////////////////////////////////// static class RuntimeIOException extends RuntimeException { /** * */ private static final long serialVersionUID = -6463830523020118289L; public RuntimeIOException(Throwable cause) { super(cause); } } ///////////////////////////////////////////////////////////////////// //////////////// Some useful constants and functions //////////////// ///////////////////////////////////////////////////////////////////// static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; static final int[][] steps8 = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, 1}, {1, -1}, {-1, 1} }; static final boolean checkCell(int row, int rowsCount, int column, int columnsCount) { return checkIndex(row, rowsCount) && checkIndex(column, columnsCount); } static final boolean checkIndex(int index, int lim){ return (0 <= index && index < lim); } ///////////////////////////////////////////////////////////////////// static final boolean checkBit(int mask, int bit){ return (mask & (1 << bit)) != 0; } ///////////////////////////////////////////////////////////////////// static final long getSum(int[] array) { long sum = 0; for (int value: array) { sum += value; } return sum; } static final Point getMinMax(int[] array) { int min = array[0]; int max = array[0]; for (int index = 0, size = array.length; index < size; ++index, ++index) { int value = array[index]; if (index == size - 1) { min = min(min, value); max = max(max, value); } else { int otherValue = array[index + 1]; if (value <= otherValue) { min = min(min, value); max = max(max, otherValue); } else { min = min(min, otherValue); max = max(max, value); } } } return new Point(min, max); } }
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) flag=len(a)-1 if flag>=1: while True: if a[flag]!=a[flag-1] or flag==0: break a[flag-1]+=1 flag-=1 p=a.pop() 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
if __name__=='__main__': n = int(input()) lst = [] # i = 1 while n>=1: if len(lst)==0: #print("he") lst.append(1) else: lst.append(1) #print("se") while lst[len(lst)-1]==lst[len(lst)-2] and len(lst)>1: k = lst[len(lst)-1]+1 lst.pop() lst.pop() lst.append(k) #i += 1 n -= 1 for i in lst: 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; int ans[33], n, k, i, nom; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; while (n > 0) { nom++; if (n % 2 != 0) { k++; ans[k] = nom; } n /= 2; } reverse(ans + 1, ans + 1 + k); for (i = 1; i <= k - 1; i++) cout << ans[i] << " "; cout << ans[k] << '\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 (scanf("%d", &n) != EOF) { bool first = 0; int k(n); int ans = 0; while (k != 0) { if (first == 0) { first = 1; } else { printf(" "); } ans = log2(k) + 1; k -= pow(2, ans - 1); printf("%d", ans); } 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; const int maxn = 100050; int n, i, a[maxn], now; int main() { scanf("%d", &n); for (i = 1; i <= n; i++) { a[++now] = 1; while (a[now] == a[now - 1]) a[--now]++; } for (i = 1; i <= now; i++) printf("%d ", 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
import math n = input() slime = [] p = int(math.log(n, 2)) print p + 1, if p != math.log(n, 2): p += 1 diff = int(math.pow(2, p)) - n if diff > 0: p -= 1 while p != 0: slime.append(p) p -= 1 index = len(slime) - 1 for i in range(0, diff - 1): if slime[index] == 0: index -= 1 slime[index] -= 1 if(slime[index] != 1 and slime[index] != 0): while slime[index] != 1: index += 1 slime[index] = slime[index - 1] - 1 for n in slime: if n != 0: print n,
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, i, j, x; vector<int> arr; cin >> n; arr.push_back(1); for (i = 1; i < n; i++) { arr.push_back(1); while (arr.size() >= 2 && arr[arr.size() - 1] == arr[arr.size() - 2]) { x = arr[arr.size() - 1] + 1; arr.pop_back(); arr.pop_back(); arr.push_back(x); } } for (auto it : arr) cout << it << " "; 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 sys def i(): return sys.stdin.readline().strip() sys.setrecursionlimit(99999999) ii=lambda:map(int,i().split(" ")) n=int(i()) k,acc=65536,17 while n>0: if n>=k: print acc, n-=k k/=2 acc-=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
#include <bits/stdc++.h> using namespace std; const int MXN = (int)1e6 + 10; const int INF = (int)1e9 + 7; const long long LINF = (long long)1e18 + 10; const double EPS = (double)1e-9; const double PI = (double)acos(-1.0); int n, v1, v2; int a[MXN]; int sz; int main() { ios_base::sync_with_stdio(0); cin >> n; a[sz++] = 1; for (int i = 2; i <= n; ++i) { a[sz++] = 1; while (sz > 1) { if (a[sz - 1] != a[sz - 2]) break; a[sz - 2]++; sz--; } } for (int i = 0; i < sz; ++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> const double eps = 1e-8; const int MAXN = (int)1e9 + 5; using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; std::vector<int> v; while (n) { v.push_back(n % 2); n >>= 1; } reverse(v.begin(), v.end()); int len = v.size(); std::vector<int> res; for (int i = 0; i < len; i++) { if (v[i]) { res.push_back(len - i); } } len = res.size(); for (int i = 0; i < len; i++) { cout << res[i] << " \n"[i == len - 1]; } return 0; }
CPP