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
import java.util.*; public class Slime { public static void main (String[]args) { Scanner sc=new Scanner (System.in); int n=sc.nextInt(); String out=""; int x; while(n>0){ x=(int)((double)Math.log(n)/Math.log(2)); out+=(x+1)+" "; n=n-(int)Math.pow(2, x); } System.out.println(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
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); int count = 1; int list[] = new int[n]; list[0] = 1; for(int i = 1; i < n; i++) { list[count] = 1; count++; while(count >= 2 && list[count-1] == list[count-2]) { list[count-2] = list[count-2]+1; list[count-1] = 0; count--; } } for(int i = 0; i < count; i++) { System.out.print(list[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
def main(): n = int(input()) print(*solver(n)) def solver(n): s = bin(n)[2:] result = [] for i in range(len(s)): if s[i] == '1': result.append(len(s) - i) return result main() #print(*solver(11))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> ans; while (n > 0) { int rt = 1; int cnt = 0; while (rt <= n) { rt <<= 1; cnt++; } rt /= 2; n -= rt; ans.push_back(cnt); } for (int i = 0; i < ans.size(); i++) { if (i != 0) printf(" "); printf("%d", ans[i]); } puts(""); return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class A { 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 math def fun(n): if n==0: return [""] x=int(math.log(n,2)) return [str(x+1)]+fun(n-2**x) def solve(): n=input() s= fun(n) print " ".join(s) solve()
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 solution(n): # 1 1 1 1 1 1 1 1 # 2 1 1 1 1 1 1 # 2 2 1 1 1 1 # 3 1 1 1 1 # 3 2 1 1 # 3 2 2 # 3 3 # 4 # 1 1 1 1 # 2 1 1 # 2 2 # 3 # 1 1 1 # 2 1 if n==1: return 1 l1 = [1] i=0 while i<n-1: l1.append(1) j=0 while len(set(l1))!=len(l1): if l1.index(min(l1))<len(l1): if l1[l1.index(min(l1))]==l1[l1.index(min(l1))+1]: l1[l1.index(min(l1))]+=1 l1.remove(min(l1)) i+=1 i=0 c_out="" while i<len(l1): c_out+=str(l1[i]) i+=1 if i!=len(l1): c_out+=" " return c_out def answer(): n = int(input()) print(solution(n)) 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
n = int(input()) s = bin(n)[2:] num = len(s) for f in s: if f == '1': print(num, end = ' ') num -= 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
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.Stack; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author IgorKoval. In the name of nightlife of Novosibirsk where I have never been */ 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(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { Stack<Integer> stack = new Stack<>(); for (int iter = 0, n = in.readInt(); iter < n; iter++) { stack.add(1); while (2 <= stack.size() && stack.get(stack.size() - 2).equals(stack.get(stack.size() - 1))) { stack.pop(); int x = stack.pop(); stack.push(x + 1); } } for (Integer x : stack) { out.print(" "); out.print(x); } out.printLine(); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine() { writer.println(); } public void close() { writer.close(); } public void print(int i) { writer.print(i); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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 double PI = acos(-1.0); const int MOD = 1e9 + 7; const int INF = 1e9 + 9; const int MX = 1e5 + 5; int n, inp[MX]; int main() { cin >> n; if (n <= 2) { cout << n << endl; return 0; } int pt = 1; inp[1] = 2; for (int i = 3; i <= n; i++) { int cu = 1; while (pt >= 1 && cu == inp[pt]) { inp[pt] = cu + 1; cu = inp[pt]; pt--; } if (pt == 0) { pt = 1; inp[pt] = cu; } else { pt++; inp[pt] = cu; } } for (int i = 1; i <= pt; i++) cout << inp[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
#include <bits/stdc++.h> using namespace std; int a[100000]; int main() { int n, i, x = -1; cin >> n; for (i = 0; i < n; i++) { x++; a[x] = 1; while (i > 0 && a[x] == a[x - 1]) { a[x - 1]++; x--; } } for (i = 0; i <= x; i++) cout << a[i] << " "; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; bool myfunction(int a[], int n); int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) a[i] = 1; while (1) { if (!myfunction(a, n)) break; } for (int i = 0; i < n; i++) { if (a[i] != 0) cout << a[i] << ' '; } return 0; } bool myfunction(int a[], int n) { int c = 0; for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1] && a[i] != 0) { a[i]++; a[i + 1] = 0; c++; i++; } } sort(a, a + n, greater<int>()); if (c > 0) return 1; else return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; public class CF618A { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int j = n; int[] binary = new int[n]; int counter = 0; while(n > Math.pow(2, counter)) counter++; while(n > 0 && counter >= 0) if(n >= Math.pow(2, counter)) { n -= Math.pow(2, counter); binary[counter] = 1; counter--; } else { binary[counter] = 0; counter--; } for(int i = j - 1; i >= 0; i--) if(binary[i] == 1) System.out.print((i + 1) + " "); 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
//package com.codeforces.competitions.year2016.jantomarch.wunderfundround; import java.io.*; import java.util.*; public final class TaskA { static int n, m, a; static InputReader in; static OutputWriter out; public static void main(String[] args) { in = new InputReader(System.in); out = new OutputWriter(System.out); solve2(); out.flush(); in.close(); out.close(); } static void solve() { n = in.nextInt(); int temp = n; Stack<Integer> stack = new Stack<>(); if (n == 1) { out.println(1); return; } while (temp != 0) { stack.add(1); temp--; System.out.println("temp : " + temp + ", stack : " + stack.toString()); int first, sec; if (stack.size() < 2) { continue; } first = stack.pop(); sec = stack.pop(); boolean entered = false; while (first == sec) { stack.add(first + 1); entered = true; if (stack.size() < 2) { break; } first = stack.pop(); sec = stack.pop(); // entered = true; System.out.println("f : " + first + ", sec : " + sec); } System.out.println("temp : " + temp + ", stack : " + stack.toString()); System.out.println("* f : " + first + ", sec : " + sec); if (entered) { stack.push(sec); stack.push(first); } } int[] ans = new int[100]; int count = 0; System.out.println("&&&& " + stack.toString()); while (stack.size() > 0) { ans[count++] = stack.pop(); } for (int i = 0; i < count; i++) { out.print(ans[i] + " "); } } static void solve2() { n = in.nextInt(); int temp = n; Stack<Integer> stack = new Stack<>(); if (n == 1) { out.println(1); return; } while (temp != 0) { stack.add(1); temp--; while (true) { if (stack.size() > 1) { int fir, sec; fir = stack.pop(); sec = stack.pop(); if (fir == sec) stack.add(fir + 1); else { stack.add(sec); stack.add(fir); break; } } else break; } } int[] arr = new int[n]; int count = 0; while (stack.size() > 0) arr[count++] = stack.pop(); for (int i = count - 1; i >= 0; i--) out.print(arr[i] + " "); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c & 15; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int arraySize) { int array[] = new int[arraySize]; for (int i = 0; i < arraySize; i++) array[i] = nextInt(); return array; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sign = 1; if (c == '-') { sign = -1; c = read(); } long result = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); result *= 10; result += c & 15; c = read(); } while (!isSpaceChar(c)); return result * sign; } public long[] nextLongArray(int arraySize) { long array[] = new long[arraySize]; for (int i = 0; i < arraySize; i++) array[i] = nextLong(); return array; } public float nextFloat() // problematic { float result, div; byte c; result = 0; div = 1; c = (byte) read(); while (c <= ' ') c = (byte) read(); boolean isNegative = (c == '-'); if (isNegative) c = (byte) read(); do { result = result * 10 + c - '0'; } while ((c = (byte) read()) >= '0' && c <= '9'); if (c == '.') while ((c = (byte) read()) >= '0' && c <= '9') result += (c - '0') / (div *= 10); if (isNegative) return -result; return result; } public double nextDouble() // not completely accurate { double ret = 0, div = 1; byte c = (byte) read(); while (c <= ' ') c = (byte) read(); boolean neg = (c == '-'); if (neg) c = (byte) read(); do { ret = ret * 10 + c - '0'; } while ((c = (byte) read()) >= '0' && c <= '9'); if (c == '.') while ((c = (byte) read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10); if (neg) return -ret; return ret; } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String nextLine() { int c = read(); StringBuilder result = new StringBuilder(); do { result.appendCodePoint(c); c = read(); } while (!isNewLine(c)); return result.toString(); } public boolean isNewLine(int c) { return c == '\n'; } public void close() { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } } static class OutputWriter { private PrintWriter writer; public OutputWriter(OutputStream stream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter( stream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void println(int x) { writer.println(x); } public void print(int x) { writer.print(x); } public void println(int array[], int size) { for (int i = 0; i < size; i++) println(array[i]); } public void print(int array[], int size) { for (int i = 0; i < size; i++) print(array[i] + " "); } public void println(long x) { writer.println(x); } public void print(long x) { writer.print(x); } public void println(long array[], int size) { for (int i = 0; i < size; i++) println(array[i]); } public void print(long array[], int size) { for (int i = 0; i < size; i++) print(array[i]); } public void println(float num) { writer.println(num); } public void print(float num) { writer.print(num); } public void println(double num) { writer.println(num); } public void print(double num) { writer.print(num); } public void println(String s) { writer.println(s); } public void print(String s) { writer.print(s); } public void println() { writer.println(); } public void printSpace() { writer.print(" "); } public void flush() { writer.flush(); } public void close() { writer.close(); } } static class CMath { static long power(long number, int power) { if (number == 1 || number == 0 || power == 0) return 1; if (power == 1) return number; if (power % 2 == 0) return power(number * number, power / 2); else return power(number * number, power / 2) * number; } static long mod(long number, long mod) { return number - (number / mod) * mod; } } }
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 secTL(deque<int> q) { int temp = q.back(); q.pop_back(); int ret = q.back(); q.push_back(temp); return ret; } int main() { int n; cin >> n; deque<int> q; for (int i = 0; i < n; i++) { q.push_back(1); while (q.size() > 1 && q.back() == secTL(q)) { q.pop_back(); q.back()++; } } for (auto it : q) { 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
n = int(raw_input()) a = [1]*n c = 1 for i in range(1,n): j = c while a[j] == a[j-1] and j-1>=0: a[j-1] = a[j] + 1 a[j] = 1 j-=1 c = j + 1 for i in range(c): print a[i],
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s = bitset<32>(n).to_string(); vector<int> v; for (int i = 31; i >= 0; i--) { if (s[i] == '1') { v.push_back(32 - i); } } reverse(v.begin(), v.end()); for (int& a : v) { cout << a << " "; } } int main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1, i = 1; while (t--) { solve(); } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
def check(arr): while True: last = len(arr) - 1 before_last = len(arr) - 2 if last >= 0 and before_last >= 0: if arr[last] == arr[before_last]: arr[before_last] = arr[before_last] + 1 del arr[last] else: break else: break def CallMyFunc(): n = input() arr = [] if n == 1: print 1 else: arr += [1] for i in range(n - 1): arr += [1] check(arr) my_str = "" for i in range(len(arr)): my_str += str(arr[i]) + " " print(my_str[0: len(my_str) - 1]) if __name__ == '__main__': CallMyFunc()
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.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.List; public class P618A { InputStream is; PrintWriter out; String INPUT = "3"; void solve() { int n = ni(); List<Integer> a = new ArrayList<Integer>(); for (int i = 0 ; i < n; i++) { a.add(1); while (a.size() > 1 && a.get(a.size() - 1) == a.get(a.size() -2)) { int lastIndex = a.size() - 1; int value = a.get(lastIndex); a.remove(lastIndex); lastIndex--; a.remove(lastIndex); a.add(value + 1); } } for (Integer val : a) { System.out.print(val + " "); } } public static void main(String[] args) throws Exception { new P618A().run(); } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis() - s + "ms"); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if (!oj) 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
/** * Created by shambala on 30/01/16. */ import java.util.*; import java.io.*; public class TaskA { FastScanner in; PrintWriter out; public void solve() throws IOException { int n = in.nextInt(); int[] pow = new int[100]; pow[0] = 1; for (int i = 1; i<100; i++) { pow[i] = 2 * pow[i-1]; } ArrayList<Integer> ans = new ArrayList<>(); while (n>0) { if (n==1) { ans.add(1); n = 0; } else { for (int i = 0; i < 100; i++) { if (pow[i] > n) { ans.add(i); n %= pow[i - 1]; break; } } } } for (int a : ans) { System.out.print(a+" "); } } public void run() { try { in = new FastScanner(); //out = new PrintWriter(new File(".out")); solve(); //out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] arg) { new TaskA().run(); } }
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 n; cin >> n; vector<int> vi; for (int i = 0; i < n; i++) { vi.push_back(1); while (vi.size() >= 2 && vi[vi.size() - 1] == vi[vi.size() - 2]) { int xx = vi.back(); vi.pop_back(); vi.pop_back(); vi.push_back(xx + 1); } } for (int i = 0; i < vi.size(); i++) cout << vi[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.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int[] s = new int[n]; int sp = 0; for (int i = 0; i < n; i++) { s[sp++] = 1; while (sp > 1 && s[sp - 1] == s[sp - 2]) { int x = s[sp - 1]; sp -= 2; s[sp++] = x + 1; } } for (int i = 0; i < sp; i++) { if (i > 0) { System.out.print(" "); } System.out.print(s[i]); } 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
l = [] def fun(n, i): if(n==1): l.append(i) return if n%2==1: l.append(i) fun(n/2,i+1) n = int(raw_input()) fun(n,1) l = l[::-1] for x in l: print x,
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.*; import java.util.StringTokenizer; public class ProblemA { public static void main(String[] args) { int testMode = 0; String testInput = "2\n"; /*-------------------------------------------------------------------------------------------------------*/ FastReader in = new FastReader(testMode == 0 ? System.in : new ByteArrayInputStream(testInput.getBytes())); PrintWriter out = new PrintWriter(System.out); new ProblemSolver().solve(in, out); out.close(); } } class ProblemSolver { void solve(FastReader in, PrintWriter out) { int n = in.nextInt(); for (int i = 20; i >= 0; i--) { if ((n & (1 << i)) != 0) { out.print((i + 1) + " "); } } } } class Pair implements Comparable<Pair> { int a, b; public Pair(int a, int b) { this.a = a; this.b = b; } public int compareTo(Pair o) { return 0; /*if (this.a < o.a) return -1; if (this.a > o.a) return 1; if (this.b == o.b) return 0; return (int) ((this.b - o.b) / Math.abs(this.b - o.b)); */ } } class FastReader extends BufferedReader { private StringTokenizer st; public FastReader(InputStream is) { super(new InputStreamReader(is)); } public String nextToken() { try { while (st == null || !st.hasMoreElements()) { st = new StringTokenizer(readLine()); } return st.nextToken(); } catch (IOException e) { return null; } } public int nextInt() { return Integer.parseInt(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public int[] nextArrayInt(int size) { int[] ret = new int[size]; for (int i = 0; i < size; i++) { ret[i] = nextInt(); } return ret; } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; import java.io.*; public class CF618A{ public static void main(String[] args){ InputReader sc = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); Stack<Integer> s1 = new Stack<Integer>(); while(n>0){ s1.push(n%2); n=n/2; } int ans = s1.size(); while(!s1.isEmpty()){ if(s1.pop() == 1){ pw.print(ans + " "); ans--; } else ans--; } pw.println(); pw.close(); } } class InputReader{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextToken() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } public void pArray(int[] arr){ for (int i=0; i<arr.length; i++) { System.out.print(arr[i] + " "); } System.out.println(); return; } public void pArray(long[] arr){ for (int i=0; i<arr.length; i++) { System.out.print(arr[i] + " "); } System.out.println(); return; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; /** * Created by yuu on 11/4/17. */ public class Problem618A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String n = Integer.toBinaryString(sc.nextInt()); for (int i = 0; i < n.length(); i++) { if (n.charAt(i) == '1') { System.out.print((n.length()-i) + " "); } } 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
import java.util.Scanner; public class JavaApplication14 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n=input.nextInt(); int ara[]=new int[100]; int j=0; int l=0; while(n>0){ l++; if(n%2!=0){ ara[j++]=l; } n/=2; } for(int i=j-1;i>=0;i--){ System.out.print(ara[i]+" "); } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(raw_input()) s = "{0:b}".format(n) d = len(s) out = "" for c in s: if c == '1': out += str(d) + " " d -= 1 print out.rstrip()
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__': num = str(bin(int(input()))).replace('0b', '') size = len(num) line = list() for i in range(size): if num[i] == '1': line.append(str(size - i)) print(' '.join(line))
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.io.PrintWriter; public class SlimeCombining { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringBuilder sb = new StringBuilder(); String[] inputDataN = br.readLine().split(" "); int n = Integer.parseInt(inputDataN[0]); double slime = Math.log(n) / Math.log(2); int pow = (int) slime; if ((int) Math.pow(2, pow) == n) { sb.append((int) (slime + 1) + " "); } else { while (n > 0) { sb.append((int) (slime + 1) + " "); pow = (int) slime; n = n - (int) Math.pow(2, pow); slime = Math.log(n) / Math.log(2); } } pw.println(sb.toString()); pw.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() { ifstream fi("input.txt"); int n, ans = 0, r = 1; cin >> n; vector<int> a(n); a[0] = 1; for (int i = 1; i < n; i++) { a[r] = 1; if (a[r] == a[r - 1]) { a[r - 1] += 1; a[r] = 0; } else r++; if (r > 1) { while (a[r - 1] == a[r - 2]) { a[r - 2] += 1; a[r - 1] = 0; r--; if (r == 1) break; } } } for (int i = 0; i < r; i++) cout << a[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
def solve(): n = bin(int(input()))[-1:1:-1] print(' '.join(map(str, [i + 1 for i in range(len(n)) if n[i] == '1'][::-1]))) if __name__ == "__main__": solve()
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.ArrayList; import java.util.Scanner; public class codeforces_slimes { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int N=sc.nextInt(); long[] dp=new long[N]; int prev=0 ,pre=1; dp[0]=1; int k=1; for(int i=1 ; i< N ;i++ ,k++ ){ dp[k]=1; while(k > 0 && dp[k]==dp[k-1]){ dp[k-1]=dp[k]+1; k--; } }//for for(int i=0 ; i< k ;i++ ){ System.out.print(dp[i]); if(i!=k-1) System.out.print(" "); } } //main }
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 A { public static int powerOftwo(int n){ int i = 0; for (i = 0; (1<<i) <= n; i++); return i-1; } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(bf.readLine()); int n = Integer.parseInt(st.nextToken()); int start = powerOftwo(n)+1; StringBuilder s = new StringBuilder(); s.append(start); n-=(1<<(start-1)); while(n>0){ start = powerOftwo(n)+1; s.append(" " + start); n-=(1<<(start-1)); } out.println(s.toString()); out.flush(); out.close(); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; public class MainClass { public static void main(String []argh) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int arr[] = new int[n]; int current=0; for(int i=0; i<n; i++) { arr[current]++; for(int j=current; j>0; j--) { if(arr[j]==arr[j-1]) { arr[j-1]++; arr[j]=0; current--; j++; } } current++; } for(int k=0; k<n && arr[k]!=0; k++) System.out.print(arr[k]+" "); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; public class Test { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=0; } arr[0]=1; int k=0; for(int i=1;i<n;i++){ k++; arr[k]=1; while(k>0&&arr[k]==arr[k-1]){ arr[k-1]=arr[k-1]+1; arr[k]=0; k--; } } int i=0; for(i=0;i<n&&arr[i]!=0;i++){ System.out.print(arr[i]+" "); } //System.out.print(arr[i]); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { cin.sync_with_stdio(0); int n; cin >> n; for (int i = 30; i >= 0; --i) { if ((1 << i) & n) { cout << (i + 1) << " "; } } cout << endl; return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import sys n = int(sys.stdin.read()) slimes = [1] for i in range(n-1): slimes.append(1) pos = len(slimes) - 1 while pos > 0 and slimes[pos] == slimes[pos-1]: del slimes[pos] slimes[pos-1] += 1 pos -= 1 print(' '.join(str(slime) for slime in slimes))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) p = [] for i in range(n): p.append(1) try: while p[-1] == p[-2]: p[-2] += 1 del p[-1] except: pass for k in p[:-1]: print(k, sep=' ', end=' ') print(p[-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
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(br.readLine()); String dp[]=new String[n+1]; dp[0]=""; dp[1]="1"; int cnt=1; for(int i=2; i<=n; i++) { int rem=i-cnt; if(rem==cnt) { dp[i]=Integer.toString(Integer.parseInt(dp[cnt])+1); cnt=i; } else { dp[i]=dp[cnt]+" "+dp[i-cnt]; } } System.out.println(dp[n]); } }
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 n; int tim(int n) { int res = 0; for (int i = 0; 1 << i <= n; ++i) res = i; return res; } int main() { cin >> n; while (n > 0) { int x = tim(n); cout << x + 1 << " "; n -= 1 << x; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import sys import math n=int(raw_input("")) x=math.log(n,2) s=[] s.append("") s.append("1") s.append("2") s.append("2 1") a=2 for i in range(4,n+1): if i>=2**(a+1): a+=1 s.append(str(a+1)+" "+s[i-2**a]) print s[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
n = int(input()) power = [1] * 100 for i in range(1, 100): power[i] = power[i - 1] * 2 answer = [] a = 99 while n > 0: if n >= power[a]: n -= power[a] answer.append(a + 1) a -= 1 print(*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
a = [] for x in range(int(input())): a.append(1) while len(a) > 1 and a[-1] == a[-2]: a.pop() a.append(a.pop() + 1) 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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * * @author ramilagger * */ public class Main { public final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public final PrintWriter pw = new PrintWriter(System.out); public StringTokenizer st; int n,m; public void solve() throws IOException { int[] a = new int[100001]; int n = nextInt(); int cnt = 1; a[cnt] = 1; for (int i = 1; i < n; i++) { a[++cnt] = 1; while (cnt - 1 >= 0 && a[cnt] == a[cnt - 1]) { a[cnt - 1] = a[cnt] + 1; a[cnt] = 0; cnt--; } } for (int i = 1; i <= cnt; i++) { pw.print(a[i] + " "); } } public void run() throws IOException { this.solve(); pw.close(); } public static void main(String[] args) throws IOException { new Main().run(); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(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 io #~ import sys #~ test = '1' #~ test = '2' #~ test = '3' #~ test = '8' #~ sys.stdin = io.StringIO(test) n = int(input()) a = [] def simplify(a): if len(a)<=1: return if a[-2]==a[-1]: del a[-1] a[-1] += 1 simplify(a) for i in range(n): a.append(1) simplify(a) 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(input()) l=[1] for i in range(2,n+1): l+=[1] while len(l)>=2: if l[-1]==l[-2]: l=l[:-2]+[l[-1]+1] else: break 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 main() { int n; cin >> n; if (n == 1) { cout << n << endl; return 0; } vector<int> v(n, 1); for (int j = 0; j < pow(v.size(), 4); j++) for (int i = 1; i < v.size(); i++) { if (v[i] == v[i - 1]) { v[i - 1] += 1; v.erase(v.begin() + i); i--; } } for (int i = 0; i < v.size(); i++) { cout << v[i] << ' '; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(raw_input()) ans = [] while n != 0: i = 0 j = 2 ** (i+1) while j <= n: i = i + 1 j = 2 ** (i + 1) ans.append(i+1) n = n - (2 ** 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
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { std::vector<int> v; int t; cin >> t; for (int i = 0; i < t; i++) { v.push_back(1); while (v[v.size() - 1] == v[v.size() - 2]) { v[v.size() - 2]++; v.pop_back(); } } for (int i = 0; i < v.size(); i++) { cout << v[i] << " "; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.*; import java.util.*; public class Cf618A { public static void main(String args[]) throws IOException { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = in.nextInt(); char a[] = Integer.toBinaryString(n).toCharArray(); for(int i = 0; i < a.length; i++){ if(a[i] == '1') w.print((a.length-i) + " "); } w.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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() b=30 while b >= 0: if 1<<b & n:print b+1 b -= 1
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(raw_input().strip()) bin = [] while n > 0 : bin.append(n % 2) n /= 2 for i in xrange(len(bin), 0, -1): if bin[i - 1]: print bin[i - 1] * 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
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; template <class T> T gcd(T a, T b) { return ((b == 0) ? a : gcd(b, a % b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> s = {1}; for (int i = (int)(1); i < (int)(n); i++) { s.push_back(1); while (s.size() >= 2 && s[s.size() - 2] == s[s.size() - 1]) s[s.size() - 2]++, s.pop_back(); } for (int i = 0; i < (int)(s.size()); i++) cout << s[i] << " "; 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
# -*- coding:utf-8 -*- import sys def some_func(): """ """ n = input() lit =[] count =1 while n: if n%2: lit.append(count) n= n/2 count+=1 for v in lit[::-1]: print v, if __name__ == '__main__': some_func()
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()) s = bin(n) s = s[2:] k = len(s) for i, x in enumerate(s): if x == '1': print(k - i, end = ' ')
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.*; import java.util.*; import java.math.BigInteger; import java.util.Map.Entry; import static java.lang.Math.*; public class A extends PrintWriter { void run() { int n = nextInt(); for (int i = 27; i >= 0; i--) { if ((n & (1 << i)) > 0) { print(i + 1); print(' '); } } } boolean skip() { while (hasNext()) { next(); } return true; } int[][] nextMatrix(int n, int m) { int[][] matrix = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) matrix[i][j] = nextInt(); return matrix; } String next() { while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(nextLine()); return tokenizer.nextToken(); } boolean hasNext() { while (!tokenizer.hasMoreTokens()) { String line = nextLine(); if (line == null) { return false; } tokenizer = new StringTokenizer(line); } return true; } int[] nextArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) { array[i] = nextInt(); } return array; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { try { return reader.readLine(); } catch (IOException err) { return null; } } public A(OutputStream outputStream) { super(outputStream); } static BufferedReader reader; static StringTokenizer tokenizer = new StringTokenizer(""); static Random rnd = new Random(); static boolean OJ; public static void main(String[] args) throws IOException { OJ = System.getProperty("ONLINE_JUDGE") != null; A solution = new A(System.out); if (OJ) { reader = new BufferedReader(new InputStreamReader(System.in)); solution.run(); } else { reader = new BufferedReader(new FileReader(new File(A.class.getName() + ".txt"))); long timeout = System.currentTimeMillis(); while (solution.hasNext()) { solution.run(); solution.println(); solution.println("----------------------------------"); } solution.println("time: " + (System.currentTimeMillis() - timeout)); } solution.close(); reader.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
list=[0] n=int(input()) for i in range(1,n+1): list.append(1) while list[len(list)-1]==list[len(list)-2]: del list[len(list)-2] list[len(list)-1]+=1 for i in range(1,len(list)): print(list[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 com.sun.org.apache.bcel.internal.generic.AALOAD; import com.sun.org.apache.bcel.internal.generic.GOTO; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import java.util.stream.IntStream; import javafx.util.Pair; import static jdk.nashorn.internal.runtime.regexp.joni.Syntax.Java; public class Main { public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); int n = input.nextInt(); Stack<Integer> st = new Stack<>(); for (int i = 0; i < n; i++) { st.push(1); while(st.size()>1&&st.get(st.size()-1)==st.get(st.size()-2)) { st.pop(); st.push(st.pop()+1); } } for (Integer integer : st) { System.out.print(integer+" "); } 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.String; import java.util.Scanner; public class A { public static void main(String[] args) { // TODO Auto-generated method stub Scanner reader = new Scanner(System.in); PrintWriter writer= new PrintWriter(System.out); String line1 = reader.nextLine(); int n = Integer.parseInt(line1); while(n>0){ int m = (int) Math.floor(Math.log(n)/Math.log(2)); writer.print(m+1+" "); n = n - (int)Math.pow(2, m); } reader.close(); writer.flush(); writer.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 double pi = acos(-1.0); const double eps = 1e-11; const int INFINITE = 0x3f3f3f3f; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T lowbit(T n) { return (n ^ (n - 1)) & n; } template <class T> inline int countbit(T n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); } template <class T> inline T gcd(T a, T b) { T c; while (a != 0) { c = a; a = b % a; b = c; } return b; } typedef vector<int> VI; typedef vector<VI> VII; typedef vector<string> VS; inline void solve() { int n; scanf("%d", &n); bool f = true; for (int i = 20; i >= 0; i--) { if ((n & (1 << i)) > 0) { if (f) f = false; else printf(" "); printf("%d", i + 1); } } printf("\n"); } int main() { ios::sync_with_stdio(false); 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; int main() { int n, i; cin >> n; vector<int> v; while (n != 0) { v.push_back(n % 2); n /= 2; } for (i = v.size() - 1; i >= 0; i--) { if (v[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 a[10010]; int main() { int n; memset(a, 0, sizeof(a)); cin >> n; int cnt = 0; while (n--) { a[++cnt] = 1; while (a[cnt] == a[cnt - 1]) { a[cnt - 1]++; cnt--; } } for (int i = 0; i < cnt; i++) cout << a[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()) l=[] for i in range(n): l.append(1) while len(l)>=2 and l[-1]==l[-2]: l.pop() l[-1]+=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()) def rec(l): while l[-1] == l[-2]: l[-2] += 1 l.pop() return l res = [0] for i in range(n): res.append(1) res = rec(res) print(" ".join(map(str, res[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(raw_input()) bitn=bin(n) reversebitn=bitn[::-1] kintegers=[] for i in xrange(0,len(reversebitn)): if reversebitn[i]=="1": kintegers.append(i+1) for x in kintegers[::-1]: print x,
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.Scanner; public class Russia_A { static int n; public static void readData() { Scanner sc = new Scanner(System.in); n = sc.nextInt(); } public static void main (String args[]) { readData(); int i,nr=0; int c[]=new int[100]; while(n>0) { c[nr]=n%2; n/=2; nr++; } for(i=nr-1;i>=0;i--) if(c[i]==1) System.out.print((i+1) + " "); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; @SuppressWarnings("unchecked") public class P618A { public void run() throws Exception { for (int n = nextInt(), b = 1 << 16, i = 17; n > 0; b >>>= 1, i--) { if ((n & b) != 0) { print(i + " "); n ^= b; } } } public static void main(String... args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P618A().run(); br.close(); pw.close(); System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]"); } static long startTime = System.currentTimeMillis(); static BufferedReader br; static PrintWriter pw; StringTokenizer stok; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } void print(byte b) { print("" + b); } void print(int i) { print("" + i); } void print(long l) { print("" + l); } void print(double d) { print("" + d); } void print(char c) { print("" + c); } void print(Object o) { if (o instanceof int[]) { print(Arrays.toString((int [])o)); } else if (o instanceof long[]) { print(Arrays.toString((long [])o)); } else if (o instanceof char[]) { print(Arrays.toString((char [])o)); } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o)); } else if (o instanceof short[]) { print(Arrays.toString((short [])o)); } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o)); } else if (o instanceof float[]) { print(Arrays.toString((float [])o)); } else if (o instanceof double[]) { print(Arrays.toString((double [])o)); } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o)); } else { print("" + o); } } void print(String s) { pw.print(s); } void println() { println(""); } void println(byte b) { println("" + b); } void println(int i) { println("" + i); } void println(long l) { println("" + l); } void println(double d) { println("" + d); } void println(char c) { println("" + c); } void println(Object o) { print(o); println(); } void println(String s) { pw.println(s); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) (br.read()); } String next() throws IOException { return nextToken(); } String nextLine() throws IOException { return br.readLine(); } int [] readInt(int size) throws IOException { int [] array = new int [size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } long [] readLong(int size) throws IOException { long [] array = new long [size]; for (int i = 0; i < size; i++) { array[i] = nextLong(); } return array; } double [] readDouble(int size) throws IOException { double [] array = new double [size]; for (int i = 0; i < size; i++) { array[i] = nextDouble(); } return array; } String [] readLines(int size) throws IOException { String [] array = new String [size]; for (int i = 0; i < size; i++) { array[i] = nextLine(); } return array; } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int x = Integer.parseInt(br.readLine()); String s =""; int c=0; while(x>0) { int remain=(x%2); x/=2; s=remain+s; } int weight=1; ArrayList arr = new ArrayList<Integer>(); for(int i=s.length()-1;i>=0;i--,weight++) { if(s.charAt(i)=='1') { arr.add(weight); } } String out=""; for(int i=arr.size()-1;i>=0;i--){ out+=arr.get(i); if(i!=0) out+=" "; } System.out.println(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
k=int(input()) a=[0] i=0 while(i<k): a.append(1) while a[len(a)-1]==a[len(a)-2]: a.remove(a[len(a)-1]) a[len(a)-1]+=1 i+=1; for i in range(1,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
n = int(input()) p = [] def zzip(p): while True: if len(p) < 2: return p sl = p.pop() slr = p.pop() if sl == slr: p.append(sl + 1) else: p.append(slr) p.append(sl) return p for i in range(0, n): p.append(1) p = zzip(p) for s in p: print(s, 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()) slimes=[] slimes.append(1) for i in range(n-1): slimes.append(1) while 1: #print("h") if len(slimes)==1 or (slimes[-1] !=slimes[-2]) : break slimes[-2]+=1 del slimes[-1] print (*slimes)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int main() { int slimes, values; vector<int> vec; cin >> slimes; for (int i = 0; i < slimes; i++) { vec.push_back(1); while (vec.size() > 1 && vec[vec.size() - 1] == vec[vec.size() - 2]) { vec.pop_back(); vec[vec.size() - 1] += 1; } } for (int j = 0; j < vec.size(); j++) { cout << vec[j] << " "; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
r=lambda:map(int,raw_input().split()) n=input() if n == 1: print 1 exit(0) s=[1] n-=1 while n: s.append(1) while len(s) >=2 and s[-1] == s[-2]: s.pop() s[-1]+=1 n-=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
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int64_t n; cin >> n; vector<int64_t> bits; int64_t b = 1; while (n > 0) { if (n % 2) { bits.push_back(b); } n /= 2; b++; } for (int64_t i = (int64_t)bits.size() - 1; i >= 0; i--) { cout << bits[i] << " "; } 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
n=int(input()) for i in range(20,-1,-1): if(2**i<=n): print(i+1,end=' ') n-=2**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
from math import * x = int(input()) while x>0: print(floor(log2(x))+1,end=' ') x-=pow(2,floor(log2(x))) print()
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int a[100010]; int main(void) { int n; cin >> n; int l = -1; for (int i = 0; i < n; i++) { l++; a[l] = 1; while (l >= 1 && a[l] == a[l - 1]) { a[l - 1] += 1; l--; } } for (int i = 0; i <= l; i++) { cout << a[i] << ' '; } return 0; }
CPP
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> using namespace std; int stiva[100005]; int sz; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { stiva[++sz] = 1; while (sz > 1 && stiva[sz] == stiva[sz - 1]) stiva[sz - 1]++, sz--; } for (int i = 1; i <= sz; ++i) cout << stiva[i] << " \n"[i == sz]; 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()) li= [] li.append(1) j = 1 for i in range(n-1): li.append(j) while len(li)>1: if li[-1]==li[-2]: li[len(li)-2]+=1 li.pop(len(li)-1) else: break print(*li)
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()) out=[] cur=1 while n>0: if n%2==1: out.append(cur) cur+=1 n//=2 out.reverse() print(*out)
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
x=int(input());p=2;a=[];b=[] for i in range(x): if p**i>x:break a.append(p**i) a=a[::-1] for i in range(len(a)): if a[i]<=x: b.append(len(a)-i) x=x-a[i] if x==0:exit(print(*b))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n=int(input()) s=bin(n)[2:] x=len(s) for i in s : if i=="1": print x, x-=1 print
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 = [] cnt = 1 while N != 0: if N % 2 != 0: ans.append(cnt) N = N // 2 cnt += 1 ans.reverse() print(" ".join(map(str, ans)))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here int[] pow2 = new int[20]; pow2[0]=1; for(int i=1 ;i<20 ; i++){ pow2[i] = pow2[i-1]*2; } Scanner s = new Scanner(System.in); int n = s.nextInt(); String[] arr = new String[100000]; int index=1,pow=1; arr[0] = "1"; for(int i=1 ; i<n ; i++){ if((i+1)==pow2[pow]){ String str = ""; str+= (pow+1); arr[index] = str; index++; pow++; }else{ int diff = (i+1)-pow2[pow-1]; String str = arr[pow2[pow-1]-1]; str+= " "+arr[diff-1]; arr[index] = str; index++; } } System.out.println(arr[index-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.Scanner; public class I { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int r[] = new int[n]; int q = 0; while (n != 0){ int t = 1; int y = 0; while (t <= n){ t = t * 2; y++; } t = t / 2; r[q] = y; q++; n = n - t; } for (int t = 0; t < q; t++){ System.out.print(r[t] + " "); } } }
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
__author__ = '11x256' n = int(raw_input()) res = [] for i in range(0,n): res.append(1) while len(res) > 1 and res[-1] == res[-2]: res= res[:-1] res[-1] +=1 s = '' for j in res: s+=str(j) s+=' ' print s[:-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=input() v=[] for x in range(1,n+1): v+=[1] while len(v)>1 and v[-2]==v[-1]: v.pop() v[-1]+=1 for x in v: print x,
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 arr[100001]; int main() { int n, k = 1; scanf("%d", &n); arr[0] = 1, n--; while (n--) { arr[k++] = 1; while (arr[k - 1] == arr[k - 2]) arr[k - 2]++, k--; } for (int 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
import java.util.Scanner; public class Code { public static class Findi{ int pq; public Findi(int f) { pq=f; } public void printf() { int i=25,p; //System.out.print("rohit"); while(i>=0) { p=(1<<i); // System.out.println(p); if((pq & p)>0 ) { System.out.print((i+1)+" "); } i--; } } } public static void main(String [] args) { Scanner in =new Scanner(System.in); int val=in.nextInt(); Findi rohit=new Findi(val); rohit.printf(); } }
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()) ans = [] st = 1 for i in range(n): ans.append(1) while len(ans) > 1 and ans[-1] == ans[-2]: ans[-2] += 1 ans.pop() print(*ans)
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.*; public class SlimeCombining { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int noSlimes = sc.nextInt(); String answer = ""; while(noSlimes > 2) { int i = 1; while((int)Math.pow(2, i) < noSlimes) { i++; } if((int)Math.pow(2, i) == noSlimes) { noSlimes = noSlimes - (int)Math.pow(2, (i)); answer += (i+1) + " "; }else{ noSlimes = noSlimes - (int)Math.pow(2, (i-1)); answer += (i) + " "; } } if(noSlimes != 0) answer += noSlimes; System.out.println(answer); sc.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()) ans = [] num = list(bin(n)[2::]) size = len(num) for idx in range(size): if num[idx] == '1': ans.append(size - idx) print(' '.join(map(str,ans)))
PYTHON3
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.lang.StringBuilder; import java.util.*; public class CFWunderA { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); int n = scanner.nextInt(); ArrayList<Integer> ans = new ArrayList<Integer>(); int twos = 65536; int numb = 17; while (n > 0) { if (twos <= n) { writer.write(numb + " "); n -= twos; } numb--; twos /= 2; } writer.write("\n"); writer.flush(); } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** * Created by MrPozitivka on 01.07.2017. */ public class Task619a { BufferedReader in; PrintWriter out; StringTokenizer st; public static void main(String[] args) throws IOException { Task619a task = new Task619a(); task.open(); task.solve(); task.close(); } private void solve() throws IOException { int n = nextInt(); int count = n; n = n -1; int h = 0; int[] array = new int[count+1]; array[0] = 1; while (n!=0 && count!=1) { h++; array[h]++; n--; while (array[h] == array[h-1]) { array[h] = 0; array[h-1]++; h--; if (h==0) break; } } for (int c:array ) { if (c== 0) break; out.print(c+" "); } } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String str = in.readLine(); if (str == null) return null; st = new StringTokenizer(str); } return st.nextToken(); } private void close() { out.flush(); } private void open() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); // in = new BufferedReader(new FileReader("file.in")); out = new PrintWriter(System.out); // out = new PrintWriter(new FileWriter("file.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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class ProblemA { public static void main(String[] args) { InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out); new ProblemA().solve(in, out); out.close(); } public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); String s = Integer.toBinaryString(n); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '1') { out.print((s.length() - i) + " "); } } } static class InputReader { public BufferedReader br; public StringTokenizer st; public InputReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
import java.util.Scanner; import java.util.Vector; public class SlimeCombiningA618 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); Vector<Integer> vs = new Vector<Integer>(); for (int i = 0; i < n; i++) { vs.addElement(1); for (int j = vs.size() - 1; j > 0; j--) { int a = vs.get(j); int b = vs.get(j - 1); if (a == b) { vs.remove(j); int c = vs.lastElement(); vs.remove(j - 1); vs.add(c + 1); } else { break; } } } for (int i = 0; i < vs.size(); i++) { System.out.print(vs.get(i)); System.out.print(' '); } } }
JAVA
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
n = int(input()) A = [] while n > 0: if n % 2 == 0: A.append(0) n //= 2 else: A.append(1) n -= 1 n //= 2 A = A[::-1] for i in range(len(A)): if A[i] == 1: print(len(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
N = int(raw_input()) ans = [] i = 1 while N > 0: if N % 2 == 1: ans.insert(0, str(i)) N /= 2 i += 1 print " ".join(ans)
PYTHON
618_A. Slime Combining
Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value v, you combine them together to create a slime with value v + 1. You would like to see what the final state of the row is after you've added all n slimes. Please print the values of the slimes in the row from left to right. Input The first line of the input will contain a single integer, n (1 ≤ n ≤ 100 000). Output Output a single line with k integers, where k is the number of slimes in the row after you've finished the procedure described in the problem statement. The i-th of these numbers should be the value of the i-th slime from the left. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 2 1 Input 8 Output 4 Note In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2. In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1. In the last sample, the steps look as follows: 1. 1 2. 2 3. 2 1 4. 3 5. 3 1 6. 3 2 7. 3 2 1 8. 4
2
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; int n; vector<int> ans; int main() { cin >> n; for (int i = 17; i >= 0; i--) { int temp = 1 << (i); if (temp <= n) { ans.push_back(i + 1); n -= temp; } } for (int i = 0; i < ans.size(); i++) { if (i) cout << " "; cout << ans[i]; } cout << endl; return 0; }
CPP